def canBeUnsubscribedByUser(self, user): """See `ISpecificationSubscription`.""" if user is None: return False if not IPersonRoles.providedBy(user): user = IPersonRoles(user) if (user.inTeam(self.specification.owner) or user.inTeam(self.person) or user.in_admin): return True # XXX Abel Deuring 2012-11-21, bug=1081677 # People who subscribed users should be able to unsubscribe # them again, similar to branch subscriptions. This is # essential if somebody was erroneuosly subscribed to a # proprietary or embargoed specification. Unfortunately, # SpecificationSubscription does not record who subscribed # somebody else, but if the specification is private, we can # check who issued the artifact grant. artifacts = getUtility(IAccessArtifactSource).find( [self.specification]) wanted = [(artifact, self.person) for artifact in artifacts] if len(wanted) == 0: return False for grant in getUtility(IAccessArtifactGrantSource).find(wanted): if user.inTeam(grant.grantor): return True return False
def canBeUnsubscribedByUser(self, user): """See `ISpecificationSubscription`.""" if user is None: return False if not IPersonRoles.providedBy(user): user = IPersonRoles(user) if ( user.inTeam(self.specification.owner) or user.inTeam(self.person) or user.in_admin): return True # XXX Abel Deuring 2012-11-21, bug=1081677 # People who subscribed users should be able to unsubscribe # them again, similar to branch subscriptions. This is # essential if somebody was erroneuosly subscribed to a # proprietary or embargoed specification. Unfortunately, # SpecificationSubscription does not record who subscribed # somebody else, but if the specification is private, we can # check who issued the artifact grant. artifacts = getUtility(IAccessArtifactSource).find( [self.specification]) wanted = [(artifact, self.person) for artifact in artifacts] if len(wanted) == 0: return False for grant in getUtility(IAccessArtifactGrantSource).find(wanted): if user.inTeam(grant.grantor): return True return False
def test_inTeam_works(self): # Make sure it actually works. team = self.factory.makeTeam(self.person) roles = IPersonRoles(self.person) self.assertTrue(roles.inTeam(team))