Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | # Copyright 2016 The Chromium Authors |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 4 | |
| 5 | """Class to show a servlet to clear a user's bouncing email timestamp.""" |
| 6 | from __future__ import print_function |
| 7 | from __future__ import division |
| 8 | from __future__ import absolute_import |
| 9 | |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 10 | import time |
| 11 | |
| 12 | from framework import framework_helpers |
| 13 | from framework import permissions |
| 14 | from framework import servlet |
| 15 | from framework import timestr |
| 16 | |
| 17 | |
| 18 | class UserClearBouncing(servlet.Servlet): |
| 19 | """Shows a page that can clear a user's bouncing email timestamp.""" |
| 20 | |
| 21 | _PAGE_TEMPLATE = 'sitewide/user-clear-bouncing-page.ezt' |
| 22 | |
| 23 | def AssertBasePermission(self, mr): |
| 24 | """Check whether the user has any permission to visit this page. |
| 25 | |
| 26 | Args: |
| 27 | mr: commonly used info parsed from the request. |
| 28 | """ |
| 29 | super(UserClearBouncing, self).AssertBasePermission(mr) |
| 30 | if mr.auth.user_id == mr.viewed_user_auth.user_id: |
| 31 | return |
| 32 | if mr.perms.HasPerm(permissions.EDIT_OTHER_USERS, None, None): |
| 33 | return |
| 34 | raise permissions.PermissionException('You cannot edit this user.') |
| 35 | |
| 36 | def GatherPageData(self, mr): |
| 37 | """Build up a dictionary of data values to use when rendering the page.""" |
| 38 | viewed_user = mr.viewed_user_auth.user_pb |
| 39 | if viewed_user.email_bounce_timestamp: |
| 40 | last_bounce_str = timestr.FormatRelativeDate( |
| 41 | viewed_user.email_bounce_timestamp, days_only=True) |
| 42 | last_bounce_str = last_bounce_str or 'Less than 2 days ago' |
| 43 | else: |
| 44 | last_bounce_str = None |
| 45 | |
| 46 | page_data = { |
| 47 | 'user_tab_mode': 'st2', |
| 48 | 'last_bounce_str': last_bounce_str, |
| 49 | } |
| 50 | return page_data |
| 51 | |
| 52 | def ProcessFormData(self, mr, post_data): |
| 53 | """Process the posted form.""" |
| 54 | viewed_user = mr.viewed_user_auth.user_pb |
| 55 | viewed_user.email_bounce_timestamp = None |
| 56 | self.services.user.UpdateUser( |
| 57 | mr.cnxn, viewed_user.user_id, viewed_user) |
| 58 | return framework_helpers.FormatAbsoluteURL( |
| 59 | mr, mr.viewed_user_auth.user_view.profile_url, include_project=False, |
| 60 | saved=1, ts=int(time.time())) |
Adrià Vilanova Martínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 61 | |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 62 | def GetUserClearBouncingPage(self, **kwargs): |
| 63 | return self.handler(**kwargs) |
Adrià Vilanova Martínez | de94280 | 2022-07-15 14:06:55 +0200 | [diff] [blame] | 64 | |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 65 | def PostUserClearBouncingPage(self, **kwargs): |
| 66 | return self.handler(**kwargs) |