def subscriber_data(self): """Return subscriber_ids in a form suitable for JavaScript use.""" bug = IBug(self.context) data = self.direct_subscriber_data(bug) others = list(bug.getIndirectSubscribers()) # If we have made it to here then the logged in user can see the # bug, hence they can see any indirect subscribers. include_private = self.user is not None if include_private: precache_permission_for_objects( self.request, 'launchpad.LimitedView', others) for person in others: if person == self.user: # Skip the current user viewing the page, continue if not include_private and person.private: # Do not include private teams if there's no logged in user. continue subscriber = { 'name': person.name, 'display_name': person.displayname, 'web_link': canonical_url(person, rootsite='mainsite'), 'self_link': absoluteURL(person, self.api_request), 'is_team': person.is_team, 'can_edit': False, } record = { 'subscriber': subscriber, 'subscription_level': 'Maybe', } data.append(record) return data
def get_string_representation(obj): """Returns a string representation of an object. It can be used as oldvalue and newvalue. Returns None if no representation can be made. """ if IPerson.providedBy(obj): return obj.name if IBug.providedBy(obj): return str(obj.id) elif ISourcePackageRelease.providedBy(obj): return "%s %s" % (obj.sourcepackagename.name, obj.version) elif IProductRelease.providedBy(obj): return "%s %s" % (obj.product.name, obj.version) elif IMilestone.providedBy(obj): return obj.name elif isinstance(obj, BaseItem): return obj.title elif isinstance(obj, basestring): return obj elif isinstance(obj, bool): return str(obj) else: return None
def ensure(cls, concrete_artifacts): """See `IAccessArtifactSource`.""" from lp.blueprints.interfaces.specification import ISpecification from lp.bugs.interfaces.bug import IBug from lp.code.interfaces.branch import IBranch from lp.code.interfaces.gitrepository import IGitRepository existing = list(cls.find(concrete_artifacts)) if len(existing) == len(concrete_artifacts): return existing # Not everything exists. Create missing ones. needed = (set(concrete_artifacts) - set(abstract.concrete_artifact for abstract in existing)) insert_values = [] for concrete in needed: if IBug.providedBy(concrete): insert_values.append((concrete, None, None, None)) elif IBranch.providedBy(concrete): insert_values.append((None, concrete, None, None)) elif IGitRepository.providedBy(concrete): insert_values.append((None, None, concrete, None)) elif ISpecification.providedBy(concrete): insert_values.append((None, None, None, concrete)) else: raise ValueError("%r is not a supported artifact" % concrete) new = create( (cls.bug, cls.branch, cls.gitrepository, cls.specification), insert_values, get_objects=True) return list(existing) + new
def ensure(cls, concrete_artifacts): """See `IAccessArtifactSource`.""" from lp.blueprints.interfaces.specification import ISpecification from lp.bugs.interfaces.bug import IBug from lp.code.interfaces.branch import IBranch existing = list(cls.find(concrete_artifacts)) if len(existing) == len(concrete_artifacts): return existing # Not everything exists. Create missing ones. needed = ( set(concrete_artifacts) - set(abstract.concrete_artifact for abstract in existing)) insert_values = [] for concrete in needed: if IBug.providedBy(concrete): insert_values.append((concrete, None, None)) elif IBranch.providedBy(concrete): insert_values.append((None, concrete, None)) elif ISpecification.providedBy(concrete): insert_values.append((None, None, concrete)) else: raise ValueError("%r is not a supported artifact" % concrete) new = create( (cls.bug, cls.branch, cls.specification), insert_values, get_objects=True) return list(existing) + new
def create(cls, requestor, artifacts=None, grantee=None, pillar=None, information_types=None): """See `IRemoveArtifactSubscriptionsJob`.""" bug_ids = [] branch_ids = [] specification_ids = [] if artifacts: for artifact in artifacts: if IBug.providedBy(artifact): bug_ids.append(artifact.id) elif IBranch.providedBy(artifact): branch_ids.append(artifact.id) elif ISpecification.providedBy(artifact): specification_ids.append(artifact.id) else: raise ValueError('Unsupported artifact: %r' % artifact) information_types = [ info_type.value for info_type in information_types or [] ] metadata = { 'bug_ids': bug_ids, 'branch_ids': branch_ids, 'specification_ids': specification_ids, 'information_types': information_types, 'requestor.id': requestor.id } return super(RemoveArtifactSubscriptionsJob, cls).create(pillar, grantee, metadata)
def create(cls, requestor, artifacts=None, grantee=None, pillar=None, information_types=None): """See `IRemoveArtifactSubscriptionsJob`.""" bug_ids = [] branch_ids = [] specification_ids = [] if artifacts: for artifact in artifacts: if IBug.providedBy(artifact): bug_ids.append(artifact.id) elif IBranch.providedBy(artifact): branch_ids.append(artifact.id) elif ISpecification.providedBy(artifact): specification_ids.append(artifact.id) else: raise ValueError("Unsupported artifact: %r" % artifact) information_types = [info_type.value for info_type in information_types or []] metadata = { "bug_ids": bug_ids, "branch_ids": branch_ids, "specification_ids": specification_ids, "information_types": information_types, "requestor.id": requestor.id, } return super(RemoveArtifactSubscriptionsJob, cls).create(pillar, grantee, metadata)
def render(self): for bugtask in IBug(self.context).bugtasks: if (IDistributionSourcePackage.providedBy(bugtask.target) and (not self.widgets['sourcepackagename'].hasInput())): self.widgets['sourcepackagename'].setRenderedValue( bugtask.sourcepackagename) break return super(DistroBugTaskCreationStep, self).render()
def _constraintForConcrete(cls, concrete_artifact): from lp.blueprints.interfaces.specification import ISpecification from lp.bugs.interfaces.bug import IBug from lp.code.interfaces.branch import IBranch if IBug.providedBy(concrete_artifact): col = cls.bug elif IBranch.providedBy(concrete_artifact): col = cls.branch elif ISpecification.providedBy(concrete_artifact): col = cls.specification else: raise ValueError("%r is not a valid artifact" % concrete_artifact) return col == concrete_artifact
def get_bug_and_bugtasks(bug_or_bugtask): """Return a bug and a list of bugtasks given a bug or a bugtask. :param bug_or_bugtask: An `IBug` or `IBugTask`. :raises ValueError: If `bug_or_bugtask` does not provide `IBug` or `IBugTask`. """ if IBug.providedBy(bug_or_bugtask): return bug_or_bugtask, bug_or_bugtask.bugtasks elif IBugTask.providedBy(bug_or_bugtask): return bug_or_bugtask.bug, [bug_or_bugtask] else: raise ValueError("Expected bug or bugtask, got %r" % (bug_or_bugtask,))
def _constraintForConcrete(cls, concrete_artifact): from lp.blueprints.interfaces.specification import ISpecification from lp.bugs.interfaces.bug import IBug from lp.code.interfaces.branch import IBranch if IBug.providedBy(concrete_artifact): col = cls.bug elif IBranch.providedBy(concrete_artifact): col = cls.branch elif ISpecification.providedBy(concrete_artifact): col = cls.specification else: raise ValueError( "%r is not a valid artifact" % concrete_artifact) return col == concrete_artifact
def get_bug_and_bugtasks(bug_or_bugtask): """Return a bug and a list of bugtasks given a bug or a bugtask. :param bug_or_bugtask: An `IBug` or `IBugTask`. :raises ValueError: If `bug_or_bugtask` does not provide `IBug` or `IBugTask`. """ if IBug.providedBy(bug_or_bugtask): return bug_or_bugtask, bug_or_bugtask.bugtasks elif IBugTask.providedBy(bug_or_bugtask): return bug_or_bugtask.bug, [bug_or_bugtask] else: raise ValueError( "Expected bug or bugtask, got %r" % (bug_or_bugtask,))
def update_bug_date_last_updated(object, event): """Update IBug.date_last_updated to the current date.""" # If no fields on the bug have changed, do nothing. if IObjectModifiedEvent.providedBy(event) and not event.edited_fields: return if IBug.providedBy(object): bug = object elif IHasBug.providedBy(object): bug = object.bug else: raise AssertionError( "Unable to retrieve current bug to update 'date last updated'. " "Event handler expects object implementing IBug or IHasBug. " "Got: %s" % repr(object)) removeSecurityProxy(bug).date_last_updated = datetime.now(pytz.UTC)
def activity(self): activity = IBug(self.context).activity list(getUtility(IPersonSet).getPrecachedPersonsFromIDs( [a.personID for a in activity], need_validity=True)) return activity
def page_description(self): return IBug(self.context).description
def subscription_info(self): return IBug(self.context).getSubscriptionInfo()
def assign_question_bug_link_karma(question, event): """Assign karma to the user which added <questionbug>.""" if IBug.providedBy(event.other_object): assignKarmaUsingQuestionContext( IPerson(event.user), event.object, 'questionlinkedtobug')
def subscribe_owner_to_bug(question, event): """Subscribe a question's owner when it's linked to a bug.""" if IBug.providedBy(event.other_object): if not event.other_object.isSubscribed(question.owner): event.other_object.subscribe(question.owner, question.owner)
def unsubscribe_owner_from_bug(question, event): """Unsubscribe a question's owner when it's unlinked from a bug.""" if IBug.providedBy(event.other_object): if event.other_object.isSubscribed(question.owner): event.other_object.unsubscribe(question.owner, question.owner)