def testMembersWithoutGivenIDs(self): h = features_pb2.Hotlist() owners, editors, followers = hotlist_helpers.MembersWithoutGivenIDs( h, set()) # Check lists are empty self.assertFalse(owners) self.assertFalse(editors) self.assertFalse(followers) h.owner_ids.extend([1, 2, 3]) h.editor_ids.extend([4, 5, 6]) h.follower_ids.extend([7, 8, 9]) owners, editors, followers = hotlist_helpers.MembersWithoutGivenIDs( h, {10, 11, 12}) self.assertEqual(h.owner_ids, owners) self.assertEqual(h.editor_ids, editors) self.assertEqual(h.follower_ids, followers) owners, editors, followers = hotlist_helpers.MembersWithoutGivenIDs( h, set()) self.assertEqual(h.owner_ids, owners) self.assertEqual(h.editor_ids, editors) self.assertEqual(h.follower_ids, followers) owners, editors, followers = hotlist_helpers.MembersWithoutGivenIDs( h, {1, 4, 7}) self.assertEqual([2, 3], owners) self.assertEqual([5, 6], editors) self.assertEqual([8, 9], followers)
def ProcessChangeOwnership(self, mr, post_data): new_owner_id_set = project_helpers.ParseUsernames( mr.cnxn, self.services.user, post_data.get('changeowners')) remain_as_editor = post_data.get('becomeeditor') == 'on' if len(new_owner_id_set) != 1: mr.errors.transfer_ownership = ( 'Please add one valid user email.') else: new_owner_id = new_owner_id_set.pop() if self.services.features.LookupHotlistIDs( mr.cnxn, [mr.hotlist.name], [new_owner_id]): mr.errors.transfer_ownership = ( 'This user already owns a hotlist with the same name') if mr.errors.AnyErrors(): self.PleaseCorrect( mr, initial_new_owner_username=post_data.get('changeowners'), open_dialog=ezt.boolean(True)) else: old_and_new_owner_ids = [new_owner_id] + mr.hotlist.owner_ids (_, editor_ids, follower_ids) = hotlist_helpers.MembersWithoutGivenIDs( mr.hotlist, old_and_new_owner_ids) if remain_as_editor and mr.hotlist.owner_ids: editor_ids.append(mr.hotlist.owner_ids[0]) self.services.features.UpdateHotlistRoles( mr.cnxn, mr.hotlist_id, [new_owner_id], editor_ids, follower_ids) hotlist = self.services.features.GetHotlist(mr.cnxn, mr.hotlist_id) hotlist_url = hotlist_helpers.GetURLOfHotlist( mr.cnxn, hotlist, self.services.user) return framework_helpers.FormatAbsoluteURL( mr,'%s%s' % (hotlist_url, urls.HOTLIST_PEOPLE), saved=1, ts=int(time.time()), include_project=False)
def ProcessRemoveMembers(self, mr, post_data, hotlist_url): """Process the user's request to remove members.""" remove_strs = post_data.getall('remove') logging.info('remove_strs = %r', remove_strs) remove_ids = set( self.services.user.LookupUserIDs(mr.cnxn, remove_strs).values()) (owner_ids, editor_ids, follower_ids) = hotlist_helpers.MembersWithoutGivenIDs( mr.hotlist, remove_ids) self.services.features.UpdateHotlistRoles( mr.cnxn, mr.hotlist_id, owner_ids, editor_ids, follower_ids) return framework_helpers.FormatAbsoluteURL( mr, '%s%s' % ( hotlist_url, urls.HOTLIST_PEOPLE), saved=1, ts=int(time.time()), include_project=False)
def ProcessRemoveSelf(self, mr, hotlist_url): """Process the request to remove the logged-in user.""" remove_ids = [mr.auth.user_id] # This function does no permission checking; that's done by the caller. (owner_ids, editor_ids, follower_ids) = hotlist_helpers.MembersWithoutGivenIDs( mr.hotlist, remove_ids) self.services.features.UpdateHotlistRoles(mr.cnxn, mr.hotlist_id, owner_ids, editor_ids, follower_ids) return framework_helpers.FormatAbsoluteURL( mr, '%s%s' % (hotlist_url, urls.HOTLIST_PEOPLE), saved=1, ts=int(time.time()), include_project=False)