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
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
def assertSortKeysEqual(self, displayname, name, expected): # The sort key calculated in-process matches the expected sort key. self.assertEqual(expected, person_sort_key(PersonNames(displayname, name)))
def subscriptions(self): """Sort the subscriptions""" from lp.registry.model.person import person_sort_key return sorted(self._subscriptions, key=lambda sub: person_sort_key(sub.person))
def subscriptions(self): """Sort the subscriptions""" from lp.registry.model.person import person_sort_key return sorted( self._subscriptions, key=lambda sub: person_sort_key(sub.person))