-
Notifications
You must be signed in to change notification settings - Fork 12
/
policies_datarequest_status.py
38 lines (26 loc) · 1.1 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
38
# -*- coding: utf-8 -*-
"""Policy check functions for datarequest status transitions."""
__copyright__ = "Copyright (c) 2019-2020, Utrecht University"
__license__ = "GPLv3, see LICENSE"
import re
import datarequest
from util import *
def can_set_datarequest_status(ctx, obj_name, status_to):
# 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, obj_name, value):
# 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)