blob: bdfe86e74fe83a0320608fd13e8719ef5124cd86 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# 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.
Copybara854996b2021-09-07 19:36:02 +00004
5"""Class to show a servlet to clear a user's bouncing email timestamp."""
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
Copybara854996b2021-09-07 19:36:02 +000010import time
11
12from framework import framework_helpers
13from framework import permissions
14from framework import servlet
15from framework import timestr
16
17
18class 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ínezde942802022-07-15 14:06:55 +020061
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010062 def GetUserClearBouncingPage(self, **kwargs):
63 return self.handler(**kwargs)
Adrià Vilanova Martínezde942802022-07-15 14:06:55 +020064
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010065 def PostUserClearBouncingPage(self, **kwargs):
66 return self.handler(**kwargs)