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