Example #1
0
    def ListFields(self, mc, request):
        """List all fields for the specified project."""
        project = self._GetProject(mc, request)

        with work_env.WorkEnv(mc, self.services) as we:
            config = we.GetProjectConfig(project.project_id)

        users_by_id = {}
        users_for_perm = {}
        # Only look for members if user choices are requested and there are user
        # fields that need permissions.
        if request.include_user_choices:
            perms_needed = {
                fd.needs_perm
                for fd in config.field_defs
                if fd.needs_perm and not fd.is_deleted
            }
            if perms_needed:
                users_by_id = tracker_helpers.GetVisibleMembers(
                    mc, project, self.services)
                effective_ids_by_user = self.services.usergroup.LookupAllMemberships(
                    mc.cnxn, users_by_id)
                users_for_perm = project_helpers.UsersWithPermsInProject(
                    project, perms_needed, users_by_id, effective_ids_by_user)

        field_defs = [
            converters.ConvertFieldDef(fd,
                                       users_for_perm.get(fd.needs_perm,
                                                          []), users_by_id,
                                       config, request.include_admin_info)
            for fd in config.field_defs if not fd.is_deleted
        ]

        result = projects_pb2.ListFieldsResponse(field_defs=field_defs)
        return result
Example #2
0
 def testUsersWithPermsInProject_StandardPermission(self):
     project = project_pb2.MakeProject('proj', committer_ids=[111])
     perms_needed = {permissions.VIEW, permissions.EDIT_ISSUE}
     actual = project_helpers.UsersWithPermsInProject(
         project, perms_needed, self.users_by_id,
         self.effective_ids_by_user)
     self.assertEqual(
         {
             permissions.VIEW: {111, 222, 333},
             permissions.EDIT_ISSUE: {111}
         }, actual)
Example #3
0
 def testUsersWithPermsInProject_CustomPermission(self):
     project = project_pb2.MakeProject('proj')
     project.extra_perms = [
         project_pb2.Project.ExtraPerms(member_id=111,
                                        perms=['FooPerm', 'BarPerm']),
         project_pb2.Project.ExtraPerms(member_id=222, perms=['BarPerm'])
     ]
     perms_needed = {'FooPerm', 'BarPerm'}
     actual = project_helpers.UsersWithPermsInProject(
         project, perms_needed, self.users_by_id,
         self.effective_ids_by_user)
     self.assertEqual({'FooPerm': {111}, 'BarPerm': {111, 222}}, actual)
Example #4
0
 def testUsersWithPermsInProject_IndirectPermission(self):
     perms_needed = {permissions.EDIT_ISSUE}
     # User 111 has the EDIT_ISSUE permission.
     project = project_pb2.MakeProject('proj', committer_ids=[111])
     # User 222 has the EDIT_ISSUE permission, because 111 is included in its
     # effective IDs.
     self.effective_ids_by_user[222] = {111}
     # User 333 doesn't have the EDIT_ISSUE permission, since only direct
     # effective IDs are taken into account.
     self.effective_ids_by_user[333] = {222}
     actual = project_helpers.UsersWithPermsInProject(
         project, perms_needed, self.users_by_id,
         self.effective_ids_by_user)
     self.assertEqual({permissions.EDIT_ISSUE: {111, 222}}, actual)