def getSharedArtifacts(self, pillar, person, user, include_bugs=True, include_branches=True, include_specifications=True): """See `ISharingService`.""" bug_ids = set() branch_ids = set() specification_ids = set() for artifact in self.getArtifactGrantsForPersonOnPillar( pillar, person): if artifact.bug_id and include_bugs: bug_ids.add(artifact.bug_id) elif artifact.branch_id and include_branches: branch_ids.add(artifact.branch_id) elif artifact.specification_id and include_specifications: specification_ids.add(artifact.specification_id) # Load the bugs. bugtasks = [] if bug_ids: param = BugTaskSearchParams(user=user, bug=any(*bug_ids)) param.setTarget(pillar) bugtasks = list(getUtility(IBugTaskSet).search(param)) # Load the branches. branches = [] if branch_ids: all_branches = getUtility(IAllBranches) wanted_branches = all_branches.visibleByUser(user).withIds( *branch_ids) branches = list(wanted_branches.getBranches()) specifications = [] if specification_ids: specifications = load(Specification, specification_ids) return bugtasks, branches, specifications
def _getBugtasks(self, target, ignore_privacy=False): """Return the list `IBugTask`s associated with the target.""" if IProductSeries.providedBy(target): params = BugTaskSearchParams(user=self.user) params.setProductSeries(target) else: params = BugTaskSearchParams( milestone=target, user=self.user, ignore_privacy=ignore_privacy) bugtasks = getUtility(IBugTaskSet).search(params) return list(bugtasks)
def most_recently_fixed_bugs(self): """Return the five most recently fixed bugs.""" params = BugTaskSearchParams( self.user, status=BugTaskStatus.FIXRELEASED, date_closed=not_equals(None), orderby='-date_closed') return getUtility(IBugSet).getDistinctBugsForBugTasks( self.context.searchTasks(params), self.user, limit=5)
def getBugData(self, user, bug_id, related_bug=None): """See `IMaloneApplication`.""" search_params = BugTaskSearchParams(user, bug=bug_id) bugtasks = getUtility(IBugTaskSet).search(search_params) if not bugtasks: return [] bugs = [task.bug for task in bugtasks] data = [] for bug in bugs: bugtask = bug.default_bugtask different_pillars = related_bug and (set( bug.affected_pillars).isdisjoint( related_bug.affected_pillars)) or False data.append({ 'id': bug_id, 'information_type': bug.information_type.title, 'is_private': bug.information_type in PRIVATE_INFORMATION_TYPES, 'importance': bugtask.importance.title, 'importance_class': 'importance' + bugtask.importance.name, 'status': bugtask.status.title, 'status_class': 'status' + bugtask.status.name, 'bug_summary': bug.title, 'description': bug.description, 'bug_url': canonical_url(bugtask), 'different_pillars': different_pillars }) return data
def duplicates(self): """Return a list of dicts of duplicates. Each dict contains the title that should be shown and the bug object itself. This allows us to protect private bugs using a title like 'Private Bug'. """ duplicate_bugs = list(self.context.duplicates) current_task = self.current_bugtask dupes_in_current_context = dict( (bugtask.bug, bugtask) for bugtask in current_task.target.searchTasks( BugTaskSearchParams(self.user, bug=any(*duplicate_bugs)))) dupes = [] for bug in duplicate_bugs: dupe = {} try: dupe['title'] = bug.title except Unauthorized: dupe['title'] = 'Private Bug' dupe['id'] = bug.id # If the dupe has the same context as the one we're in, link # to that bug task directly. if bug in dupes_in_current_context: dupe['url'] = canonical_url(dupes_in_current_context[bug]) else: dupe['url'] = canonical_url(bug) dupes.append(dupe) return dupes
def getInvisibleArtifacts(self, person, branches=None, bugs=None): """See `ISharingService`.""" bugs_by_id = {} branches_by_id = {} for bug in bugs or []: bugs_by_id[bug.id] = bug for branch in branches or []: branches_by_id[branch.id] = branch # Load the bugs. visible_bug_ids = set() if bugs_by_id: param = BugTaskSearchParams( user=person, bug=any(*bugs_by_id.keys())) visible_bug_ids = set(getUtility(IBugTaskSet).searchBugIds(param)) invisible_bug_ids = set(bugs_by_id.keys()).difference(visible_bug_ids) invisible_bugs = [bugs_by_id[bug_id] for bug_id in invisible_bug_ids] # Load the branches. invisible_branches = [] if branches_by_id: all_branches = getUtility(IAllBranches) visible_branch_ids = all_branches.visibleByUser(person).withIds( *branches_by_id.keys()).getBranchIds() invisible_branch_ids = ( set(branches_by_id.keys()).difference(visible_branch_ids)) invisible_branches = [ branches_by_id[branch_id] for branch_id in invisible_branch_ids] return invisible_bugs, invisible_branches
def test_getBugCvesForBugTasks(self): # ICveSet.getBugCvesForBugTasks() returns tuples (bug, cve) # for the given bugtasks. bugtasks = self.distroseries.searchTasks( BugTaskSearchParams(self.distroseries.owner, has_cve=True)) bug_cves = getUtility(ICveSet).getBugCvesForBugTasks(bugtasks) found_bugs = [bug for bug, cve in bug_cves] found_cves = [cve for bug, cve in bug_cves] self.assertEqual(self.bugs, found_bugs) self.assertEqual(self.cves, found_cves)
def setUp(self): super(TestProjectExcludeConjoinedMasterSearch, self).setUp() self.bugtask_set = getUtility(IBugTaskSet) self.product = self.factory.makeProduct() self.milestone = self.factory.makeMilestone(product=self.product, name='foo') self.bug_count = 2 self.bugs = [ self.makeBug(self.milestone) for i in range(self.bug_count) ] self.params = BugTaskSearchParams(user=None, milestone=self.milestone, exclude_conjoined_tasks=True)
def setUp(self): super(TestDistributionExcludeConjoinedMasterSearch, self).setUp() self.bugtask_set = getUtility(IBugTaskSet) self.distro = getUtility(ILaunchpadCelebrities).ubuntu self.milestone = self.factory.makeMilestone(distribution=self.distro, name='foo') self.bug_count = 2 self.bugs = [ self.makeBug(self.milestone) for i in range(self.bug_count) ] self.params = BugTaskSearchParams(user=None, milestone=self.milestone, exclude_conjoined_tasks=True)
def getLinkedBugTasks(self, user): """See `ISpecification`.""" params = BugTaskSearchParams(user=user, linked_blueprints=self.id) tasks = getUtility(IBugTaskSet).search(params) if self.distroseries is not None: context = self.distroseries elif self.distribution is not None: context = self.distribution elif self.productseries is not None: context = self.productseries else: context = self.product return filter_bugtasks_by_context(context, tasks)
def setUp(self): super(TestProjectGroupExcludeConjoinedMasterSearch, self).setUp() self.bugtask_set = getUtility(IBugTaskSet) self.projectgroup = self.factory.makeProject() self.bug_count = 2 self.bug_products = {} for i in range(self.bug_count): product = self.factory.makeProduct(project=self.projectgroup) product_milestone = self.factory.makeMilestone(product=product, name='foo') bug = self.makeBug(product_milestone) self.bug_products[bug] = product self.milestone = self.projectgroup.getMilestone('foo') self.params = BugTaskSearchParams(user=None, milestone=self.milestone, exclude_conjoined_tasks=True)
def _getBugtasks(self, target, ignore_privacy=False): """Return the list `IBugTask`s associated with the target.""" if IProductSeries.providedBy(target): params = BugTaskSearchParams(user=self.user) params.setProductSeries(target) else: params = BugTaskSearchParams(milestone=target, user=self.user, ignore_privacy=ignore_privacy) bugtasks = getUtility(IBugTaskSet).search(params) return list(bugtasks)
def getVisibleArtifacts(self, person, branches=None, bugs=None, specifications=None, ignore_permissions=False): """See `ISharingService`.""" bugs_by_id = {} branches_by_id = {} for bug in bugs or []: if (not ignore_permissions and not check_permission('launchpad.View', bug)): raise Unauthorized bugs_by_id[bug.id] = bug for branch in branches or []: if (not ignore_permissions and not check_permission('launchpad.View', branch)): raise Unauthorized branches_by_id[branch.id] = branch for spec in specifications or []: if (not ignore_permissions and not check_permission('launchpad.View', spec)): raise Unauthorized # Load the bugs. visible_bug_ids = [] if bugs_by_id: param = BugTaskSearchParams( user=person, bug=any(*bugs_by_id.keys())) visible_bug_ids = set(getUtility(IBugTaskSet).searchBugIds(param)) visible_bugs = [bugs_by_id[bug_id] for bug_id in visible_bug_ids] # Load the branches. visible_branches = [] if branches_by_id: all_branches = getUtility(IAllBranches) wanted_branches = all_branches.visibleByUser(person).withIds( *branches_by_id.keys()) visible_branches = list(wanted_branches.getBranches()) visible_specs = [] if specifications: visible_private_spec_ids = self._getVisiblePrivateSpecificationIDs( person, specifications) visible_specs = [ spec for spec in specifications if spec.id in visible_private_spec_ids or not spec.private] return visible_bugs, visible_branches, visible_specs
def destroySelf(self): """See `IMilestone`.""" params = BugTaskSearchParams(milestone=self, user=None) bugtasks = getUtility(IBugTaskSet).search(params) subscriptions = IResultSet(self.getSubscriptions()) assert subscriptions.is_empty(), ( "You cannot delete a milestone which has structural " "subscriptions.") assert bugtasks.is_empty(), ( "You cannot delete a milestone which has bugtasks targeted " "to it.") assert self.all_specifications.is_empty(), ( "You cannot delete a milestone which has specifications targeted " "to it.") assert self.product_release is None, ( "You cannot delete a milestone which has a product release " "associated with it.") super(Milestone, self).destroySelf()
def test_delete_conjoined_bugtask(self): product = self.factory.makeProduct() bug = self.factory.makeBug(target=product) master_bugtask = getUtility(IBugTaskSet).createTask( bug, product.owner, product.development_focus) milestone = self.factory.makeMilestone( productseries=product.development_focus) login_person(product.owner) master_bugtask.transitionToMilestone(milestone, product.owner) form = { 'field.actions.delete': 'Delete Milestone', } view = create_initialized_view(milestone, '+delete', form=form) self.assertEqual([], view.errors) self.assertEqual([], list(product.all_milestones)) tasks = product.development_focus.searchTasks( BugTaskSearchParams(user=None)) self.assertEqual(0, tasks.count())
def searchTasks(self, search_params, user=None, order_by=None, search_text=None, status=None, importance=None, assignee=None, bug_reporter=None, bug_supervisor=None, bug_commenter=None, bug_subscriber=None, owner=None, structural_subscriber=None, affected_user=None, affects_me=False, has_patch=None, has_cve=None, distribution=None, tags=None, tags_combinator=BugTagsSearchCombinator.ALL, omit_duplicates=True, omit_targeted=None, status_upstream=None, milestone=None, component=None, nominated_for=None, sourcepackagename=None, has_no_package=None, hardware_bus=None, hardware_vendor_id=None, hardware_product_id=None, hardware_driver_name=None, hardware_driver_package_name=None, hardware_owner_is_bug_reporter=None, hardware_owner_is_affected_by_bug=False, hardware_owner_is_subscribed_to_bug=False, hardware_is_linked_to_bug=False, linked_branches=None, linked_blueprints=None, modified_since=None, created_since=None, created_before=None, information_type=None): """See `IHasBugs`.""" if status is None: # If no statuses are supplied, default to the # list of all unreolved statuses. status = list(UNRESOLVED_BUGTASK_STATUSES) if order_by is None: # If no order_by value is supplied, default to importance. order_by = ['-importance'] if search_params is None: kwargs = dict(locals()) del kwargs['self'] del kwargs['user'] del kwargs['search_params'] search_params = BugTaskSearchParams.fromSearchForm(user, **kwargs) self._customizeSearchParams(search_params) return BugTaskSet().search(search_params)
def getInvisibleArtifacts(self, person, bugs=None, branches=None, gitrepositories=None): """See `ISharingService`.""" bug_ids = list(map(attrgetter("id"), bugs or [])) branch_ids = list(map(attrgetter("id"), branches or [])) gitrepository_ids = list(map(attrgetter("id"), gitrepositories or [])) # Load the bugs. invisible_bugs = [] if bug_ids: param = BugTaskSearchParams(user=person, bug=any(*bug_ids)) visible_bug_ids = set(getUtility(IBugTaskSet).searchBugIds(param)) invisible_bugs = [ bug for bug in bugs if bug.id not in visible_bug_ids ] # Load the branches. invisible_branches = [] if branch_ids: all_branches = getUtility(IAllBranches) visible_branch_ids = all_branches.visibleByUser(person).withIds( *branch_ids).getBranchIds() invisible_branches = [ branch for branch in branches if branch.id not in visible_branch_ids ] # Load the Git repositories. invisible_gitrepositories = [] if gitrepository_ids: all_gitrepositories = getUtility(IAllGitRepositories) visible_gitrepository_ids = all_gitrepositories.visibleByUser( person).withIds(*gitrepository_ids).getRepositoryIds() invisible_gitrepositories = [ gitrepository for gitrepository in gitrepositories if gitrepository.id not in visible_gitrepository_ids ] return invisible_bugs, invisible_branches, invisible_gitrepositories
def test_getBugCvesForBugTasks_with_mapper(self): # ICveSet.getBugCvesForBugTasks() takes a function f as an # optional argeument. This function is applied to each CVE # related to the given bugs; the method return a sequence of # tuples (bug, f(cve)). def cve_name(cve): return cve.displayname bugtasks = self.distroseries.searchTasks( BugTaskSearchParams(self.distroseries.owner, has_cve=True)) bug_cves = getUtility(ICveSet).getBugCvesForBugTasks( bugtasks, cve_name) found_bugs = [bug for bug, cve in bug_cves] cve_data = [cve for bug, cve in bug_cves] self.assertEqual(self.bugs, found_bugs) expected = [ u'CVE-2000-0001', u'CVE-2000-0002', u'CVE-2000-0003', u'CVE-2000-0004' ] self.assertEqual(expected, cve_data)
def buglinks(self): """Return a list of dict with bug, title and can_see_bug keys for the linked bugs. It makes the Right Thing(tm) with private bug. """ # Do a regular search to get the bugtasks so that visibility is # evaluated and eager loading is performed. bug_ids = [bug.id for bug in self.context.bugs] if not bug_ids: return [] bugtask_set = getUtility(IBugTaskSet) query = BugTaskSearchParams(user=self.user, bug=any(*bug_ids)) bugtasks = list(bugtask_set.search(query)) # collate by bug bugs = defaultdict(list) for task in bugtasks: bugs[task.bug].append(task) badges = bugtask_set.getBugTaskBadgeProperties(bugtasks) tags = bugtask_set.getBugTaskTags(bugtasks) people = bugtask_set.getBugTaskPeople(bugtasks) links = [] columns_to_show = [ "id", "summary", "bugtargetdisplayname", "importance", "status" ] for bug, tasks in bugs.items(): navigator = BugListingBatchNavigator( tasks, self.request, columns_to_show=columns_to_show, size=config.malone.buglist_batch_size) get_property_cache(navigator).bug_badge_properties = badges get_property_cache(navigator).tags_for_batch = tags get_property_cache(navigator).bugtask_people = people links.append({ 'bug': bug, 'title': bug.title, 'can_view_bug': True, 'tasks': tasks, 'batch_navigator': navigator, }) return links
def getInformationTypesToShow(self): """Get the information types to display on the edit form. We display a highly customised set of information types: anything allowed by the namespace, plus the current type, except some of the obscure types unless there's a linked bug with an obscure type. """ allowed_types = self.context.getAllowedInformationTypes(self.user) # If we're stacked on a private branch, only show that # information type. if self.context.stacked_on and self.context.stacked_on.private: shown_types = set([self.context.stacked_on.information_type]) else: shown_types = ( InformationType.PUBLIC, InformationType.PUBLICSECURITY, InformationType.PRIVATESECURITY, InformationType.USERDATA, InformationType.PROPRIETARY, InformationType.EMBARGOED, ) # XXX Once Branch Visibility Policies are removed, we only want to # show Private (USERDATA) if the branch is linked to such a bug. hidden_types = ( # InformationType.USERDATA, ) if set(allowed_types).intersection(hidden_types): params = BugTaskSearchParams( user=self.user, linked_branches=self.context.id, information_type=hidden_types) if not getUtility(IBugTaskSet).searchBugIds(params).is_empty(): shown_types += hidden_types # Now take the intersection of the allowed and shown types. combined_types = set(allowed_types).intersection(shown_types) combined_types.add(self.context.information_type) return combined_types
def test_milestone_bugtasks(self): """Bugtasks and project milestones. Bugtasks assigned to product milestones are also assigned to the corresponding project milestone. """ self.createProductMilestone('1.1', 'evolution', None) self.createProductMilestone('1.1', 'gnomebaker', None) self.createProductMilestone('1.1', 'firefox', None) self._createProductBugtask('evolution', '1.1') self._createProductBugtask('gnomebaker', '1.1') self._createProductBugtask('firefox', '1.1') milestone = getUtility(IProjectGroupSet)['gnome'].getMilestone('1.1') searchparams = BugTaskSearchParams(user=None, milestone=milestone) bugtasks = list(getUtility(IBugTaskSet).search(searchparams)) # Only the first two bugs created here belong to the gnome project. self.assertEqual([bugtask.bug.title for bugtask in bugtasks], [ 'Milestone test bug for evolution', 'Milestone test bug for gnomebaker' ])
def test_delete_all_bugtasks(self): # When a milestone is deleted, all bugtasks are deleted. milestone = self.factory.makeMilestone() self.factory.makeBug(milestone=milestone) self.factory.makeBug(milestone=milestone, information_type=InformationType.USERDATA) # Remove the APG the product owner has so he can't see the private bug. ap = getUtility(IAccessPolicySource).find([ (milestone.product, InformationType.USERDATA) ]).one() getUtility(IAccessPolicyGrantSource).revoke([ (ap, milestone.product.owner) ]) form = { 'field.actions.delete': 'Delete Milestone', } with person_logged_in(milestone.product.owner): view = create_initialized_view(milestone, '+delete', form=form) self.assertEqual([], view.errors) tasks = milestone.product.development_focus.searchTasks( BugTaskSearchParams(user=None)) self.assertEqual(0, tasks.count())
def export_bugtasks(ztm, bugtarget, output, include_private=False): # Collect bug task IDs. if include_private: # The admin team can see all bugs user = getUtility(ILaunchpadCelebrities).admin else: user = None ids = [ task.id for task in bugtarget.searchTasks( BugTaskSearchParams(user=user, omit_dupes=False, orderby='id')) ] bugtaskset = getUtility(IBugTaskSet) output.write('<launchpad-bugs xmlns="%s">\n' % BUGS_XMLNS) for count, taskid in enumerate(ids): task = bugtaskset.get(taskid) tree = ET.ElementTree(serialise_bugtask(task)) tree.write(output) # Periodically abort the transaction so that we don't lock # everyone else out. if count % 100: ztm.abort() output.write('</launchpad-bugs>\n')
def check_bug_links(self, links): """Checks links of the form /bugs/100""" invalid_links = {} valid_links = {} user = self.user # List of all the bugs we are checking. bugs_ids = set([int(link[len('/bugs/'):]) for link in links]) if bugs_ids: params = BugTaskSearchParams( user=user, status=None, bug=any(*bugs_ids)) bugtasks = getUtility(IBugTaskSet).search(params) for task in bugtasks: valid_links['/bugs/' + str(task.bug.id)] = task.bug.title # Remove valid bugs from the list of all the bugs. if task.bug.id in bugs_ids: bugs_ids.remove(task.bug.id) # We should now have only invalid bugs in bugs list for bug in bugs_ids: invalid_links['/bugs/%d' % bug] = ( "Bug %s cannot be found" % bug) return {'valid': valid_links, 'invalid': invalid_links}
def getExtendedRevisionDetails(self, user, revisions): """See `IBranchCollection`.""" if not revisions: return [] branch = revisions[0].branch def make_rev_info(branch_revision, merge_proposal_revs, linked_bugtasks): rev_info = { 'revision': branch_revision, 'linked_bugtasks': None, 'merge_proposal': None, } merge_proposal = merge_proposal_revs.get(branch_revision.sequence) rev_info['merge_proposal'] = merge_proposal if merge_proposal is not None: rev_info['linked_bugtasks'] = linked_bugtasks.get( merge_proposal.source_branch.id) return rev_info rev_nos = [revision.sequence for revision in revisions] merge_proposals = self.getMergeProposals( target_branch=branch, merged_revnos=rev_nos, statuses=[BranchMergeProposalStatus.MERGED]) merge_proposal_revs = dict([(mp.merged_revno, mp) for mp in merge_proposals]) source_branch_ids = [mp.source_branch.id for mp in merge_proposals] linked_bugtasks = defaultdict(list) if source_branch_ids: # We get the bugtasks for our merge proposal branches # First, the bug ids params = BugTaskSearchParams( user=user, status=None, linked_branches=any(*source_branch_ids)) bug_ids = getUtility(IBugTaskSet).searchBugIds(params) # Then the bug tasks and branches store = IStore(BugBranch) rs = store.using( BugBranch, Join(BugTask, BugTask.bugID == BugBranch.bugID), ).find((BugTask, BugBranch), BugBranch.bugID.is_in(bug_ids), BugBranch.branchID.is_in(source_branch_ids)) # Build up a collection of bugtasks for each branch bugtasks_for_branch = defaultdict(list) for bugtask, bugbranch in rs: bugtasks_for_branch[bugbranch.branch].append(bugtask) # Now filter those down to one bugtask per branch for branch, tasks in bugtasks_for_branch.iteritems(): linked_bugtasks[branch.id].extend( filter_bugtasks_by_context(branch.target.context, tasks)) return [ make_rev_info(rev, merge_proposal_revs, linked_bugtasks) for rev in revisions ]
def new_bugtasks_count(self): search_params = BugTaskSearchParams(self.user, status=BugTaskStatus.NEW, omit_dupes=True) return self.context.searchTasks(search_params).count()
def bugtask_count(self): user = getUtility(ILaunchBag).user search_params = BugTaskSearchParams(user=user) return getUtility(IBugTaskSet).search(search_params).count()
def most_recently_reported_bugs(self): """Return the five most recently reported bugs.""" params = BugTaskSearchParams(self.user, orderby='-datecreated') return getUtility(IBugSet).getDistinctBugsForBugTasks( self.context.searchTasks(params), self.user, limit=5)
def searchTasks(self, search_params, user=None, order_by=None, search_text=None, status=None, importance=None, assignee=None, bug_reporter=None, bug_supervisor=None, bug_commenter=None, bug_subscriber=None, owner=None, structural_subscriber=None, affected_user=None, affects_me=False, has_patch=None, has_cve=None, distribution=None, tags=None, tags_combinator=BugTagsSearchCombinator.ALL, omit_duplicates=True, omit_targeted=None, status_upstream=None, milestone=None, component=None, nominated_for=None, sourcepackagename=None, has_no_package=None, hardware_bus=None, hardware_vendor_id=None, hardware_product_id=None, hardware_driver_name=None, hardware_driver_package_name=None, hardware_owner_is_bug_reporter=None, hardware_owner_is_affected_by_bug=False, hardware_owner_is_subscribed_to_bug=False, hardware_is_linked_to_bug=False, linked_branches=None, linked_blueprints=None, modified_since=None, created_since=None, created_before=None, information_type=None): """See `IHasBugs`.""" if status is None: # If no statuses are supplied, default to the # list of all unreolved statuses. status = list(UNRESOLVED_BUGTASK_STATUSES) if order_by is None: # If no order_by value is supplied, default to importance. order_by = ['-importance'] if search_params is None: kwargs = dict(locals()) del kwargs['self'] del kwargs['user'] del kwargs['search_params'] search_params = BugTaskSearchParams.fromSearchForm(user, **kwargs) self._customizeSearchParams(search_params) return BugTaskSet().search(search_params)
def initialize(self): """See `LaunchpadView`.""" super(CVEReportView, self).initialize() search_params = BugTaskSearchParams( self.user, has_cve=True) bugtasks = shortlist( self.context.searchTasks(search_params), longest_expected=600) if not bugtasks: self.open_cve_bugtasks = [] self.resolved_cve_bugtasks = [] return bugtask_set = getUtility(IBugTaskSet) badge_properties = bugtask_set.getBugTaskBadgeProperties(bugtasks) people = bugtask_set.getBugTaskPeople(bugtasks) open_bugtaskcves = {} resolved_bugtaskcves = {} for bugtask in bugtasks: badges = badge_properties[bugtask] # Wrap the bugtask in a BugTaskListingItem, to avoid db # queries being issues when trying to render the badges. bugtask = BugTaskListingItem( bugtask, has_bug_branch=badges['has_branch'], has_specification=badges['has_specification'], has_patch=badges['has_patch'], tags=(), people=people) if bugtask.status in RESOLVED_BUGTASK_STATUSES: current_bugtaskcves = resolved_bugtaskcves else: current_bugtaskcves = open_bugtaskcves if bugtask.bug.id not in current_bugtaskcves: current_bugtaskcves[bugtask.bug.id] = BugTaskCve() current_bugtaskcves[bugtask.bug.id].bugtasks.append(bugtask) bugcves = getUtility(ICveSet).getBugCvesForBugTasks( bugtasks, get_cve_display_data) for bug, cve in bugcves: if bug.id in open_bugtaskcves: open_bugtaskcves[bug.id].cves.append(cve) if bug.id in resolved_bugtaskcves: resolved_bugtaskcves[bug.id].cves.append(cve) # Order the dictionary items by bug ID and then store only the # bugtaskcve objects. self.open_cve_bugtasks = [ bugtaskcve for bug, bugtaskcve in sorted(open_bugtaskcves.items())] self.resolved_cve_bugtasks = [ bugtaskcve for bug, bugtaskcve in sorted(resolved_bugtaskcves.items())] # The page contains links to the bug task assignees: # Pre-load the related Person and ValidPersonCache records assignee_ids = [task.assigneeID for task in bugtasks] list(getUtility(IPersonSet).getPrecachedPersonsFromIDs( assignee_ids, need_validity=True))
def getVisibleArtifacts(self, person, bugs=None, branches=None, gitrepositories=None, specifications=None, ignore_permissions=False): """See `ISharingService`.""" bug_ids = [] branch_ids = [] gitrepository_ids = [] for bug in bugs or []: if (not ignore_permissions and not check_permission('launchpad.View', bug)): raise Unauthorized bug_ids.append(bug.id) for branch in branches or []: if (not ignore_permissions and not check_permission('launchpad.View', branch)): raise Unauthorized branch_ids.append(branch.id) for gitrepository in gitrepositories or []: if (not ignore_permissions and not check_permission('launchpad.View', gitrepository)): raise Unauthorized gitrepository_ids.append(gitrepository.id) for spec in specifications or []: if (not ignore_permissions and not check_permission('launchpad.View', spec)): raise Unauthorized # Load the bugs. visible_bugs = [] if bug_ids: param = BugTaskSearchParams(user=person, bug=any(*bug_ids)) visible_bug_ids = set(getUtility(IBugTaskSet).searchBugIds(param)) visible_bugs = [bug for bug in bugs if bug.id in visible_bug_ids] # Load the branches. visible_branches = [] if branch_ids: all_branches = getUtility(IAllBranches) wanted_branches = all_branches.visibleByUser(person).withIds( *branch_ids) visible_branches = list(wanted_branches.getBranches()) # Load the Git repositories. visible_gitrepositories = [] if gitrepository_ids: all_gitrepositories = getUtility(IAllGitRepositories) wanted_gitrepositories = all_gitrepositories.visibleByUser( person).withIds(*gitrepository_ids) visible_gitrepositories = list( wanted_gitrepositories.getRepositories()) # Load the specifications. visible_specs = [] if specifications: visible_private_spec_ids = self._getVisiblePrivateSpecificationIDs( person, specifications) visible_specs = [ spec for spec in specifications if spec.id in visible_private_spec_ids or not spec.private ] return (visible_bugs, visible_branches, visible_gitrepositories, visible_specs)