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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/monorail/sitewide/group_helpers.py
diff --git a/appengine/monorail/sitewide/group_helpers.py b/appengine/monorail/sitewide/group_helpers.py
new file mode 100644
index 0000000000000000000000000000000000000000..b35351e1501f2ba7957ce893bbdc1f47261c854f
--- /dev/null
+++ b/appengine/monorail/sitewide/group_helpers.py
@@ -0,0 +1,73 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is govered by a BSD-style
+# license that can be found in the LICENSE file or at
+# https://developers.google.com/open-source/licenses/bsd
+
+"""Helper functions used in user group modules."""
+
+from framework import framework_views
+from proto import usergroup_pb2
+
+
+class GroupVisibilityView(object):
+ """Object for group visibility information that can be easily used in EZT."""
+
+ VISIBILITY_NAMES = {
+ usergroup_pb2.MemberVisibility.ANYONE: 'Anyone on the Internet',
+ usergroup_pb2.MemberVisibility.MEMBERS: 'Group Members',
+ usergroup_pb2.MemberVisibility.OWNERS: 'Group Owners'}
+
+ def __init__(self, group_visibility_enum):
+ self.key = int(group_visibility_enum)
+ self.name = self.VISIBILITY_NAMES[group_visibility_enum]
+
+
+class GroupTypeView(object):
+ """Object for group type information that can be easily used in EZT."""
+
+ TYPE_NAMES = {
+ usergroup_pb2.GroupType.CHROME_INFRA_AUTH: 'Chrome-infra-auth',
+ usergroup_pb2.GroupType.MDB: 'MDB',
+ usergroup_pb2.GroupType.BAGGINS: 'Baggins'}
+
+ def __init__(self, group_type_enum):
+ self.key = int(group_type_enum)
+ self.name = self.TYPE_NAMES[group_type_enum]
+
+
+class GroupMemberView(framework_views.UserView):
+ """Wrapper class to display basic group member information in a template."""
+
+ def __init__(self, user_id, email, obscure_email, group_id, role):
+ assert role in ['member', 'owner']
+ super(GroupMemberView, self).__init__(
+ user_id, email, obscure_email)
+ self.group_id = group_id
+ self.role = role
+
+
+def BuildUserGroupVisibilityOptions():
+ """Return a list of user group visibility values for use in an HTML menu.
+
+ Returns:
+ A list of GroupVisibilityView objects that can be used in EZT.
+ """
+ vis_levels = [usergroup_pb2.MemberVisibility.OWNERS,
+ usergroup_pb2.MemberVisibility.MEMBERS,
+ usergroup_pb2.MemberVisibility.ANYONE]
+
+ return [GroupVisibilityView(vis) for vis in vis_levels]
+
+
+def BuildUserGroupTypeOptions():
+ """Return a list of user group types for use in an HTML menu.
+
+ Returns:
+ A list of GroupTypeView objects that can be used in EZT.
+ """
+ group_types = [usergroup_pb2.GroupType.CHROME_INFRA_AUTH,
+ usergroup_pb2.GroupType.MDB,
+ usergroup_pb2.GroupType.BAGGINS]
+
+ return sorted([GroupTypeView(gt) for gt in group_types],
+ key=lambda gtv: gtv.name)
« 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