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

Unified Diff: appengine/monorail/sitewide/grouplist.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/groupdetail.py ('k') | appengine/monorail/sitewide/hostinghome.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/monorail/sitewide/grouplist.py
diff --git a/appengine/monorail/sitewide/grouplist.py b/appengine/monorail/sitewide/grouplist.py
new file mode 100644
index 0000000000000000000000000000000000000000..a8852e90b711026b8087510c5cb2888bdcf64302
--- /dev/null
+++ b/appengine/monorail/sitewide/grouplist.py
@@ -0,0 +1,67 @@
+# 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
+
+"""Classes to list user groups."""
+
+import logging
+import time
+
+from third_party import ezt
+
+from framework import framework_helpers
+from framework import permissions
+from framework import servlet
+from framework import urls
+from framework import xsrf
+from sitewide import sitewide_views
+
+
+class GroupList(servlet.Servlet):
+ """Shows a page with a simple form to create a user group."""
+
+ _PAGE_TEMPLATE = 'sitewide/group-list-page.ezt'
+
+ def GatherPageData(self, mr):
+ """Build up a dictionary of data values to use when rendering the page."""
+ group_views = [
+ sitewide_views.GroupView(*groupinfo) for groupinfo in
+ self.services.usergroup.GetAllUserGroupsInfo(mr.cnxn)]
+ group_views.sort(key=lambda gv: gv.name)
+ offer_group_deletion = mr.perms.CanUsePerm(
+ permissions.DELETE_GROUP, mr.auth.effective_ids, None, [])
+ offer_group_creation = mr.perms.CanUsePerm(
+ permissions.CREATE_GROUP, mr.auth.effective_ids, None, [])
+
+ return {
+ 'form_token': xsrf.GenerateToken(
+ mr.auth.user_id, '%s.do' % urls.GROUP_DELETE),
+ 'groups': group_views,
+ 'offer_group_deletion': ezt.boolean(offer_group_deletion),
+ 'offer_group_creation': ezt.boolean(offer_group_creation),
+ }
+
+ def ProcessFormData(self, mr, post_data):
+ """Process the posted form."""
+ if 'removebtn' in post_data:
+ return self.ProcessDeleteGroups(mr, post_data)
+
+ def ProcessDeleteGroups(self, mr, post_data):
+ """Process request to delete groups."""
+ if not mr.perms.CanUsePerm(
+ permissions.DELETE_GROUP, mr.auth.effective_ids, None, []):
+ raise permissions.PermissionException(
+ 'User is not permitted to delete groups')
+
+ remove_groups = [int(g) for g in post_data.getall('remove')]
+
+ if not mr.errors.AnyErrors():
+ self.services.usergroup.DeleteGroups(mr.cnxn, remove_groups)
+
+ if mr.errors.AnyErrors():
+ self.PleaseCorrect(mr)
+ else:
+ return framework_helpers.FormatAbsoluteURL(
+ mr, '/g', include_project=False,
+ saved=1, ts=int(time.time()))
« no previous file with comments | « appengine/monorail/sitewide/groupdetail.py ('k') | appengine/monorail/sitewide/hostinghome.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698