Ejemplo n.º 1
0
 def unsubscribe(self, person, unsubscribed_by, ignore_permissions=False):
     """See ISpecification."""
     # see if a relevant subscription exists, and if so, delete it
     if person is None:
         person = unsubscribed_by
     for sub in self.subscriptions:
         if sub.person.id == person.id:
             if (not sub.canBeUnsubscribedByUser(unsubscribed_by)
                     and not ignore_permissions):
                 raise UserCannotUnsubscribePerson(
                     '%s does not have permission to unsubscribe %s.' %
                     (unsubscribed_by.displayname, person.displayname))
             get_property_cache(self).subscriptions.remove(sub)
             SpecificationSubscription.delete(sub.id)
             artifacts_to_delete = getUtility(IAccessArtifactSource).find(
                 [self])
             getUtility(IAccessArtifactGrantSource).revokeByArtifact(
                 artifacts_to_delete, [person])
             return
Ejemplo n.º 2
0
 def unsubscribe(self, person, unsubscribed_by, ignore_permissions=False):
     """See ISpecification."""
     # see if a relevant subscription exists, and if so, delete it
     if person is None:
         person = unsubscribed_by
     for sub in self.subscriptions:
         if sub.person.id == person.id:
             if (not sub.canBeUnsubscribedByUser(unsubscribed_by) and
                 not ignore_permissions):
                 raise UserCannotUnsubscribePerson(
                     '%s does not have permission to unsubscribe %s.' % (
                         unsubscribed_by.displayname,
                         person.displayname))
             get_property_cache(self).subscriptions.remove(sub)
             SpecificationSubscription.delete(sub.id)
             artifacts_to_delete = getUtility(
                 IAccessArtifactSource).find([self])
             getUtility(IAccessArtifactGrantSource).revokeByArtifact(
                 artifacts_to_delete, [person])
             return
Ejemplo n.º 3
0
 def subscribe(self, person, subscribed_by=None, essential=False):
     """See ISpecification."""
     if subscribed_by is None:
         subscribed_by = person
     # Create or modify a user's subscription to this blueprint.
     # First see if a relevant subscription exists, and if so, return it
     sub = self.subscription(person)
     if sub is not None:
         if sub.essential != essential:
             # If a subscription already exists, but the value for
             # 'essential' changes, there's no need to create a new
             # subscription, but we modify the existing subscription
             # and notify the user about the change.
             sub.essential = essential
             # The second argument should really be a copy of sub with
             # only the essential attribute changed, but we know
             # that we can get away with not examining the attribute
             # at all - it's a boolean!
             notify(
                 ObjectModifiedEvent(sub,
                                     sub, ['essential'],
                                     user=subscribed_by))
         return sub
     # since no previous subscription existed, create and return a new one
     sub = SpecificationSubscription(specification=self,
                                     person=person,
                                     essential=essential)
     property_cache = get_property_cache(self)
     if 'subscription' in property_cache:
         from lp.registry.model.person import person_sort_key
         property_cache.subscriptions.append(sub)
         property_cache.subscriptions.sort(
             key=lambda sub: person_sort_key(sub.person))
     if self.information_type in PRIVATE_INFORMATION_TYPES:
         # Grant the subscriber access if they can't see the
         # specification.
         service = getUtility(IService, 'sharing')
         ignored, ignored, shared_specs = service.getVisibleArtifacts(
             person, specifications=[self], ignore_permissions=True)
         if not shared_specs:
             service.ensureAccessGrants([person],
                                        subscribed_by,
                                        specifications=[self])
     notify(ObjectCreatedEvent(sub, user=subscribed_by))
     return sub
Ejemplo n.º 4
0
 def subscription(self, person):
     """See ISpecification."""
     return SpecificationSubscription.selectOneBy(specification=self,
                                                  person=person)
Ejemplo n.º 5
0
 def subscription(self, person):
     """See ISpecification."""
     return SpecificationSubscription.selectOneBy(
             specification=self, person=person)