This repository was archived by the owner on Jan 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEventLogger.py
63 lines (54 loc) · 2.35 KB
/
EventLogger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# EventLogger.py - event logging system for Recent Updates pane
# part of Sluggo, a free and open source issue tracker
# Copyright (c) 2020 Slugbotics - see git repository history for individual committers
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
from datetime import datetime, timezone
import json
from . common import db, Field, auth
from . helper import Helper
class EventLogger:
@staticmethod
def log_comment(content, ticket_id, action_auth_user):
db.events.insert(
type="post-comment",
description=content,
related_ticket=ticket_id,
action_user=action_auth_user
)
print("Logged comment by user " + str(action_auth_user) + " with message " + str(content) + " on ticket " +\
str(ticket_id))
@staticmethod
def log_status_change(status, ticket_id, action_auth_user):
db.events.insert(
type="ticket-status-change",
description=status,
related_ticket=ticket_id,
action_user=action_auth_user
)
print("Logged status change by user " + str(action_auth_user) + " with status " + str(status) + " on ticket " +\
str(ticket_id))
@staticmethod
def get_recent_updates_for_user(user_id):
events = []
# Get events pertaining to any pinned tickets
pinned_ticket_ids = Helper.get_pinned_ticket_ids_for_user(user_id)
for ptid in pinned_ticket_ids:
# Grab events
events += db(db.events.related_ticket == ptid).select().as_list()
# Get events pertaining to any assigned tickets
assigned_tickets_ids = Helper.get_assigned_ticket_ids_for_user(user_id)
for atid in assigned_tickets_ids:
# Grab events
atevents = db(db.events.related_ticket == atid).select().as_list()
for atevent in atevents:
if atevent not in events:
events.append(atevent) # does this code confuse you? GOOD
# Sort and limit
# TODO: This won't work well as the number of events gets very large
events.sort(key=lambda x: x["id"], reverse=True)
events = events[:3]
return events