Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1070)

Side by Side Diff: appengine/monorail/sitewide/group_helpers.py

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « appengine/monorail/sitewide/custom_404.py ('k') | appengine/monorail/sitewide/groupadmin.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is govered by a BSD-style
3 # license that can be found in the LICENSE file or at
4 # https://developers.google.com/open-source/licenses/bsd
5
6 """Helper functions used in user group modules."""
7
8 from framework import framework_views
9 from proto import usergroup_pb2
10
11
12 class GroupVisibilityView(object):
13 """Object for group visibility information that can be easily used in EZT."""
14
15 VISIBILITY_NAMES = {
16 usergroup_pb2.MemberVisibility.ANYONE: 'Anyone on the Internet',
17 usergroup_pb2.MemberVisibility.MEMBERS: 'Group Members',
18 usergroup_pb2.MemberVisibility.OWNERS: 'Group Owners'}
19
20 def __init__(self, group_visibility_enum):
21 self.key = int(group_visibility_enum)
22 self.name = self.VISIBILITY_NAMES[group_visibility_enum]
23
24
25 class GroupTypeView(object):
26 """Object for group type information that can be easily used in EZT."""
27
28 TYPE_NAMES = {
29 usergroup_pb2.GroupType.CHROME_INFRA_AUTH: 'Chrome-infra-auth',
30 usergroup_pb2.GroupType.MDB: 'MDB',
31 usergroup_pb2.GroupType.BAGGINS: 'Baggins'}
32
33 def __init__(self, group_type_enum):
34 self.key = int(group_type_enum)
35 self.name = self.TYPE_NAMES[group_type_enum]
36
37
38 class GroupMemberView(framework_views.UserView):
39 """Wrapper class to display basic group member information in a template."""
40
41 def __init__(self, user_id, email, obscure_email, group_id, role):
42 assert role in ['member', 'owner']
43 super(GroupMemberView, self).__init__(
44 user_id, email, obscure_email)
45 self.group_id = group_id
46 self.role = role
47
48
49 def BuildUserGroupVisibilityOptions():
50 """Return a list of user group visibility values for use in an HTML menu.
51
52 Returns:
53 A list of GroupVisibilityView objects that can be used in EZT.
54 """
55 vis_levels = [usergroup_pb2.MemberVisibility.OWNERS,
56 usergroup_pb2.MemberVisibility.MEMBERS,
57 usergroup_pb2.MemberVisibility.ANYONE]
58
59 return [GroupVisibilityView(vis) for vis in vis_levels]
60
61
62 def BuildUserGroupTypeOptions():
63 """Return a list of user group types for use in an HTML menu.
64
65 Returns:
66 A list of GroupTypeView objects that can be used in EZT.
67 """
68 group_types = [usergroup_pb2.GroupType.CHROME_INFRA_AUTH,
69 usergroup_pb2.GroupType.MDB,
70 usergroup_pb2.GroupType.BAGGINS]
71
72 return sorted([GroupTypeView(gt) for gt in group_types],
73 key=lambda gtv: gtv.name)
OLDNEW
« no previous file with comments | « appengine/monorail/sitewide/custom_404.py ('k') | appengine/monorail/sitewide/groupadmin.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698