OLD | NEW |
(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 """Page for showing a user's saved queries and subscription options.""" |
| 7 |
| 8 import logging |
| 9 import time |
| 10 |
| 11 from features import savedqueries_helpers |
| 12 from framework import framework_helpers |
| 13 from framework import permissions |
| 14 from framework import servlet |
| 15 from framework import urls |
| 16 |
| 17 |
| 18 class SavedQueries(servlet.Servlet): |
| 19 """A page class that shows the user's saved queries.""" |
| 20 |
| 21 _PAGE_TEMPLATE = 'features/saved-queries-page.ezt' |
| 22 |
| 23 def AssertBasePermission(self, mr): |
| 24 super(SavedQueries, self).AssertBasePermission(mr) |
| 25 viewing_self = mr.viewed_user_auth.user_id == mr.auth.user_id |
| 26 if not mr.auth.user_pb.is_site_admin and not viewing_self: |
| 27 raise permissions.PermissionException( |
| 28 'User not allowed to edit this user\'s saved queries') |
| 29 |
| 30 def GatherPageData(self, mr): |
| 31 """Build up a dictionary of data values to use when rendering the page.""" |
| 32 saved_queries = self.services.features.GetSavedQueriesByUserID( |
| 33 mr.cnxn, mr.viewed_user_auth.user_id) |
| 34 saved_query_views = [ |
| 35 savedqueries_helpers.SavedQueryView( |
| 36 sq, idx + 1, mr.cnxn, self.services.project) |
| 37 for idx, sq in enumerate(saved_queries)] |
| 38 |
| 39 page_data = { |
| 40 'canned_queries': saved_query_views, |
| 41 'new_query_indexes': ( |
| 42 range(len(saved_queries) + 1, |
| 43 savedqueries_helpers.MAX_QUERIES + 1)), |
| 44 'max_queries': savedqueries_helpers.MAX_QUERIES, |
| 45 'user_tab_mode': 'st4', |
| 46 } |
| 47 return page_data |
| 48 |
| 49 def ProcessFormData(self, mr, post_data): |
| 50 """Validate and store the contents of the issues tracker admin page. |
| 51 |
| 52 Args: |
| 53 mr: commonly used info parsed from the request. |
| 54 post_data: HTML form data from the request. |
| 55 |
| 56 Returns: |
| 57 String URL to redirect the user to, or None if response was already sent. |
| 58 """ |
| 59 existing_queries = savedqueries_helpers.ParseSavedQueries( |
| 60 mr.cnxn, post_data, self.services.project) |
| 61 added_queries = savedqueries_helpers.ParseSavedQueries( |
| 62 mr.cnxn, post_data, self.services.project, prefix='new_') |
| 63 saved_queries = existing_queries + added_queries |
| 64 |
| 65 self.services.features.UpdateUserSavedQueries( |
| 66 mr.cnxn, mr.viewed_user_auth.user_id, saved_queries) |
| 67 |
| 68 return framework_helpers.FormatAbsoluteURL( |
| 69 mr, '/u/%s%s' % (mr.viewed_username, urls.SAVED_QUERIES), |
| 70 include_project=False, saved=1, ts=int(time.time())) |
OLD | NEW |