예제 #1
0
    def testViewingSelf(self):
        member_view = project_views.MemberView(0, 111, self.alice_view,
                                               self.project, None)
        self.assertFalse(member_view.viewing_self)
        member_view = project_views.MemberView(222, 111, self.alice_view,
                                               self.project, None)
        self.assertFalse(member_view.viewing_self)

        member_view = project_views.MemberView(111, 111, self.alice_view,
                                               self.project, None)
        self.assertTrue(member_view.viewing_self)
예제 #2
0
    def testRoles(self):
        member_view = project_views.MemberView(0, 111, self.alice_view,
                                               self.project, None)
        self.assertEqual('Owner', member_view.role)
        self.assertEqual('/p/proj/people/detail?u=111', member_view.detail_url)

        member_view = project_views.MemberView(0, 222, self.bob_view,
                                               self.project, None)
        self.assertEqual('Committer', member_view.role)
        self.assertEqual('/p/proj/people/detail?u=222', member_view.detail_url)

        member_view = project_views.MemberView(0, 333, self.carol_view,
                                               self.project, None)
        self.assertEqual('Contributor', member_view.role)
        self.assertEqual('/p/proj/people/detail?u=333', member_view.detail_url)
예제 #3
0
 def _MakeMemberViews(self, logged_in_user_id, users_by_id, member_ids,
                      project, project_commitments, acexclusion_ids):
     """Return a sorted list of MemberViews for display by EZT."""
     member_views = [
         project_views.MemberView(logged_in_user_id,
                                  member_id,
                                  users_by_id[member_id],
                                  project,
                                  project_commitments,
                                  acexclusion_ids=acexclusion_ids)
         for member_id in member_ids
     ]
     member_views.sort(key=lambda mv: mv.user.email)
     return member_views
예제 #4
0
    def GatherPageData(self, mr):
        """Build up a dictionary of data values to use when rendering the page."""

        member_id = self.ValidateMemberID(mr.cnxn, mr.specified_user_id,
                                          mr.project)
        group_ids = self.services.usergroup.DetermineWhichUserIDsAreGroups(
            mr.cnxn, [member_id])
        users_by_id = framework_views.MakeAllUserViews(mr.cnxn,
                                                       self.services.user,
                                                       [member_id])
        framework_views.RevealAllEmailsToMembers(mr.auth, mr.project,
                                                 users_by_id)

        project_commitments = self.services.project.GetProjectCommitments(
            mr.cnxn, mr.project_id)
        (ac_exclusion_ids, no_expand_ids
         ) = self.services.project.GetProjectAutocompleteExclusion(
             mr.cnxn, mr.project_id)
        member_view = project_views.MemberView(
            mr.auth.user_id,
            member_id,
            users_by_id[member_id],
            mr.project,
            project_commitments,
            ac_exclusion=(member_id in ac_exclusion_ids),
            no_expand=(member_id in no_expand_ids),
            is_group=(member_id in group_ids))

        member_user = self.services.user.GetUser(mr.cnxn, member_id)
        # This ignores indirect memberships, which is ok because we are viewing
        # the page for a member directly involved in the project
        role_perms = permissions.GetPermissions(member_user, {member_id},
                                                mr.project)

        # TODO(jrobbins): clarify in the UI which permissions are built-in to
        # the user's direct role, vs. which are granted via a group membership,
        # vs. which ones are extra_perms that have been added specifically for
        # this user.
        member_perms = template_helpers.EZTItem()
        for perm in CHECKBOX_PERMS:
            setattr(
                member_perms, perm,
                ezt.boolean(role_perms.HasPerm(perm, member_id, mr.project)))

        displayed_extra_perms = [
            perm for perm in member_view.extra_perms
            if perm not in CHECKBOX_PERMS
        ]

        viewing_self = mr.auth.user_id == member_id
        warn_abandonment = (viewing_self
                            and permissions.ShouldCheckForAbandonment(mr))

        return {
            'subtab_mode':
            None,
            'member':
            member_view,
            'role_perms':
            role_perms,
            'member_perms':
            member_perms,
            'displayed_extra_perms':
            displayed_extra_perms,
            'offer_edit_perms':
            ezt.boolean(self.CanEditPerms(mr)),
            'offer_edit_member_notes':
            ezt.boolean(self.CanEditMemberNotes(mr, member_id)),
            'offer_remove_role':
            ezt.boolean(self.CanRemoveRole(mr, member_id)),
            'expand_perms':
            ezt.boolean(mr.auth.user_pb.keep_people_perms_open),
            'warn_abandonment':
            ezt.boolean(warn_abandonment),
            'total_num_owners':
            len(mr.project.owner_ids),
        }