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

Side by Side Diff: appengine/monorail/project/projectadmin.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
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 """Servlets for project administration main subtab."""
7
8 import logging
9 import time
10
11 from third_party import cloudstorage
12 from third_party import ezt
13
14 from framework import emailfmt
15 from framework import framework_bizobj
16 from framework import framework_constants
17 from framework import framework_helpers
18 from framework import gcs_helpers
19 from framework import permissions
20 from framework import servlet
21 from framework import urls
22 from framework import validate
23 from project import project_helpers
24 from project import project_views
25 from tracker import tracker_views
26
27
28 _MSG_INVALID_EMAIL_ADDRESS = 'Invalid email address'
29 _MSG_DESCRIPTION_MISSING = 'Description is missing'
30 _MSG_SUMMARY_MISSING = 'Summary is missing'
31
32
33 class ProjectAdmin(servlet.Servlet):
34 """A page with project configuration options for the Project Owner(s)."""
35
36 _PAGE_TEMPLATE = 'project/project-admin-page.ezt'
37 _MAIN_TAB_MODE = servlet.Servlet.MAIN_TAB_ADMIN
38
39 def AssertBasePermission(self, mr):
40 super(ProjectAdmin, self).AssertBasePermission(mr)
41 if not self.CheckPerm(mr, permissions.EDIT_PROJECT):
42 raise permissions.PermissionException(
43 'User is not allowed to administer this project')
44
45 def GatherPageData(self, mr):
46 """Build up a dictionary of data values to use when rendering the page."""
47 available_access_levels = project_helpers.BuildProjectAccessOptions(
48 mr.project)
49 offer_access_level = len(available_access_levels) > 1
50 access_view = project_views.ProjectAccessView(mr.project.access)
51
52 return {
53 'admin_tab_mode': self.ADMIN_TAB_META,
54 'initial_summary': mr.project.summary,
55 'initial_project_home': mr.project.home_page,
56 'initial_docs_url': mr.project.docs_url,
57 'initial_logo_gcs_id': mr.project.logo_gcs_id,
58 'initial_logo_file_name': mr.project.logo_file_name,
59 'logo_view': tracker_views.LogoView(mr.project),
60 'initial_description': mr.project.description,
61 'issue_notify': mr.project.issue_notify_address,
62 'process_inbound_email': ezt.boolean(
63 mr.project.process_inbound_email),
64 'email_from_addr': emailfmt.FormatFromAddr(mr.project),
65 'only_owners_remove_restrictions': ezt.boolean(
66 mr.project.only_owners_remove_restrictions),
67 'only_owners_see_contributors': ezt.boolean(
68 mr.project.only_owners_see_contributors),
69 'offer_access_level': ezt.boolean(offer_access_level),
70 'initial_access': access_view,
71 'available_access_levels': available_access_levels,
72 }
73
74 def ProcessFormData(self, mr, post_data):
75 """Process the posted form."""
76 # 1. Parse and validate user input.
77 summary, description = self._ParseMeta(post_data, mr.errors)
78 access = project_helpers.ParseProjectAccess(
79 mr.project, post_data.get('access'))
80
81 only_owners_remove_restrictions = (
82 'only_owners_remove_restrictions' in post_data)
83 only_owners_see_contributors = 'only_owners_see_contributors' in post_data
84
85 issue_notify = post_data['issue_notify']
86 if issue_notify and not validate.IsValidEmail(issue_notify):
87 mr.errors.issue_notify = _MSG_INVALID_EMAIL_ADDRESS
88
89 process_inbound_email = 'process_inbound_email' in post_data
90 home_page = post_data.get('project_home')
91 if home_page and not (
92 home_page.startswith('http:') or home_page.startswith('https:')):
93 mr.errors.project_home = 'Home page link must start with http: or https:'
94 docs_url = post_data.get('docs_url')
95 if docs_url and not (
96 docs_url.startswith('http:') or docs_url.startswith('https:')):
97 mr.errors.docs_url = 'Documentation link must start with http: or https:'
98
99 logo_gcs_id = ''
100 logo_file_name = ''
101 if 'logo' in post_data and not isinstance(post_data['logo'], basestring):
102 item = post_data['logo']
103 logo_file_name = item.filename
104 try:
105 logo_gcs_id = gcs_helpers.StoreLogoInGCS(
106 logo_file_name, item.value, mr.project.project_id)
107 except gcs_helpers.UnsupportedMimeType, e:
108 mr.errors.logo = e.message
109 elif mr.project.logo_gcs_id and mr.project.logo_file_name:
110 logo_gcs_id = mr.project.logo_gcs_id
111 logo_file_name = mr.project.logo_file_name
112 if post_data.get('delete_logo'):
113 try:
114 gcs_helpers.DeleteObjectFromGCS(logo_gcs_id)
115 except cloudstorage.NotFoundError:
116 pass
117 # Reset the GCS ID and file name.
118 logo_gcs_id = ''
119 logo_file_name = ''
120
121 # 2. Call services layer to save changes.
122 if not mr.errors.AnyErrors():
123 self.services.project.UpdateProject(
124 mr.cnxn, mr.project.project_id, issue_notify_address=issue_notify,
125 summary=summary, description=description,
126 only_owners_remove_restrictions=only_owners_remove_restrictions,
127 only_owners_see_contributors=only_owners_see_contributors,
128 process_inbound_email=process_inbound_email, access=access,
129 home_page=home_page, docs_url=docs_url,
130 logo_gcs_id=logo_gcs_id, logo_file_name=logo_file_name,
131 )
132
133 # 3. Determine the next page in the UI flow.
134 if mr.errors.AnyErrors():
135 access_view = project_views.ProjectAccessView(access)
136 self.PleaseCorrect(
137 mr, initial_summary=summary, initial_description=description,
138 initial_access=access_view)
139 else:
140 return framework_helpers.FormatAbsoluteURL(
141 mr, urls.ADMIN_META, saved=1, ts=int(time.time()))
142
143 def _ParseMeta(self, post_data, errors):
144 """Process a POST on the project metadata section of the admin page."""
145 summary = None
146 description = None
147
148 if 'summary' in post_data:
149 summary = post_data['summary']
150 if not summary:
151 errors.summary = _MSG_SUMMARY_MISSING
152 if 'description' in post_data:
153 description = post_data['description']
154 if not description:
155 errors.description = _MSG_DESCRIPTION_MISSING
156
157 return summary, description
OLDNEW
« no previous file with comments | « appengine/monorail/project/project_views.py ('k') | appengine/monorail/project/projectadminadvanced.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698