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,463 @@
|
|
|
1
|
+
from django.shortcuts import get_object_or_404
|
|
2
|
+
from django.utils import timezone
|
|
3
|
+
from django.utils.functional import cached_property
|
|
4
|
+
from django.utils.translation import gettext_lazy as _
|
|
5
|
+
from rest_framework.reverse import reverse
|
|
6
|
+
from wbcompliance.models import (
|
|
7
|
+
ComplianceAction,
|
|
8
|
+
ComplianceEvent,
|
|
9
|
+
ComplianceTask,
|
|
10
|
+
ComplianceTaskGroup,
|
|
11
|
+
ComplianceTaskInstance,
|
|
12
|
+
ComplianceType,
|
|
13
|
+
ReviewComplianceTask,
|
|
14
|
+
)
|
|
15
|
+
from wbcore import serializers as wb_serializers
|
|
16
|
+
from wbcore.contrib.directory.models import Person
|
|
17
|
+
from wbcore.contrib.directory.serializers import PersonRepresentationSerializer
|
|
18
|
+
|
|
19
|
+
from .compliance_type import ComplianceTypeRepresentationSerializer
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ComplianceTaskGroupRepresentationSerializer(wb_serializers.RepresentationSerializer):
|
|
23
|
+
_detail = wb_serializers.HyperlinkField(reverse_name="wbcompliance:compliancetaskgroup-detail")
|
|
24
|
+
|
|
25
|
+
class Meta:
|
|
26
|
+
model = ComplianceTaskGroup
|
|
27
|
+
fields = ("id", "name", "_detail")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ComplianceTaskRepresentationSerializer(wb_serializers.RepresentationSerializer):
|
|
31
|
+
_detail = wb_serializers.HyperlinkField(reverse_name="wbcompliance:compliancetask-detail")
|
|
32
|
+
|
|
33
|
+
class Meta:
|
|
34
|
+
model = ComplianceTask
|
|
35
|
+
fields = ("id", "title", "occurrence", "active", "type", "_detail")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class ReviewComplianceTaskRepresentationSerializer(wb_serializers.RepresentationSerializer):
|
|
39
|
+
_detail = wb_serializers.HyperlinkField(reverse_name="wbcompliance:reviewcompliancetask-detail")
|
|
40
|
+
|
|
41
|
+
class Meta:
|
|
42
|
+
model = ReviewComplianceTask
|
|
43
|
+
fields = ("id", "title", "computed_str", "occurrence", "year", "occured", "_detail")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class NoInstanceReviewComplianceTaskRepresentationSerializer(ReviewComplianceTaskRepresentationSerializer):
|
|
47
|
+
def get_filter_params(self, request):
|
|
48
|
+
if task_id := request.parser_context["view"].kwargs.get("pk"):
|
|
49
|
+
task = get_object_or_404(ComplianceTask, pk=task_id)
|
|
50
|
+
return {"is_instance": False, "type": task.type.id}
|
|
51
|
+
return {"is_instance": False}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class InstanceReviewComplianceTaskRepresentationSerializer(ReviewComplianceTaskRepresentationSerializer):
|
|
55
|
+
def get_filter_params(self, request):
|
|
56
|
+
if task_id := request.parser_context["view"].kwargs.get("task_id"):
|
|
57
|
+
task = get_object_or_404(ComplianceTask, pk=task_id)
|
|
58
|
+
return {"is_instance": True, "type": task.type.id}
|
|
59
|
+
return {"is_instance": True}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class ComplianceTaskGroupModelSerializer(wb_serializers.ModelSerializer):
|
|
63
|
+
@wb_serializers.register_resource()
|
|
64
|
+
def register_history_resource(self, instance, request, user):
|
|
65
|
+
resources = {
|
|
66
|
+
"compliancetask": reverse(
|
|
67
|
+
"wbcompliance:compliancetaskgroup-compliancetask-list", args=[instance.id], request=request
|
|
68
|
+
),
|
|
69
|
+
}
|
|
70
|
+
return resources
|
|
71
|
+
|
|
72
|
+
class Meta:
|
|
73
|
+
model = ComplianceTaskGroup
|
|
74
|
+
fields = ("id", "name", "order", "_additional_resources")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class ComplianceTaskModelSerializer(wb_serializers.ModelSerializer):
|
|
78
|
+
@wb_serializers.register_resource()
|
|
79
|
+
def register_history_resource(self, instance, request, user):
|
|
80
|
+
resources = {
|
|
81
|
+
"compliancetaskinstance": reverse(
|
|
82
|
+
"wbcompliance:compliancetask-compliancetaskinstance-list", args=[instance.id], request=request
|
|
83
|
+
),
|
|
84
|
+
}
|
|
85
|
+
if user.is_superuser:
|
|
86
|
+
resources["generateinstance"] = reverse(
|
|
87
|
+
"wbcompliance:compliancetask-generate-instance", args=[instance.id], request=request
|
|
88
|
+
)
|
|
89
|
+
return resources
|
|
90
|
+
|
|
91
|
+
_group = ComplianceTaskGroupRepresentationSerializer(source="group")
|
|
92
|
+
review = wb_serializers.PrimaryKeyRelatedField(
|
|
93
|
+
queryset=ReviewComplianceTask.objects.all(),
|
|
94
|
+
label=_("Indicator Reports"),
|
|
95
|
+
many=True,
|
|
96
|
+
help_text=_("list of reports that contain this task"),
|
|
97
|
+
)
|
|
98
|
+
_review = NoInstanceReviewComplianceTaskRepresentationSerializer(
|
|
99
|
+
source="review",
|
|
100
|
+
many=True,
|
|
101
|
+
optional_get_parameters={"type": "type"},
|
|
102
|
+
depends_on=[{"field": "type", "options": {}}],
|
|
103
|
+
)
|
|
104
|
+
_type = ComplianceTypeRepresentationSerializer(source="type")
|
|
105
|
+
type = wb_serializers.PrimaryKeyRelatedField(
|
|
106
|
+
queryset=ComplianceType.objects.all(),
|
|
107
|
+
label=_("Administrator"),
|
|
108
|
+
)
|
|
109
|
+
occurrence = wb_serializers.ChoiceField(
|
|
110
|
+
default=wb_serializers.DefaultAttributeFromRemoteField("review_id", ReviewComplianceTask, "occurrence"),
|
|
111
|
+
choices=ReviewComplianceTask.Occurrence.choices,
|
|
112
|
+
)
|
|
113
|
+
type = wb_serializers.PrimaryKeyRelatedField(
|
|
114
|
+
queryset=ComplianceType.objects.all(),
|
|
115
|
+
label=_("Administrator"),
|
|
116
|
+
default=wb_serializers.DefaultAttributeFromRemoteField("review_id", ReviewComplianceTask, "type.id"),
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
class Meta:
|
|
120
|
+
model = ComplianceTask
|
|
121
|
+
# dependency_map = {
|
|
122
|
+
# "review": ["type"],
|
|
123
|
+
# }
|
|
124
|
+
fields = (
|
|
125
|
+
"id",
|
|
126
|
+
"title",
|
|
127
|
+
"description",
|
|
128
|
+
"occurrence",
|
|
129
|
+
"active",
|
|
130
|
+
"type",
|
|
131
|
+
"_type",
|
|
132
|
+
"group",
|
|
133
|
+
"_group",
|
|
134
|
+
"_additional_resources",
|
|
135
|
+
"risk_level",
|
|
136
|
+
"remarks",
|
|
137
|
+
"review",
|
|
138
|
+
"_review",
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class ComplianceTaskReviewModelSerializer(ComplianceTaskModelSerializer):
|
|
143
|
+
def create(self, validated_data):
|
|
144
|
+
if (view := self.context.get("view", None)) and (review_id := view.kwargs.get("review_id", None)):
|
|
145
|
+
validated_data["review"] = ReviewComplianceTask.objects.filter(id=review_id)
|
|
146
|
+
|
|
147
|
+
return super().create(validated_data)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class ComplianceTaskInstanceModelSerializer(wb_serializers.ModelSerializer):
|
|
151
|
+
task = wb_serializers.PrimaryKeyRelatedField(
|
|
152
|
+
queryset=ComplianceTask.objects.all(),
|
|
153
|
+
label=_("Indicator"),
|
|
154
|
+
)
|
|
155
|
+
_task = ComplianceTaskRepresentationSerializer(source="task")
|
|
156
|
+
type_name = wb_serializers.CharField(required=False, read_only=True, label=_("Administrator"))
|
|
157
|
+
group_name = wb_serializers.CharField(required=False, read_only=True, label=_("Group"))
|
|
158
|
+
task_title = wb_serializers.CharField(required=False, read_only=True, label=_("Indicators"))
|
|
159
|
+
review = wb_serializers.PrimaryKeyRelatedField(
|
|
160
|
+
queryset=ReviewComplianceTask.objects.all(),
|
|
161
|
+
label=_("Indicator Instance Reports"),
|
|
162
|
+
many=True,
|
|
163
|
+
help_text=_("list of reports that contain this task"),
|
|
164
|
+
)
|
|
165
|
+
_review = InstanceReviewComplianceTaskRepresentationSerializer(source="review", many=True)
|
|
166
|
+
|
|
167
|
+
text = wb_serializers.TextAreaField(
|
|
168
|
+
required=False, label=_("Text"), allow_blank=True, allow_null=True, help_text=_("Information for Management")
|
|
169
|
+
)
|
|
170
|
+
summary_text = wb_serializers.TextAreaField(
|
|
171
|
+
required=False,
|
|
172
|
+
label=_("Summary Text"),
|
|
173
|
+
allow_blank=True,
|
|
174
|
+
allow_null=True,
|
|
175
|
+
help_text=_("Information for the Board of Directors"),
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
class Meta:
|
|
179
|
+
model = ComplianceTaskInstance
|
|
180
|
+
fields = (
|
|
181
|
+
"id",
|
|
182
|
+
"occured",
|
|
183
|
+
"status",
|
|
184
|
+
"type_name",
|
|
185
|
+
"group_name",
|
|
186
|
+
"text",
|
|
187
|
+
"summary_text",
|
|
188
|
+
"_task",
|
|
189
|
+
"task",
|
|
190
|
+
"review",
|
|
191
|
+
"_review",
|
|
192
|
+
"_additional_resources",
|
|
193
|
+
"task_title",
|
|
194
|
+
)
|
|
195
|
+
read_only_fields = ("review", "_review", "task", "_task")
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
class ComplianceTaskInstanceListModelSerializer(ComplianceTaskInstanceModelSerializer):
|
|
199
|
+
class Meta:
|
|
200
|
+
model = ComplianceTaskInstance
|
|
201
|
+
fields = (
|
|
202
|
+
"id",
|
|
203
|
+
"occured",
|
|
204
|
+
"status",
|
|
205
|
+
"type_name",
|
|
206
|
+
"group_name",
|
|
207
|
+
"_task",
|
|
208
|
+
"task",
|
|
209
|
+
"task_title",
|
|
210
|
+
"review",
|
|
211
|
+
"_review",
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
class ComplianceActionModelSerializer(wb_serializers.ModelSerializer):
|
|
216
|
+
type = wb_serializers.PrimaryKeyRelatedField(
|
|
217
|
+
queryset=ComplianceType.objects.all(),
|
|
218
|
+
label=_("Administrator"),
|
|
219
|
+
)
|
|
220
|
+
_type = ComplianceTypeRepresentationSerializer(source="type")
|
|
221
|
+
_creator = PersonRepresentationSerializer(source="creator")
|
|
222
|
+
_changer = PersonRepresentationSerializer(source="changer")
|
|
223
|
+
description = wb_serializers.TextField(
|
|
224
|
+
default="", label=_("Description"), help_text=_("Explanation for Management")
|
|
225
|
+
)
|
|
226
|
+
summary_description = wb_serializers.TextField(
|
|
227
|
+
default="", label=_("Summary Description"), help_text=_("Explanation for the Board of Directors")
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
class Meta:
|
|
231
|
+
percent_fields = ["progress"]
|
|
232
|
+
|
|
233
|
+
model = ComplianceAction
|
|
234
|
+
fields = (
|
|
235
|
+
"id",
|
|
236
|
+
"title",
|
|
237
|
+
"description",
|
|
238
|
+
"summary_description",
|
|
239
|
+
"deadline",
|
|
240
|
+
"progress",
|
|
241
|
+
"status",
|
|
242
|
+
"type",
|
|
243
|
+
"_type",
|
|
244
|
+
"active",
|
|
245
|
+
"creator",
|
|
246
|
+
"_creator",
|
|
247
|
+
"created",
|
|
248
|
+
"changer",
|
|
249
|
+
"_changer",
|
|
250
|
+
"last_modified",
|
|
251
|
+
)
|
|
252
|
+
read_only_fields = ("creator", "created", "changer", "last_modified")
|
|
253
|
+
|
|
254
|
+
@cached_property
|
|
255
|
+
def user_profile(self) -> Person | None:
|
|
256
|
+
if request := self.context.get("request"):
|
|
257
|
+
return request.user.profile
|
|
258
|
+
return None
|
|
259
|
+
|
|
260
|
+
def create(self, validated_data):
|
|
261
|
+
validated_data["creator"] = self.user_profile
|
|
262
|
+
return super().create(validated_data)
|
|
263
|
+
|
|
264
|
+
def update(self, instance, validated_data):
|
|
265
|
+
profile = self.user_profile
|
|
266
|
+
validated_data["changer"] = profile
|
|
267
|
+
validated_data.pop("creator", None)
|
|
268
|
+
validated_data.pop("created", None)
|
|
269
|
+
return super().update(instance, validated_data)
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
class ComplianceEventModelSerializer(wb_serializers.ModelSerializer):
|
|
273
|
+
type = wb_serializers.PrimaryKeyRelatedField(
|
|
274
|
+
queryset=ComplianceType.objects.all(),
|
|
275
|
+
label=_("Administrator"),
|
|
276
|
+
)
|
|
277
|
+
_type = ComplianceTypeRepresentationSerializer(source="type")
|
|
278
|
+
_creator = PersonRepresentationSerializer(source="creator")
|
|
279
|
+
_changer = PersonRepresentationSerializer(source="changer")
|
|
280
|
+
title = wb_serializers.CharField(label=_("Title"), allow_null=False)
|
|
281
|
+
exec_summary = wb_serializers.TextField(
|
|
282
|
+
default="", label=_("Executive Summary for Management"), help_text=_("Executive Summary for Management")
|
|
283
|
+
)
|
|
284
|
+
exec_summary_board = wb_serializers.TextField(
|
|
285
|
+
default="",
|
|
286
|
+
label=_("Executive Summary for the Board of Directors"),
|
|
287
|
+
help_text=_("Executive Summary for the Board of Directors"),
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
class Meta:
|
|
291
|
+
model = ComplianceEvent
|
|
292
|
+
fields = (
|
|
293
|
+
"id",
|
|
294
|
+
"type_event",
|
|
295
|
+
"level",
|
|
296
|
+
"title",
|
|
297
|
+
"exec_summary",
|
|
298
|
+
"exec_summary_board",
|
|
299
|
+
"description",
|
|
300
|
+
"actions_taken",
|
|
301
|
+
"confidential",
|
|
302
|
+
"consequences",
|
|
303
|
+
"future_suggestions",
|
|
304
|
+
"type",
|
|
305
|
+
"_type",
|
|
306
|
+
"active",
|
|
307
|
+
"creator",
|
|
308
|
+
"_creator",
|
|
309
|
+
"created",
|
|
310
|
+
"changer",
|
|
311
|
+
"_changer",
|
|
312
|
+
"last_modified",
|
|
313
|
+
)
|
|
314
|
+
read_only_fields = ("creator", "created", "changer", "last_modified")
|
|
315
|
+
|
|
316
|
+
@cached_property
|
|
317
|
+
def user_profile(self) -> Person | None:
|
|
318
|
+
if request := self.context.get("request"):
|
|
319
|
+
return request.user.profile
|
|
320
|
+
return None
|
|
321
|
+
|
|
322
|
+
def create(self, validated_data):
|
|
323
|
+
validated_data["creator"] = self.user_profile
|
|
324
|
+
return super().create(validated_data)
|
|
325
|
+
|
|
326
|
+
def update(self, instance, validated_data):
|
|
327
|
+
profile = self.user_profile
|
|
328
|
+
validated_data["changer"] = profile
|
|
329
|
+
validated_data.pop("creator", None)
|
|
330
|
+
validated_data.pop("created", None)
|
|
331
|
+
return super().update(instance, validated_data)
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
class ReviewComplianceTaskModelSerializer(wb_serializers.ModelSerializer):
|
|
335
|
+
@wb_serializers.register_only_instance_resource()
|
|
336
|
+
def register_history_resource(self, instance, request, user, **kwargs):
|
|
337
|
+
if not instance.is_instance:
|
|
338
|
+
resources = {
|
|
339
|
+
"task_group": reverse("wbcompliance:compliancetaskgroup-list", args=[], request=request),
|
|
340
|
+
"task_no_group": reverse(
|
|
341
|
+
"wbcompliance:review-compliancetasknogroup-list", args=[instance.id], request=request
|
|
342
|
+
),
|
|
343
|
+
}
|
|
344
|
+
if instance.status == ReviewComplianceTask.Status.DRAFT and user.is_superuser:
|
|
345
|
+
resources["link_tasks"] = reverse(
|
|
346
|
+
"wbcompliance:reviewcompliancetask-link-tasks", args=[instance.id], request=request
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
if instance.status == ReviewComplianceTask.Status.VALIDATED and user.has_perm(
|
|
350
|
+
"wbcompliance.administrate_compliance"
|
|
351
|
+
):
|
|
352
|
+
resources["regenerate_document"] = reverse(
|
|
353
|
+
"wbcompliance:reviewcompliancetask-regenerate-document", args=[instance.id], request=request
|
|
354
|
+
)
|
|
355
|
+
|
|
356
|
+
from_date, to_date = instance.get_period_date()
|
|
357
|
+
if not ReviewComplianceTask.objects.filter(
|
|
358
|
+
review_task=instance, from_date=from_date, to_date=to_date
|
|
359
|
+
).exists():
|
|
360
|
+
resources["generate_instance"] = reverse(
|
|
361
|
+
"wbcompliance:reviewcompliancetask-generate-instance", args=[instance.id], request=request
|
|
362
|
+
)
|
|
363
|
+
group_ids = instance.get_task_group_ids_from_review()
|
|
364
|
+
for group_id in group_ids:
|
|
365
|
+
resources[f"taskgroup{group_id}"] = reverse(
|
|
366
|
+
"wbcompliance:review-compliancetaskgroup-list",
|
|
367
|
+
args=[instance.id, group_id],
|
|
368
|
+
request=request,
|
|
369
|
+
)
|
|
370
|
+
else:
|
|
371
|
+
resources = {
|
|
372
|
+
"actions": reverse(
|
|
373
|
+
"wbcompliance:type-complianceaction-list", args=[instance.type.id], request=request
|
|
374
|
+
),
|
|
375
|
+
"events": reverse("wbcompliance:type-complianceevent-list", args=[instance.type.id], request=request),
|
|
376
|
+
"taskinstance_no_group": reverse(
|
|
377
|
+
"wbcompliance:review-compliancetaskinstancenogroup-list", args=[instance.id], request=request
|
|
378
|
+
),
|
|
379
|
+
}
|
|
380
|
+
group_ids = instance.get_task_group_ids_from_review(through_task=False)
|
|
381
|
+
for group_id in group_ids:
|
|
382
|
+
resources[f"taskinstancegroup{group_id}"] = reverse(
|
|
383
|
+
"wbcompliance:review-compliancetaskinstancegroup-list",
|
|
384
|
+
args=[instance.id, group_id],
|
|
385
|
+
request=request,
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
return resources
|
|
389
|
+
|
|
390
|
+
year = wb_serializers.YearField(default=timezone.now().year)
|
|
391
|
+
creator = wb_serializers.PrimaryKeyRelatedField(
|
|
392
|
+
default=wb_serializers.CurrentUserDefault("profile"),
|
|
393
|
+
many=False,
|
|
394
|
+
read_only=True,
|
|
395
|
+
)
|
|
396
|
+
_creator = PersonRepresentationSerializer(source="creator")
|
|
397
|
+
_changer = PersonRepresentationSerializer(source="changer")
|
|
398
|
+
review_task = wb_serializers.PrimaryKeyRelatedField(read_only=True, label=_("Main Indicator Report"))
|
|
399
|
+
_review_task = ReviewComplianceTaskRepresentationSerializer(source="review_task")
|
|
400
|
+
type = wb_serializers.PrimaryKeyRelatedField(
|
|
401
|
+
queryset=ComplianceType.objects.all(),
|
|
402
|
+
label=_("Administrator"),
|
|
403
|
+
)
|
|
404
|
+
_type = ComplianceTypeRepresentationSerializer(source="type")
|
|
405
|
+
occured = wb_serializers.DateField(read_only=True, label=_("Occured Instance Report"))
|
|
406
|
+
occurrence = wb_serializers.ChoiceField(
|
|
407
|
+
choices=ReviewComplianceTask.Occurrence.choices,
|
|
408
|
+
read_only=lambda view: not getattr(view.get_object(), "is_instance", True)
|
|
409
|
+
if "pk" in view.kwargs
|
|
410
|
+
else not view.new_mode,
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
class Meta:
|
|
414
|
+
model = ReviewComplianceTask
|
|
415
|
+
fields = (
|
|
416
|
+
"id",
|
|
417
|
+
"title",
|
|
418
|
+
"from_date",
|
|
419
|
+
"to_date",
|
|
420
|
+
"description",
|
|
421
|
+
"year",
|
|
422
|
+
"creator",
|
|
423
|
+
"_creator",
|
|
424
|
+
"created",
|
|
425
|
+
"changer",
|
|
426
|
+
"_changer",
|
|
427
|
+
"changed",
|
|
428
|
+
"status",
|
|
429
|
+
"_additional_resources",
|
|
430
|
+
"occurrence",
|
|
431
|
+
"computed_str",
|
|
432
|
+
"is_instance",
|
|
433
|
+
"review_task",
|
|
434
|
+
"_review_task",
|
|
435
|
+
"occured",
|
|
436
|
+
"type",
|
|
437
|
+
"_type",
|
|
438
|
+
)
|
|
439
|
+
read_only_fields = (
|
|
440
|
+
"creator",
|
|
441
|
+
"created",
|
|
442
|
+
"changer",
|
|
443
|
+
"changed",
|
|
444
|
+
"occured",
|
|
445
|
+
"is_instance",
|
|
446
|
+
"review_task",
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
@cached_property
|
|
450
|
+
def user_profile(self) -> Person | None:
|
|
451
|
+
if request := self.context.get("request"):
|
|
452
|
+
return request.user.profile
|
|
453
|
+
return None
|
|
454
|
+
|
|
455
|
+
def create(self, validated_data):
|
|
456
|
+
validated_data["creator"] = self.user_profile
|
|
457
|
+
return super().create(validated_data)
|
|
458
|
+
|
|
459
|
+
def update(self, instance, validated_data):
|
|
460
|
+
validated_data["changer"] = self.user_profile
|
|
461
|
+
validated_data.pop("creator", None)
|
|
462
|
+
validated_data.pop("created", None)
|
|
463
|
+
return super().update(instance, validated_data)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from django.utils.translation import gettext_lazy
|
|
2
|
+
from wbcompliance.models import ComplianceType
|
|
3
|
+
from wbcore import serializers as wb_serializers
|
|
4
|
+
from wbcore.contrib.authentication.serializers import GroupRepresentationSerializer
|
|
5
|
+
from wbcore.contrib.directory.serializers import PersonRepresentationSerializer
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ComplianceTypeRepresentationSerializer(wb_serializers.RepresentationSerializer):
|
|
9
|
+
class Meta:
|
|
10
|
+
model = ComplianceType
|
|
11
|
+
fields = (
|
|
12
|
+
"id",
|
|
13
|
+
"name",
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ComplianceTypeModelSerializer(wb_serializers.ModelSerializer):
|
|
18
|
+
_in_charge = GroupRepresentationSerializer(source="in_charge", many=True)
|
|
19
|
+
administrators = wb_serializers.PrimaryKeyRelatedField(
|
|
20
|
+
label=gettext_lazy("Administrator"), many=True, read_only=True
|
|
21
|
+
)
|
|
22
|
+
_administrators = PersonRepresentationSerializer(many=True, source="administrators")
|
|
23
|
+
|
|
24
|
+
class Meta:
|
|
25
|
+
model = ComplianceType
|
|
26
|
+
fields = ("id", "name", "description", "in_charge", "_in_charge", "administrators", "_administrators")
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from .checks import RiskCheckModelSerializer, RiskCheckRepresentationSerializer
|
|
2
|
+
from .incidents import (
|
|
3
|
+
CheckedObjectIncidentRelationshipModelSerializer,
|
|
4
|
+
CheckedObjectIncidentRelationshipRepresentationSerializer,
|
|
5
|
+
RiskIncidentModelSerializer,
|
|
6
|
+
RiskIncidentRepresentationSerializer,
|
|
7
|
+
RiskIncidentTypeRepresentationSerializer,
|
|
8
|
+
RuleThresholdModelSerializer,
|
|
9
|
+
)
|
|
10
|
+
from .rules import (
|
|
11
|
+
RuleGroupRepresentationSerializer,
|
|
12
|
+
RiskRuleModelSerializer,
|
|
13
|
+
RiskRuleRepresentationSerializer,
|
|
14
|
+
RuleBackendModelSerializer,
|
|
15
|
+
RuleBackendRepresentationSerializer,
|
|
16
|
+
RuleCheckedObjectRelationshipModelSerializer,
|
|
17
|
+
RuleCheckedObjectRelationshipRepresentationSerializer,
|
|
18
|
+
RuleThresholdRepresentationSerializer,
|
|
19
|
+
)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from rest_framework.reverse import reverse
|
|
2
|
+
from wbcompliance.models.risk_management import RiskCheck
|
|
3
|
+
from wbcore import serializers as wb_serializers
|
|
4
|
+
from wbcore.content_type.serializers import ContentTypeRepresentationSerializer
|
|
5
|
+
from wbcore.contrib.icons.serializers import IconSelectField
|
|
6
|
+
|
|
7
|
+
from .rules import RuleCheckedObjectRelationshipRepresentationSerializer
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class RiskCheckRepresentationSerializer(wb_serializers.RepresentationSerializer):
|
|
11
|
+
class Meta:
|
|
12
|
+
model = RiskCheck
|
|
13
|
+
fields = ("id", "computed_str")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class RiskCheckModelSerializer(wb_serializers.ModelSerializer):
|
|
17
|
+
_rule_checked_object_relationship = RuleCheckedObjectRelationshipRepresentationSerializer(
|
|
18
|
+
source="rule_checked_object_relationship"
|
|
19
|
+
)
|
|
20
|
+
_trigger_content_type = ContentTypeRepresentationSerializer(source="trigger_content_type")
|
|
21
|
+
rule_repr = wb_serializers.CharField()
|
|
22
|
+
|
|
23
|
+
status_icon = IconSelectField(read_only=True)
|
|
24
|
+
|
|
25
|
+
@wb_serializers.register_resource()
|
|
26
|
+
def additional_resources(self, instance, request, user):
|
|
27
|
+
res = {}
|
|
28
|
+
if instance.incidents.exists():
|
|
29
|
+
res[
|
|
30
|
+
"incidents"
|
|
31
|
+
] = f'{reverse("wbcompliance:checkedobjectincidentrelationship-list", args=[], request=request)}?rule_check={instance.id}'
|
|
32
|
+
|
|
33
|
+
return res
|
|
34
|
+
|
|
35
|
+
class Meta:
|
|
36
|
+
model = RiskCheck
|
|
37
|
+
fields = (
|
|
38
|
+
"id",
|
|
39
|
+
"rule_repr",
|
|
40
|
+
"rule_checked_object_relationship",
|
|
41
|
+
"_rule_checked_object_relationship",
|
|
42
|
+
"creation_datetime",
|
|
43
|
+
"evaluation_date",
|
|
44
|
+
"computed_str",
|
|
45
|
+
"_trigger_content_type",
|
|
46
|
+
"trigger_content_type",
|
|
47
|
+
"trigger_id",
|
|
48
|
+
"status",
|
|
49
|
+
"rule_repr",
|
|
50
|
+
"status_icon",
|
|
51
|
+
"_additional_resources",
|
|
52
|
+
)
|
|
53
|
+
read_only_fields = fields
|