-
Notifications
You must be signed in to change notification settings - Fork 12
/
policies_datarequest_status.py
37 lines (27 loc) · 1.22 KB
/
policies_datarequest_status.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
"""Policy check functions for datarequest status transitions."""
__copyright__ = "Copyright (c) 2019-2024, Utrecht University"
__license__ = "GPLv3, see LICENSE"
import re
import datarequest
from util import *
def can_set_datarequest_status(ctx: rule.Context,
obj_name: str,
status_to: str) -> policy.Succeed | policy.Fail:
# Get current status.
try:
status_from = datarequest.status_get_from_path(ctx, obj_name)
except error.UUError:
return policy.fail('Could not get current datarequest status')
# Check if transition is valid.
transition = (datarequest.status(status_from),
datarequest.status(status_to))
if transition not in datarequest.status_transitions:
return policy.fail('Illegal datarequest status transition')
return policy.succeed()
def post_status_transition(ctx: rule.Context, obj_name: str, value: str) -> None:
# Write timestamp to provenance log
request_id = re.sub(r"^[^0-9]*/(\d+).*", r"\1", obj_name)
status = datarequest.status[value]
datarequest.datarequest_provenance_write(ctx, request_id, status)
# Send emails
datarequest.send_emails(ctx, obj_name, value)