blob: 3decdf46e045376063739caece1d61f54ae20ec6 [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
15from framework import permissions
16from framework import servlet
17from framework import timestr
18
19
20class UserClearBouncing(servlet.Servlet):
21 """Shows a page that can clear a user's bouncing email timestamp."""
22
23 _PAGE_TEMPLATE = 'sitewide/user-clear-bouncing-page.ezt'
24
25 def AssertBasePermission(self, mr):
26 """Check whether the user has any permission to visit this page.
27
28 Args:
29 mr: commonly used info parsed from the request.
30 """
31 super(UserClearBouncing, self).AssertBasePermission(mr)
32 if mr.auth.user_id == mr.viewed_user_auth.user_id:
33 return
34 if mr.perms.HasPerm(permissions.EDIT_OTHER_USERS, None, None):
35 return
36 raise permissions.PermissionException('You cannot edit this user.')
37
38 def GatherPageData(self, mr):
39 """Build up a dictionary of data values to use when rendering the page."""
40 viewed_user = mr.viewed_user_auth.user_pb
41 if viewed_user.email_bounce_timestamp:
42 last_bounce_str = timestr.FormatRelativeDate(
43 viewed_user.email_bounce_timestamp, days_only=True)
44 last_bounce_str = last_bounce_str or 'Less than 2 days ago'
45 else:
46 last_bounce_str = None
47
48 page_data = {
49 'user_tab_mode': 'st2',
50 'last_bounce_str': last_bounce_str,
51 }
52 return page_data
53
54 def ProcessFormData(self, mr, post_data):
55 """Process the posted form."""
56 viewed_user = mr.viewed_user_auth.user_pb
57 viewed_user.email_bounce_timestamp = None
58 self.services.user.UpdateUser(
59 mr.cnxn, viewed_user.user_id, viewed_user)
60 return framework_helpers.FormatAbsoluteURL(
61 mr, mr.viewed_user_auth.user_view.profile_url, include_project=False,
62 saved=1, ts=int(time.time()))