Beispiel #1
0
    def addBugSubscription(self, subscriber, subscribed_by):
        """See `IStructuralSubscriptionTarget`."""
        # This is a helper method for creating a structural
        # subscription. It is useful so long as subscriptions are mainly
        # used to implement bug supervisor rules.
        if not self.userCanAlterBugSubscription(subscriber, subscribed_by):
            raise UserCannotSubscribePerson(
                '%s does not have permission to subscribe %s' % (
                    subscribed_by.name, subscriber.name))

        return self.addSubscription(subscriber, subscribed_by)
    def removeBugSubscription(self, subscriber, unsubscribed_by):
        """See `IStructuralSubscriptionTarget`."""
        if subscriber is None:
            subscriber = unsubscribed_by

        if not self.userCanAlterSubscription(subscriber, unsubscribed_by):
            raise UserCannotSubscribePerson(
                '%s does not have permission to unsubscribe %s.' %
                (unsubscribed_by.name, subscriber.name))

        subscription_to_remove = self.getSubscriptions(
            subscriber=subscriber).one()

        if subscription_to_remove is None:
            raise DeleteSubscriptionError("%s is not subscribed to %s." %
                                          (subscriber.name, self.displayname))
        subscription_to_remove.delete()
Beispiel #3
0
    def addBugSubscriptionFilter(self, subscriber, subscribed_by):
        """See `IStructuralSubscriptionTarget`."""
        if not self.userCanAlterBugSubscription(subscriber, subscribed_by):
            raise UserCannotSubscribePerson(
                '%s does not have permission to subscribe %s' % (
                    subscribed_by.name, subscriber.name))

        subscription = self.getSubscription(subscriber)
        if subscription is None:
            # No subscription exists for this target for the subscriber so
            # create a new one.
            subscription = self.addSubscription(subscriber, subscribed_by)
            # Newly created subscriptions automatically get a subscription
            # filter, this is the new filter being requested so return it.
            return subscription.bug_filters[0]
        else:
            # Since the subscription already exists, we need a new filter to
            # return.
            return subscription.newBugFilter()
Beispiel #4
0
    def addSubscription(self, subscriber, subscribed_by):
        """See `IStructuralSubscriptionTarget`."""
        if subscriber is None:
            subscriber = subscribed_by

        if not self.userCanAlterSubscription(subscriber, subscribed_by):
            raise UserCannotSubscribePerson(
                '%s does not have permission to subscribe %s.' % (
                    subscribed_by.name, subscriber.name))

        existing_subscription = self.getSubscription(subscriber)

        if existing_subscription is not None:
            return existing_subscription
        else:
            new_subscription = StructuralSubscription(
                subscriber=subscriber,
                subscribed_by=subscribed_by,
                **self._target_args)
            new_subscription.newBugFilter()
            return new_subscription
Beispiel #5
0
 def test_UserCannotSubscribePerson_authorised(self):
     error_view = create_webservice_error_view(UserCannotSubscribePerson())
     self.assertEqual(UNAUTHORIZED, error_view.status)