~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

[r=wallyworld][bug=816261] Move bugs subscriptions_list to apps and
        add IQuestion.canBeUnsubscribedBy

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
from lp.answers.model.questionreopening import create_questionreopening
88
88
from lp.answers.model.questionsubscription import QuestionSubscription
89
89
from lp.app.enums import ServiceUsage
 
90
from lp.app.errors import UserCannotUnsubscribePerson
90
91
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
91
92
from lp.bugs.interfaces.buglink import IBugLinkTarget
92
93
from lp.bugs.interfaces.bugtask import BugTaskStatus
527
528
        Store.of(sub).flush()
528
529
        return sub
529
530
 
530
 
    def unsubscribe(self, person):
 
531
    def unsubscribe(self, person, unsubscribed_by):
531
532
        """See `IQuestion`."""
532
533
        # See if a relevant subscription exists, and if so, delete it.
533
534
        for sub in self.subscriptions:
534
535
            if sub.person.id == person.id:
 
536
                if not sub.canBeUnsubscribedByUser(unsubscribed_by):
 
537
                    raise UserCannotUnsubscribePerson(
 
538
                        '%s does not have permission to unsubscribe %s.' % (
 
539
                            unsubscribed_by.displayname,
 
540
                            person.displayname))
535
541
                store = Store.of(sub)
536
542
                sub.destroySelf()
537
543
                store.flush()