forked from CyberCX-STA/PurpleOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
49 lines (44 loc) · 1.57 KB
/
utils.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
from datetime import datetime, timedelta
from model import TestCase
from flask_security import current_user
from functools import wraps
def applyFormData (obj, form, fields):
for field in fields:
if field in form: # and form[field]:
obj[field] = form[field]
return obj
def applyFormListData (obj, form, fields):
for field in fields:
if field in form: # and form[field]:
obj[field] = form.getlist(field)
return obj
def applyFormBoolData (obj, form, fields):
for field in fields:
if field in form: # and form[field]:
obj[field] = form[field].lower() in ["true", "yes", "on"]
return obj
def applyFormTimeData (obj, form, fields):
for field in fields:
if field in form: # and form[field]:
if form[field] and form[field] != "None":
localTime = datetime.strptime(form[field], "%Y-%m-%dT%H:%M")
utcTime = localTime + timedelta(minutes=int(form["timezone"]))
obj[field] = utcTime
else:
obj[field] = None
return obj
def user_assigned_assessment(f):
@wraps(f)
def inner(*args, **kwargs):
if current_user.has_role("Admin"):
return f(*args, **kwargs)
id = kwargs.get("id")
if not id:
id = args[0]
if TestCase.objects(id=id).count():
id = TestCase.objects(id=id).first().assessmentid
if (id in [str(a.id) for a in current_user.assessments]):
return f(*args, **kwargs)
else:
return ("", 403)
return inner