blob: ca2ab2db68fb609fcb77d70d60e0e864f7446f5a [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"""Helpers for showing alerts at the top of the page.
6
7These alerts are then displayed by alerts.ezt.
8"""
9from __future__ import print_function
10from __future__ import division
11from __future__ import absolute_import
12
13import time
14
15import ezt
16
17# Expiration time for special features of timestamped links.
18# This is not for security, just for informational messages that
19# make sense in the context of a user session, but that should
20# not appear days later if the user follows a bookmarked link.
21_LINK_EXPIRATION_SEC = 8
22
23
24class AlertsView(object):
25 """EZT object for showing alerts at the top of the page."""
26
27 def __init__(self, mr):
28 # Used to show message confirming item was updated
29 self.updated = mr.GetIntParam('updated')
30
31 # Used to show message confirming item was moved and the location of the new
32 # item.
33 self.moved_to_project = mr.GetParam('moved_to_project')
34 self.moved_to_id = mr.GetIntParam('moved_to_id')
35 self.moved = self.moved_to_project and self.moved_to_id
36
37 # Used to show message confirming item was copied and the location of the
38 # new item.
39 self.copied_from_id = mr.GetIntParam('copied_from_id')
40 self.copied_to_project = mr.GetParam('copied_to_project')
41 self.copied_to_id = mr.GetIntParam('copied_to_id')
42 self.copied = self.copied_to_project and self.copied_to_id
43
44 # Used to show message confirming items deleted
45 self.deleted = mr.GetParam('deleted')
46
47 # If present, we will show message confirming that data was saved
48 self.saved = mr.GetParam('saved')
49
50 link_generation_timestamp = mr.GetIntParam('ts', default_value=0)
51 now = int(time.time())
52 ts_links_are_valid = now - link_generation_timestamp < _LINK_EXPIRATION_SEC
53
54 show_alert = ts_links_are_valid and (
55 self.updated or self.moved or self.copied or self.deleted or self.saved)
56 self.show = ezt.boolean(show_alert)