wbcompliance 2.2.1__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wbcompliance/__init__.py +1 -0
- wbcompliance/admin/__init__.py +16 -0
- wbcompliance/admin/compliance_form.py +56 -0
- wbcompliance/admin/compliance_task.py +135 -0
- wbcompliance/admin/compliance_type.py +8 -0
- wbcompliance/admin/risk_management/__init__.py +3 -0
- wbcompliance/admin/risk_management/checks.py +7 -0
- wbcompliance/admin/risk_management/incidents.py +50 -0
- wbcompliance/admin/risk_management/rules.py +63 -0
- wbcompliance/admin/utils.py +46 -0
- wbcompliance/apps.py +14 -0
- wbcompliance/factories/__init__.py +21 -0
- wbcompliance/factories/compliance.py +246 -0
- wbcompliance/factories/risk_management/__init__.py +12 -0
- wbcompliance/factories/risk_management/backends.py +42 -0
- wbcompliance/factories/risk_management/checks.py +12 -0
- wbcompliance/factories/risk_management/incidents.py +84 -0
- wbcompliance/factories/risk_management/rules.py +100 -0
- wbcompliance/filters/__init__.py +2 -0
- wbcompliance/filters/compliances.py +189 -0
- wbcompliance/filters/risk_management/__init__.py +3 -0
- wbcompliance/filters/risk_management/checks.py +22 -0
- wbcompliance/filters/risk_management/incidents.py +113 -0
- wbcompliance/filters/risk_management/rules.py +110 -0
- wbcompliance/filters/risk_management/tables.py +112 -0
- wbcompliance/filters/risk_management/utils.py +3 -0
- wbcompliance/management/__init__.py +10 -0
- wbcompliance/migrations/0001_initial_squashed_squashed_0010_alter_checkedobjectincidentrelationship_resolved_by_and_more.py +1744 -0
- wbcompliance/migrations/0011_alter_riskrule_parameters.py +21 -0
- wbcompliance/migrations/0012_alter_compliancetype_options.py +20 -0
- wbcompliance/migrations/0013_alter_riskrule_unique_together.py +16 -0
- wbcompliance/migrations/0014_alter_reviewcompliancetask_year.py +27 -0
- wbcompliance/migrations/0015_auto_20240103_0957.py +43 -0
- wbcompliance/migrations/0016_checkedobjectincidentrelationship_report_details_and_more.py +37 -0
- wbcompliance/migrations/0017_alter_rulebackend_incident_report_template.py +20 -0
- wbcompliance/migrations/0018_alter_rulecheckedobjectrelationship_unique_together.py +39 -0
- wbcompliance/migrations/0019_rulegroup_riskrule_activation_date_and_more.py +60 -0
- wbcompliance/migrations/__init__.py +0 -0
- wbcompliance/models/__init__.py +20 -0
- wbcompliance/models/compliance_form.py +626 -0
- wbcompliance/models/compliance_task.py +800 -0
- wbcompliance/models/compliance_type.py +133 -0
- wbcompliance/models/enums.py +13 -0
- wbcompliance/models/risk_management/__init__.py +4 -0
- wbcompliance/models/risk_management/backend.py +139 -0
- wbcompliance/models/risk_management/checks.py +194 -0
- wbcompliance/models/risk_management/dispatch.py +41 -0
- wbcompliance/models/risk_management/incidents.py +619 -0
- wbcompliance/models/risk_management/mixins.py +115 -0
- wbcompliance/models/risk_management/rules.py +654 -0
- wbcompliance/permissions.py +32 -0
- wbcompliance/serializers/__init__.py +30 -0
- wbcompliance/serializers/compliance_form.py +320 -0
- wbcompliance/serializers/compliance_task.py +463 -0
- wbcompliance/serializers/compliance_type.py +26 -0
- wbcompliance/serializers/risk_management/__init__.py +19 -0
- wbcompliance/serializers/risk_management/checks.py +53 -0
- wbcompliance/serializers/risk_management/incidents.py +227 -0
- wbcompliance/serializers/risk_management/rules.py +158 -0
- wbcompliance/tasks.py +112 -0
- wbcompliance/tests/__init__.py +0 -0
- wbcompliance/tests/conftest.py +63 -0
- wbcompliance/tests/disable_signals.py +82 -0
- wbcompliance/tests/mixins.py +17 -0
- wbcompliance/tests/risk_management/__init__.py +0 -0
- wbcompliance/tests/risk_management/models/__init__.py +0 -0
- wbcompliance/tests/risk_management/models/test_backends.py +0 -0
- wbcompliance/tests/risk_management/models/test_checks.py +55 -0
- wbcompliance/tests/risk_management/models/test_incidents.py +327 -0
- wbcompliance/tests/risk_management/models/test_rules.py +255 -0
- wbcompliance/tests/signals.py +89 -0
- wbcompliance/tests/test_filters.py +23 -0
- wbcompliance/tests/test_models.py +57 -0
- wbcompliance/tests/test_serializers.py +48 -0
- wbcompliance/tests/test_views.py +377 -0
- wbcompliance/tests/tests.py +21 -0
- wbcompliance/urls.py +238 -0
- wbcompliance/viewsets/__init__.py +40 -0
- wbcompliance/viewsets/buttons/__init__.py +9 -0
- wbcompliance/viewsets/buttons/compliance_form.py +78 -0
- wbcompliance/viewsets/buttons/compliance_task.py +149 -0
- wbcompliance/viewsets/buttons/risk_managment/__init__.py +3 -0
- wbcompliance/viewsets/buttons/risk_managment/checks.py +11 -0
- wbcompliance/viewsets/buttons/risk_managment/incidents.py +51 -0
- wbcompliance/viewsets/buttons/risk_managment/rules.py +35 -0
- wbcompliance/viewsets/compliance_form.py +425 -0
- wbcompliance/viewsets/compliance_task.py +513 -0
- wbcompliance/viewsets/compliance_type.py +38 -0
- wbcompliance/viewsets/display/__init__.py +22 -0
- wbcompliance/viewsets/display/compliance_form.py +317 -0
- wbcompliance/viewsets/display/compliance_task.py +453 -0
- wbcompliance/viewsets/display/compliance_type.py +22 -0
- wbcompliance/viewsets/display/risk_managment/__init__.py +11 -0
- wbcompliance/viewsets/display/risk_managment/checks.py +46 -0
- wbcompliance/viewsets/display/risk_managment/incidents.py +155 -0
- wbcompliance/viewsets/display/risk_managment/rules.py +146 -0
- wbcompliance/viewsets/display/risk_managment/tables.py +51 -0
- wbcompliance/viewsets/endpoints/__init__.py +27 -0
- wbcompliance/viewsets/endpoints/compliance_form.py +207 -0
- wbcompliance/viewsets/endpoints/compliance_task.py +193 -0
- wbcompliance/viewsets/endpoints/compliance_type.py +9 -0
- wbcompliance/viewsets/endpoints/risk_managment/__init__.py +12 -0
- wbcompliance/viewsets/endpoints/risk_managment/checks.py +16 -0
- wbcompliance/viewsets/endpoints/risk_managment/incidents.py +36 -0
- wbcompliance/viewsets/endpoints/risk_managment/rules.py +32 -0
- wbcompliance/viewsets/endpoints/risk_managment/tables.py +14 -0
- wbcompliance/viewsets/menu/__init__.py +17 -0
- wbcompliance/viewsets/menu/compliance_form.py +49 -0
- wbcompliance/viewsets/menu/compliance_task.py +130 -0
- wbcompliance/viewsets/menu/compliance_type.py +17 -0
- wbcompliance/viewsets/menu/risk_management.py +56 -0
- wbcompliance/viewsets/risk_management/__init__.py +21 -0
- wbcompliance/viewsets/risk_management/checks.py +49 -0
- wbcompliance/viewsets/risk_management/incidents.py +204 -0
- wbcompliance/viewsets/risk_management/mixins.py +52 -0
- wbcompliance/viewsets/risk_management/rules.py +179 -0
- wbcompliance/viewsets/risk_management/tables.py +96 -0
- wbcompliance/viewsets/titles/__init__.py +17 -0
- wbcompliance/viewsets/titles/compliance_form.py +101 -0
- wbcompliance/viewsets/titles/compliance_task.py +60 -0
- wbcompliance/viewsets/titles/compliance_type.py +13 -0
- wbcompliance/viewsets/titles/risk_managment/__init__.py +1 -0
- wbcompliance/viewsets/titles/risk_managment/checks.py +0 -0
- wbcompliance/viewsets/titles/risk_managment/incidents.py +0 -0
- wbcompliance/viewsets/titles/risk_managment/rules.py +0 -0
- wbcompliance/viewsets/titles/risk_managment/tables.py +7 -0
- wbcompliance-2.2.1.dist-info/METADATA +7 -0
- wbcompliance-2.2.1.dist-info/RECORD +129 -0
- wbcompliance-2.2.1.dist-info/WHEEL +5 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from django.utils.translation import gettext as _
|
|
4
|
+
from rest_framework.reverse import reverse
|
|
5
|
+
from wbcompliance.models.risk_management import RiskIncident, RiskIncidentType
|
|
6
|
+
from wbcore.contrib.icons import WBIcon
|
|
7
|
+
from wbcore.metadata.configs import display as dp
|
|
8
|
+
from wbcore.metadata.configs.display.instance_display.shortcuts import (
|
|
9
|
+
Display,
|
|
10
|
+
create_simple_display,
|
|
11
|
+
create_simple_section,
|
|
12
|
+
)
|
|
13
|
+
from wbcore.metadata.configs.display.instance_display.utils import repeat_field
|
|
14
|
+
from wbcore.metadata.configs.display.view_config import DisplayViewConfig
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def get_formatting(id_field="id", color=False):
|
|
18
|
+
formattings = []
|
|
19
|
+
for _type in RiskIncidentType.objects.all():
|
|
20
|
+
style = {"backgroundColor": _type.color}
|
|
21
|
+
if color:
|
|
22
|
+
style["color"] = _type.color
|
|
23
|
+
formattings.append(
|
|
24
|
+
dp.FormattingRule(
|
|
25
|
+
style=style,
|
|
26
|
+
condition=("==", getattr(_type, id_field)),
|
|
27
|
+
),
|
|
28
|
+
)
|
|
29
|
+
return dp.Formatting(column="severity", formatting_rules=formattings)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def get_legends():
|
|
33
|
+
legends = []
|
|
34
|
+
for _type in RiskIncidentType.objects.all():
|
|
35
|
+
legends.append(dp.LegendItem(icon=_type.color, label=_type.name, value=_type.id))
|
|
36
|
+
return dp.Legend(items=legends, key="severity")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class RiskIncidentDisplayConfig(DisplayViewConfig):
|
|
40
|
+
def get_list_display(self) -> Optional[dp.ListDisplay]:
|
|
41
|
+
fields = [
|
|
42
|
+
dp.Field(
|
|
43
|
+
key=None,
|
|
44
|
+
label="Rule",
|
|
45
|
+
open_by_default=False,
|
|
46
|
+
children=[
|
|
47
|
+
dp.Field(key="status", label=_("Status"), show="open"),
|
|
48
|
+
dp.Field(key="object_repr", label=_("Object")),
|
|
49
|
+
dp.Field(key="rule", label=_("Rule")),
|
|
50
|
+
dp.Field(key="threshold_repr", label=_("Breached Threshold")),
|
|
51
|
+
],
|
|
52
|
+
),
|
|
53
|
+
dp.Field(
|
|
54
|
+
key=None,
|
|
55
|
+
label="Incident",
|
|
56
|
+
open_by_default=False,
|
|
57
|
+
children=[
|
|
58
|
+
dp.Field(key="breached_value", label=_("Breached Value")),
|
|
59
|
+
dp.Field(key="report", label=_("Report Detail"), show="open"),
|
|
60
|
+
dp.Field(key="checked_date", label=_("Date"), show="open"),
|
|
61
|
+
],
|
|
62
|
+
),
|
|
63
|
+
dp.Field(
|
|
64
|
+
key=None,
|
|
65
|
+
label="Management",
|
|
66
|
+
open_by_default=False,
|
|
67
|
+
children=[
|
|
68
|
+
dp.Field(key="resolved_by", label=_("Resolved By")),
|
|
69
|
+
dp.Field(key="is_notified", label=_("Users notified"), show="open"),
|
|
70
|
+
dp.Field(key="ignore_until", label=_("Ignored Until"), show="open"),
|
|
71
|
+
dp.Field(key="comment", label=_("Comment"), show="open"),
|
|
72
|
+
],
|
|
73
|
+
),
|
|
74
|
+
]
|
|
75
|
+
return dp.ListDisplay(
|
|
76
|
+
fields=fields,
|
|
77
|
+
tree=True,
|
|
78
|
+
tree_group_level_options=[
|
|
79
|
+
dp.TreeGroupLevelOption(
|
|
80
|
+
filter_key="incident",
|
|
81
|
+
filter_depth=1,
|
|
82
|
+
clear_filter=True,
|
|
83
|
+
list_endpoint=reverse(
|
|
84
|
+
"wbcompliance:checkedobjectincidentrelationship-list",
|
|
85
|
+
args=[],
|
|
86
|
+
request=self.request,
|
|
87
|
+
),
|
|
88
|
+
)
|
|
89
|
+
],
|
|
90
|
+
# tree_group_lookup="id_repr",
|
|
91
|
+
tree_group_pinned="left",
|
|
92
|
+
tree_group_field="date_range",
|
|
93
|
+
tree_group_label=_("Date Range"),
|
|
94
|
+
legends=[
|
|
95
|
+
get_legends(),
|
|
96
|
+
dp.Legend(
|
|
97
|
+
key="status",
|
|
98
|
+
items=[
|
|
99
|
+
dp.LegendItem(
|
|
100
|
+
icon=WBIcon.VIEW.icon,
|
|
101
|
+
label=_("{} Incidents").format(RiskIncident.Status.OPEN.label),
|
|
102
|
+
value=RiskIncident.Status.OPEN.name,
|
|
103
|
+
),
|
|
104
|
+
],
|
|
105
|
+
),
|
|
106
|
+
],
|
|
107
|
+
formatting=[
|
|
108
|
+
get_formatting(),
|
|
109
|
+
dp.Formatting(
|
|
110
|
+
column="status",
|
|
111
|
+
formatting_rules=[
|
|
112
|
+
dp.FormattingRule(
|
|
113
|
+
icon=WBIcon.VIEW.icon,
|
|
114
|
+
condition=("==", RiskIncident.Status.OPEN.name),
|
|
115
|
+
)
|
|
116
|
+
],
|
|
117
|
+
),
|
|
118
|
+
],
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
def get_instance_display(self) -> Display:
|
|
122
|
+
return create_simple_display(
|
|
123
|
+
[
|
|
124
|
+
[repeat_field(3, "status")],
|
|
125
|
+
["date_range", "rule", "severity"],
|
|
126
|
+
["breached_content_type", "breached_object_id", "breached_object_repr"],
|
|
127
|
+
["comment", "resolved_by", "ignore_until"],
|
|
128
|
+
[repeat_field(3, "relationships_section")],
|
|
129
|
+
],
|
|
130
|
+
[
|
|
131
|
+
create_simple_section(
|
|
132
|
+
"relationships_section", _("Relationships"), [["relationships"]], "relationships", collapsed=False
|
|
133
|
+
)
|
|
134
|
+
],
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
class CheckedObjectIncidentRelationshipRiskRuleDisplayConfig(DisplayViewConfig):
|
|
139
|
+
def get_list_display(self) -> Optional[dp.ListDisplay]:
|
|
140
|
+
return dp.ListDisplay(
|
|
141
|
+
fields=[
|
|
142
|
+
dp.Field(key="status", label=_("status")),
|
|
143
|
+
dp.Field(key="checked_date", label=_("Date")),
|
|
144
|
+
dp.Field(key="rule_check", label=_("Check")),
|
|
145
|
+
dp.Field(key="checked_object", label=_("Checked Object")),
|
|
146
|
+
dp.Field(key="breached_value", label=_("Breached Value")),
|
|
147
|
+
dp.Field(key="report", label=_("Report")),
|
|
148
|
+
dp.Field(key="resolved_by", label=_("resolved_by")),
|
|
149
|
+
dp.Field(key="comment", label=_("comment")),
|
|
150
|
+
],
|
|
151
|
+
legends=[get_legends()],
|
|
152
|
+
formatting=[
|
|
153
|
+
get_formatting(),
|
|
154
|
+
],
|
|
155
|
+
)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from django.utils.translation import gettext as _
|
|
4
|
+
from wbcore.contrib.color.enums import WBColor
|
|
5
|
+
from wbcore.enums import Unit
|
|
6
|
+
from wbcore.metadata.configs import display as dp
|
|
7
|
+
from wbcore.metadata.configs.display.instance_display.shortcuts import (
|
|
8
|
+
Display,
|
|
9
|
+
create_simple_display,
|
|
10
|
+
create_simple_section,
|
|
11
|
+
)
|
|
12
|
+
from wbcore.metadata.configs.display.instance_display.utils import repeat_field
|
|
13
|
+
from wbcore.metadata.configs.display.view_config import DisplayViewConfig
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class RuleThresholdRiskRuleDisplayConfig(DisplayViewConfig):
|
|
17
|
+
def get_list_display(self) -> Optional[dp.ListDisplay]:
|
|
18
|
+
return dp.ListDisplay(
|
|
19
|
+
fields=[
|
|
20
|
+
# dp.Field(key="range", label=_("Range")),
|
|
21
|
+
dp.Field(key="range_lower", label=_("Lower Range")),
|
|
22
|
+
dp.Field(key="range_upper", label=_("Upper Range")),
|
|
23
|
+
dp.Field(key="severity", label=_("Severity")),
|
|
24
|
+
dp.Field(key="notifiable_users", label=_("Notifiable Users")),
|
|
25
|
+
dp.Field(key="notifiable_groups", label=_("Notifiable Groups")),
|
|
26
|
+
dp.Field(key="upgradable_after_days", label=_("Upgrade severity after")),
|
|
27
|
+
]
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
def get_instance_display(self) -> Display:
|
|
31
|
+
return create_simple_display(
|
|
32
|
+
[
|
|
33
|
+
["severity", "upgradable_after_days", "range_lower", "range_upper"],
|
|
34
|
+
[repeat_field(2, "notifiable_users"), repeat_field(2, "notifiable_groups")],
|
|
35
|
+
]
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class RuleCheckedObjectRelationshipRiskRuleDisplayConfig(DisplayViewConfig):
|
|
40
|
+
def get_list_display(self) -> Optional[dp.ListDisplay]:
|
|
41
|
+
return dp.ListDisplay(
|
|
42
|
+
fields=[
|
|
43
|
+
# dp.Field(key="checked_object_content_type", label=_("Content Type")),
|
|
44
|
+
# dp.Field(key="checked_object_id", label=_("Object ID")),
|
|
45
|
+
dp.Field(key="checked_object_repr", label=_("Checked Objects")),
|
|
46
|
+
]
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
def get_instance_display(self) -> Display:
|
|
50
|
+
return create_simple_display([["checked_object_id" if self.new_mode else "checked_object_repr"]])
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class RiskRuleDisplayConfig(DisplayViewConfig):
|
|
54
|
+
def get_list_display(self) -> Optional[dp.ListDisplay]:
|
|
55
|
+
return dp.ListDisplay(
|
|
56
|
+
fields=[
|
|
57
|
+
dp.Field(key="name", label=_("Name"), width=Unit.PIXEL(300)),
|
|
58
|
+
dp.Field(key="description", label=_("Description")),
|
|
59
|
+
dp.Field(key="open_incidents_count", label=_("Open Incidents")),
|
|
60
|
+
dp.Field(key="is_enable", label=_("Enable")),
|
|
61
|
+
dp.Field(key="only_passive_check_allowed", label=_("Passive Only")),
|
|
62
|
+
dp.Field(
|
|
63
|
+
key=None,
|
|
64
|
+
label="Administration",
|
|
65
|
+
open_by_default=False,
|
|
66
|
+
children=[
|
|
67
|
+
dp.Field(key="rule_backend", label=_("Rule Backend"), width=Unit.PIXEL(200)),
|
|
68
|
+
dp.Field(key="frequency", label=_("Frequency"), width=Unit.PIXEL(200)),
|
|
69
|
+
dp.Field(key="activation_date", label=_("Activation Date"), width=Unit.PIXEL(200)),
|
|
70
|
+
dp.Field(key="is_silent", label=_("Silent"), show="open"),
|
|
71
|
+
dp.Field(key="is_mandatory", label=_("Mandatory"), show="open"),
|
|
72
|
+
dp.Field(
|
|
73
|
+
key="automatically_close_incident", label=_("Automatically Close Incidents"), show="open"
|
|
74
|
+
),
|
|
75
|
+
dp.Field(key="apply_to_all_active_relationships", label=_("All Checked Objects"), show="open"),
|
|
76
|
+
dp.Field(key="permission_type", label=_("Permission"), show="open"),
|
|
77
|
+
],
|
|
78
|
+
),
|
|
79
|
+
],
|
|
80
|
+
legends=[
|
|
81
|
+
dp.Legend(
|
|
82
|
+
key="in_breach",
|
|
83
|
+
items=[
|
|
84
|
+
dp.LegendItem(icon=WBColor.RED_LIGHT.value, label=_("In Breach"), value="BREACH"),
|
|
85
|
+
dp.LegendItem(icon=WBColor.GREEN_LIGHT.value, label=_("Passed"), value="PASSED"),
|
|
86
|
+
],
|
|
87
|
+
),
|
|
88
|
+
],
|
|
89
|
+
formatting=[
|
|
90
|
+
dp.Formatting(
|
|
91
|
+
column="in_breach",
|
|
92
|
+
formatting_rules=[
|
|
93
|
+
dp.FormattingRule(
|
|
94
|
+
style={"backgroundColor": WBColor.RED_LIGHT.value},
|
|
95
|
+
condition=("==", "BREACH"),
|
|
96
|
+
),
|
|
97
|
+
dp.FormattingRule(
|
|
98
|
+
style={"backgroundColor": WBColor.GREEN_LIGHT.value},
|
|
99
|
+
condition=("==", "PASSED"),
|
|
100
|
+
),
|
|
101
|
+
],
|
|
102
|
+
)
|
|
103
|
+
],
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
def get_instance_display(self) -> Display:
|
|
107
|
+
try:
|
|
108
|
+
rule = self.view.get_object()
|
|
109
|
+
parameter_fields = [
|
|
110
|
+
[
|
|
111
|
+
f"parameters__{field}"
|
|
112
|
+
for field in rule.rule_backend.backend_class.get_serializer_class().get_parameter_fields()
|
|
113
|
+
]
|
|
114
|
+
]
|
|
115
|
+
except Exception:
|
|
116
|
+
parameter_fields = [["parameters"]]
|
|
117
|
+
return create_simple_display(
|
|
118
|
+
[
|
|
119
|
+
[repeat_field(2, "name"), repeat_field(2, "rule_backend"), "is_enable"],
|
|
120
|
+
["permission_type", "frequency", "activation_date", repeat_field(2, "creator")],
|
|
121
|
+
[
|
|
122
|
+
"only_passive_check_allowed",
|
|
123
|
+
"is_silent",
|
|
124
|
+
"is_mandatory",
|
|
125
|
+
"automatically_close_incident",
|
|
126
|
+
"apply_to_all_active_relationships",
|
|
127
|
+
],
|
|
128
|
+
[repeat_field(5, "description")],
|
|
129
|
+
[repeat_field(5, "parameters_section")],
|
|
130
|
+
[repeat_field(5, "thresholds_section")],
|
|
131
|
+
[repeat_field(5, "relationships_section")],
|
|
132
|
+
[repeat_field(5, "incidents_section")],
|
|
133
|
+
],
|
|
134
|
+
[
|
|
135
|
+
create_simple_section("parameters_section", _("Parameters"), parameter_fields, collapsed=True),
|
|
136
|
+
create_simple_section(
|
|
137
|
+
"thresholds_section", _("Thresholds"), [["thresholds"]], "thresholds", collapsed=True
|
|
138
|
+
),
|
|
139
|
+
create_simple_section(
|
|
140
|
+
"relationships_section", _("Relationships"), [["relationships"]], "relationships", collapsed=True
|
|
141
|
+
),
|
|
142
|
+
create_simple_section(
|
|
143
|
+
"incidents_section", _("Incidents"), [["incidents"]], "incidents", collapsed=False
|
|
144
|
+
),
|
|
145
|
+
],
|
|
146
|
+
)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from django.utils.translation import gettext as _
|
|
4
|
+
from wbcore.contrib.color.enums import WBColor
|
|
5
|
+
from wbcore.enums import Unit
|
|
6
|
+
from wbcore.metadata.configs import display as dp
|
|
7
|
+
from wbcore.metadata.configs.display.view_config import DisplayViewConfig
|
|
8
|
+
|
|
9
|
+
from .incidents import get_formatting, get_legends
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class RiskManagementIncidentTableDisplayConfig(DisplayViewConfig):
|
|
13
|
+
def get_list_display(self) -> Optional[dp.ListDisplay]:
|
|
14
|
+
if content_type := self.view.checked_object_content_type:
|
|
15
|
+
field_name = content_type.name
|
|
16
|
+
else:
|
|
17
|
+
field_name = "Checked object"
|
|
18
|
+
fields = [
|
|
19
|
+
dp.Field(
|
|
20
|
+
key="checked_object_repr",
|
|
21
|
+
label=field_name,
|
|
22
|
+
width=Unit.PIXEL(250),
|
|
23
|
+
formatting_rules=[dp.FormattingRule(style={"fontWeight": "bold"})],
|
|
24
|
+
)
|
|
25
|
+
]
|
|
26
|
+
for key, label in self.view.get_rule_map:
|
|
27
|
+
fields.append(
|
|
28
|
+
dp.Field(
|
|
29
|
+
key=key,
|
|
30
|
+
label=label,
|
|
31
|
+
width=Unit.PIXEL(200),
|
|
32
|
+
formatting_rules=[
|
|
33
|
+
dp.FormattingRule(
|
|
34
|
+
condition=("==", -1),
|
|
35
|
+
style={"backgroundColor": WBColor.GREEN_LIGHT.value, "color": WBColor.GREEN_LIGHT.value},
|
|
36
|
+
),
|
|
37
|
+
*get_formatting(id_field="severity_order", color=True).formatting_rules,
|
|
38
|
+
],
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
return dp.ListDisplay(
|
|
42
|
+
fields=fields,
|
|
43
|
+
legends=[
|
|
44
|
+
dp.Legend(
|
|
45
|
+
items=[
|
|
46
|
+
dp.LegendItem(icon=WBColor.GREEN_LIGHT.value, label=_("No Incident")),
|
|
47
|
+
*get_legends().items,
|
|
48
|
+
]
|
|
49
|
+
)
|
|
50
|
+
],
|
|
51
|
+
)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from .compliance_form import (
|
|
2
|
+
CFComplianceFormSectionEndpointConfig,
|
|
3
|
+
CFComplianceFormSignatureEndpointConfig,
|
|
4
|
+
ComplianceFormEndpointConfig,
|
|
5
|
+
ComplianceFormRuleEndpointConfig,
|
|
6
|
+
ComplianceFormSectionRuleEndpointConfig,
|
|
7
|
+
ComplianceFormSignatureEndpointConfig,
|
|
8
|
+
ComplianceFormSignatureSectionRuleEndpointConfig,
|
|
9
|
+
ComplianceFormTypeEndpointConfig,
|
|
10
|
+
)
|
|
11
|
+
from .compliance_task import (
|
|
12
|
+
ComplianceActionEndpointConfig,
|
|
13
|
+
ComplianceEventEndpointConfig,
|
|
14
|
+
ComplianceTaskComplianceTaskGroupEndpointConfig,
|
|
15
|
+
ComplianceTaskEndpointConfig,
|
|
16
|
+
ComplianceTaskGroupEndpointConfig,
|
|
17
|
+
ComplianceTaskInstanceComplianceTaskEndpointConfig,
|
|
18
|
+
ComplianceTaskInstanceEndpointConfig,
|
|
19
|
+
ComplianceTaskInstanceReviewGroupEndpointConfig,
|
|
20
|
+
ComplianceTaskInstanceReviewNoGroupEndpointConfig,
|
|
21
|
+
ComplianceTaskMatrixEndpointConfig,
|
|
22
|
+
ComplianceTaskReviewGroupEndpointConfig,
|
|
23
|
+
ComplianceTaskReviewNoGroupEndpointConfig,
|
|
24
|
+
ReviewComplianceTaskEndpointConfig,
|
|
25
|
+
)
|
|
26
|
+
from .compliance_type import ComplianceTypeEndpointConfig
|
|
27
|
+
from .risk_managment import *
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
from rest_framework.reverse import reverse
|
|
2
|
+
from wbcompliance.models import ComplianceForm, ComplianceFormSection, ComplianceType
|
|
3
|
+
from wbcore.metadata.configs.endpoints import EndpointViewConfig
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
# Compliance Form
|
|
7
|
+
class ComplianceFormEndpointConfig(EndpointViewConfig):
|
|
8
|
+
def get_instance_endpoint(self, **kwargs):
|
|
9
|
+
if self.instance:
|
|
10
|
+
obj = self.view.get_object()
|
|
11
|
+
if (
|
|
12
|
+
not ComplianceType.is_administrator(self.request.user)
|
|
13
|
+
or obj.status == ComplianceForm.Status.ACTIVATION_REQUESTED
|
|
14
|
+
):
|
|
15
|
+
return None
|
|
16
|
+
return super().get_instance_endpoint()
|
|
17
|
+
|
|
18
|
+
def get_create_endpoint(self, **kwargs):
|
|
19
|
+
if ComplianceType.is_administrator(self.request.user):
|
|
20
|
+
return super().get_create_endpoint()
|
|
21
|
+
return None
|
|
22
|
+
|
|
23
|
+
def get_delete_endpoint(self, **kwargs):
|
|
24
|
+
if self.instance:
|
|
25
|
+
obj = self.view.get_object()
|
|
26
|
+
if (
|
|
27
|
+
not ComplianceType.is_administrator(self.request.user)
|
|
28
|
+
or obj.status == ComplianceForm.Status.ACTIVATION_REQUESTED
|
|
29
|
+
):
|
|
30
|
+
return None
|
|
31
|
+
return super().get_delete_endpoint()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ComplianceFormSignatureEndpointConfig(EndpointViewConfig):
|
|
35
|
+
def get_endpoint(self, **kwargs):
|
|
36
|
+
return reverse(f"{self.view.get_model().get_endpoint_basename()}-list", request=self.request)
|
|
37
|
+
|
|
38
|
+
def get_instance_endpoint(self, **kwargs):
|
|
39
|
+
if self.instance:
|
|
40
|
+
obj = self.view.get_object()
|
|
41
|
+
if obj.person != self.request.user.profile or obj.signed:
|
|
42
|
+
return None
|
|
43
|
+
return super().get_instance_endpoint()
|
|
44
|
+
|
|
45
|
+
def get_create_endpoint(self, **kwargs):
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
def get_delete_endpoint(self, **kwargs):
|
|
49
|
+
return None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class CFComplianceFormSignatureEndpointConfig(ComplianceFormSignatureEndpointConfig):
|
|
53
|
+
def get_endpoint(self, **kwargs):
|
|
54
|
+
return reverse(
|
|
55
|
+
"wbcompliance:complianceform-signatures-list",
|
|
56
|
+
args=[self.view.kwargs["compliance_form_id"]],
|
|
57
|
+
request=self.request,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
# SECTION OF THE COMPLIANCE FORM
|
|
62
|
+
class CFComplianceFormSectionEndpointConfig(EndpointViewConfig):
|
|
63
|
+
def get_endpoint(self, **kwargs):
|
|
64
|
+
return reverse(
|
|
65
|
+
"wbcompliance:complianceform-sections-list",
|
|
66
|
+
args=[self.view.kwargs["compliance_form_id"]],
|
|
67
|
+
request=self.request,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
def get_instance_endpoint(self, **kwargs):
|
|
71
|
+
if self.instance and not ComplianceType.is_administrator(self.request.user):
|
|
72
|
+
return None
|
|
73
|
+
if self.instance and "compliance_form_id" in self.view.kwargs:
|
|
74
|
+
obj = ComplianceForm.objects.get(id=self.view.kwargs.get("compliance_form_id"))
|
|
75
|
+
if obj.status == ComplianceForm.Status.ACTIVATION_REQUESTED:
|
|
76
|
+
return None
|
|
77
|
+
return super().get_instance_endpoint()
|
|
78
|
+
|
|
79
|
+
def get_create_endpoint(self, **kwargs):
|
|
80
|
+
if not ComplianceType.is_administrator(self.request.user):
|
|
81
|
+
return None
|
|
82
|
+
if "compliance_form_id" in self.view.kwargs:
|
|
83
|
+
obj = ComplianceForm.objects.get(id=self.view.kwargs.get("compliance_form_id"))
|
|
84
|
+
if obj.status == ComplianceForm.Status.ACTIVATION_REQUESTED:
|
|
85
|
+
return None
|
|
86
|
+
return super().get_create_endpoint()
|
|
87
|
+
|
|
88
|
+
def get_delete_endpoint(self, **kwargs):
|
|
89
|
+
if not ComplianceType.is_administrator(self.request.user):
|
|
90
|
+
return None
|
|
91
|
+
if "compliance_form_id" in self.view.kwargs:
|
|
92
|
+
obj = ComplianceForm.objects.get(id=self.view.kwargs.get("compliance_form_id"))
|
|
93
|
+
if obj.status == ComplianceForm.Status.ACTIVATION_REQUESTED:
|
|
94
|
+
return None
|
|
95
|
+
if "pk" in self.view.kwargs:
|
|
96
|
+
return f'{self.get_endpoint()}{self.view.kwargs["pk"]}/'
|
|
97
|
+
return super().get_delete_endpoint()
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# RULES OF THE SECTION
|
|
101
|
+
class ComplianceFormRuleEndpointConfig(EndpointViewConfig):
|
|
102
|
+
def get_list_endpoint(self, **kwargs):
|
|
103
|
+
return reverse(f"{self.view.get_model().get_endpoint_basename()}-list", request=self.request)
|
|
104
|
+
|
|
105
|
+
def get_instance_endpoint(self, **kwargs):
|
|
106
|
+
if self.instance and not ComplianceType.is_administrator(self.request.user):
|
|
107
|
+
return None
|
|
108
|
+
return super().get_instance_endpoint()
|
|
109
|
+
|
|
110
|
+
def get_create_endpoint(self, **kwargs):
|
|
111
|
+
if ComplianceType.is_administrator(self.request.user):
|
|
112
|
+
return super().get_create_endpoint()
|
|
113
|
+
return None
|
|
114
|
+
|
|
115
|
+
def get_delete_endpoint(self, **kwargs):
|
|
116
|
+
if ComplianceType.is_administrator(self.request.user):
|
|
117
|
+
return super().get_delete_endpoint()
|
|
118
|
+
return None
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class ComplianceFormSectionRuleEndpointConfig(EndpointViewConfig):
|
|
122
|
+
def get_endpoint(self, **kwargs):
|
|
123
|
+
return reverse(
|
|
124
|
+
"wbcompliance:complianceformsection-rules-list",
|
|
125
|
+
args=[self.view.kwargs["section_id"]],
|
|
126
|
+
request=self.request,
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
def get_list_endpoint(self, **kwargs):
|
|
130
|
+
return super().get_list_endpoint()
|
|
131
|
+
|
|
132
|
+
def get_instance_endpoint(self, **kwargs):
|
|
133
|
+
if self.instance and not ComplianceType.is_administrator(self.request.user):
|
|
134
|
+
return None
|
|
135
|
+
if self.instance and "section_id" in self.view.kwargs:
|
|
136
|
+
obj = ComplianceFormSection.objects.get(id=self.view.kwargs.get("section_id"))
|
|
137
|
+
if obj.compliance_form.status == ComplianceForm.Status.ACTIVATION_REQUESTED:
|
|
138
|
+
return None
|
|
139
|
+
return super().get_instance_endpoint()
|
|
140
|
+
|
|
141
|
+
def get_create_endpoint(self, **kwargs):
|
|
142
|
+
if not ComplianceType.is_administrator(self.request.user):
|
|
143
|
+
return None
|
|
144
|
+
if "section_id" in self.view.kwargs:
|
|
145
|
+
obj = ComplianceFormSection.objects.get(id=self.view.kwargs.get("section_id"))
|
|
146
|
+
if obj.compliance_form.status == ComplianceForm.Status.ACTIVATION_REQUESTED:
|
|
147
|
+
return None
|
|
148
|
+
return super().get_create_endpoint()
|
|
149
|
+
|
|
150
|
+
def get_delete_endpoint(self, **kwargs):
|
|
151
|
+
if not ComplianceType.is_administrator(self.request.user):
|
|
152
|
+
return None
|
|
153
|
+
if "section_id" in self.view.kwargs:
|
|
154
|
+
obj = ComplianceFormSection.objects.get(id=self.view.kwargs.get("section_id"))
|
|
155
|
+
if obj.compliance_form.status == ComplianceForm.Status.ACTIVATION_REQUESTED:
|
|
156
|
+
return None
|
|
157
|
+
if "pk" in self.view.kwargs:
|
|
158
|
+
return f'{self.get_endpoint()}{self.view.kwargs["pk"]}/'
|
|
159
|
+
return super().get_delete_endpoint()
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class ComplianceFormSignatureSectionRuleEndpointConfig(EndpointViewConfig):
|
|
163
|
+
def get_endpoint(self, **kwargs):
|
|
164
|
+
return reverse(
|
|
165
|
+
"wbcompliance:complianceformsignaturesection-rules-list",
|
|
166
|
+
args=[self.view.kwargs["section_id"]],
|
|
167
|
+
request=self.request,
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
def get_list_endpoint(self, **kwargs):
|
|
171
|
+
return super().get_list_endpoint()
|
|
172
|
+
|
|
173
|
+
def get_instance_endpoint(self, **kwargs):
|
|
174
|
+
if self.instance:
|
|
175
|
+
obj = self.view.get_object()
|
|
176
|
+
if (
|
|
177
|
+
obj.section.compliance_form_signature.person != self.request.user.profile
|
|
178
|
+
or obj.section.compliance_form_signature.signed
|
|
179
|
+
):
|
|
180
|
+
return None
|
|
181
|
+
return super().get_instance_endpoint()
|
|
182
|
+
|
|
183
|
+
def get_create_endpoint(self, **kwargs):
|
|
184
|
+
return None
|
|
185
|
+
|
|
186
|
+
def get_delete_endpoint(self, **kwargs):
|
|
187
|
+
return None
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
class ComplianceFormTypeEndpointConfig(EndpointViewConfig):
|
|
191
|
+
def get_list_endpoint(self, **kwargs):
|
|
192
|
+
return reverse(f"{self.view.get_model().get_endpoint_basename()}-list", request=self.request)
|
|
193
|
+
|
|
194
|
+
def get_instance_endpoint(self, **kwargs):
|
|
195
|
+
if self.instance and not ComplianceType.is_administrator(self.request.user):
|
|
196
|
+
return None
|
|
197
|
+
return super().get_instance_endpoint()
|
|
198
|
+
|
|
199
|
+
def get_create_endpoint(self, **kwargs):
|
|
200
|
+
if ComplianceType.is_administrator(self.request.user):
|
|
201
|
+
return super().get_create_endpoint()
|
|
202
|
+
return None
|
|
203
|
+
|
|
204
|
+
def get_delete_endpoint(self, **kwargs):
|
|
205
|
+
if ComplianceType.is_administrator(self.request.user):
|
|
206
|
+
return super().get_delete_endpoint()
|
|
207
|
+
return None
|