~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/answers/model/questionsubscription.py

Add support for IQuestion.canBeUnsubscribedBy plus tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
from canonical.database.sqlbase import SQLBase
16
16
from lp.answers.interfaces.questionsubscription import IQuestionSubscription
17
17
from lp.registry.interfaces.person import validate_public_person
 
18
from lp.registry.interfaces.role import IPersonRoles
18
19
 
19
20
 
20
21
class QuestionSubscription(SQLBase):
30
31
    person = ForeignKey(
31
32
        dbName='person', foreignKey='Person',
32
33
        storm_validator=validate_public_person, notNull=True)
 
34
 
 
35
    def canBeUnsubscribedByUser(self, user):
 
36
        """See `IQuestionSubscription`."""
 
37
        if user is None:
 
38
            return False
 
39
        # The people who can unsubscribe someone are:
 
40
        # - lp admins
 
41
        # - the person themselves
 
42
        # - the question owner
 
43
        # - people who can reject questions (eg target owner, answer contacts)
 
44
        return (user.inTeam(self.question.owner) or
 
45
                user.inTeam(self.person) or
 
46
                IPersonRoles(user).in_admin or
 
47
                self.question.canReject(user))