Skip to content

Commit b90632c

Browse files
authored
Add diff_version field (#3126)
1 parent f9146df commit b90632c

11 files changed

Lines changed: 124 additions & 3 deletions

File tree

data/example-data.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,7 @@
12931293
"number": "1 - 1",
12941294
"number_value": 1,
12951295
"title": "\u00c4nderungsantrag zu 1",
1296+
"diff_version": "0.1.2",
12961297
"text": "<p>l&ouml;mk</p>",
12971298
"text_hash": "0339e76557663e3a6f03b9e347409f97",
12981299
"category_weight": 10000,
@@ -1323,6 +1324,7 @@
13231324
"number": "2",
13241325
"number_value": 2,
13251326
"title": "ohne",
1327+
"diff_version": "0.1.2",
13261328
"text": "<p>sf</p>",
13271329
"text_hash": "60d31eb37595dd44584be5ef363283e3",
13281330
"category_weight": 100,

meta

openslides_backend/action/actions/motion/base_create_forwarded.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def prefetch(self, action_data: ActionData) -> None:
7878
"all_derived_motion_ids",
7979
"amendment_ids",
8080
"attachment_meeting_mediafile_ids",
81+
"diff_version",
8182
],
8283
),
8384
],
@@ -229,6 +230,7 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
229230

230231
self.handle_number(instance)
231232
self.set_origin_ids(instance)
233+
self.set_diff_version(instance)
232234
self.set_text_hash(instance)
233235
instance["forwarded"] = datetime.now(ZoneInfo("UTC"))
234236
with_change_recommendations = instance.pop("with_change_recommendations", False)
@@ -441,6 +443,14 @@ def set_origin_ids(self, instance: dict[str, Any]) -> None:
441443
instance["all_origin_ids"] = origin.get("all_origin_ids", [])
442444
instance["all_origin_ids"].append(instance["origin_id"])
443445

446+
def set_diff_version(self, instance: dict[str, Any]) -> None:
447+
if diff_version := self.datastore.get(
448+
fqid_from_collection_and_id("motion", instance["origin_id"]),
449+
["diff_version"],
450+
lock_result=False,
451+
).get("diff_version"):
452+
instance["diff_version"] = diff_version
453+
444454
def duplicate_mediafiles(
445455
self,
446456
action_data: ActionData,

openslides_backend/action/actions/motion/create.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class MotionCreate(
4242
schema = DefaultSchema(Motion()).get_create_schema(
4343
optional_properties=[
4444
"number",
45+
"diff_version",
4546
"additional_submitter",
4647
"sort_parent_id",
4748
"category_id",

openslides_backend/action/actions/motion/payload_validation_mixin.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class MotionErrorType(StrEnum):
2121
REASON = "reason"
2222
WORKFLOW = "workflow"
2323
TITLE = "title"
24+
DIFF_VERSION = "diff_version"
2425

2526

2627
class MotionActionErrorData(TypedDict):
@@ -86,6 +87,18 @@ def _check_recommendation_and_state(
8687
)
8788
return errors
8889

90+
def _check_diff_version(
91+
self, instance: dict[str, Any], datastore_instance: dict[str, Any] = {}
92+
) -> list[MotionActionErrorData]:
93+
if instance.get("lead_motion_id") or datastore_instance.get("lead_motion_id"):
94+
return [
95+
{
96+
"type": (MotionErrorType.DIFF_VERSION),
97+
"message": "You can define a diff_version only for the lead motion",
98+
}
99+
]
100+
return []
101+
89102

90103
class MotionCreatePayloadValidationMixin(MotionBasePayloadValidationMixin):
91104
"""
@@ -137,6 +150,8 @@ def _create_conduct_before_checks(
137150
"message": "You can't give amendment_paragraphs in this context",
138151
}
139152
)
153+
if instance.get("diff_version"):
154+
errors += self._check_diff_version(instance)
140155
if (not instance.get("reason")) and self.check_reason_required(meeting_id):
141156
errors.append(
142157
{"type": MotionErrorType.REASON, "message": "Reason is required"}
@@ -196,10 +211,14 @@ def _update_conduct_before_checks(
196211
self, instance: dict[str, Any], meeting_id: int
197212
) -> list[MotionActionErrorData]:
198213
errors: list[MotionActionErrorData] = []
199-
if instance.get("text") or instance.get("amendment_paragraphs"):
214+
if (
215+
instance.get("text")
216+
or instance.get("amendment_paragraphs")
217+
or instance.get("diff_version")
218+
):
200219
motion = self.datastore.get(
201220
fqid_from_collection_and_id("motion", instance["id"]),
202-
["text", "amendment_paragraphs"],
221+
["text", "amendment_paragraphs", "lead_motion_id"],
203222
)
204223
if instance.get("text"):
205224
if not motion.get("text"):
@@ -224,4 +243,6 @@ def _update_conduct_before_checks(
224243
"message": "Reason is required to update.",
225244
}
226245
)
246+
if instance.get("diff_version"):
247+
errors += self._check_diff_version(instance, motion)
227248
return errors

openslides_backend/action/actions/motion/update.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class MotionUpdate(
5555
optional_properties=[
5656
"title",
5757
"number",
58+
"diff_version",
5859
"additional_submitter",
5960
"text",
6061
"reason",

openslides_backend/models/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,7 @@ class Motion(Model):
16421642
},
16431643
)
16441644
title = fields.CharField(required=True)
1645+
diff_version = fields.CharField()
16451646
text = fields.HTMLStrictField()
16461647
text_hash = fields.CharField()
16471648
amendment_paragraphs = fields.JSONField()

tests/system/action/motion/test_create.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,3 +1038,26 @@ def test_create_with_irrelevant_delegator_setting(self) -> None:
10381038
"submitter_ids": None,
10391039
},
10401040
)
1041+
1042+
def test_create_motion_with_diff_version(self) -> None:
1043+
response = self.request(
1044+
"motion.create",
1045+
{
1046+
"title": "test_Xcdfgee",
1047+
"meeting_id": 1,
1048+
"workflow_id": 1,
1049+
"text": "test",
1050+
"diff_version": "0.1.2",
1051+
},
1052+
)
1053+
self.assert_status_code(response, 200)
1054+
self.assert_model_exists(
1055+
"motion/1",
1056+
{
1057+
"title": "test_Xcdfgee",
1058+
"meeting_id": 1,
1059+
"text": "test",
1060+
"submitter_ids": None,
1061+
"diff_version": "0.1.2",
1062+
},
1063+
)

tests/system/action/motion/test_create_amendment.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,17 @@ def test_create_amendment_no_permissions_extra_fields(self) -> None:
316316
f"You are not allowed to perform action motion.create. Forbidden fields: {field} with possibly needed permission(s): motion.can_manage",
317317
response.json["message"],
318318
)
319+
320+
def test_create_amendment_with_diff_version_not_allowed(self) -> None:
321+
response = self.request(
322+
"motion.create",
323+
{
324+
**self.default_action_data,
325+
"diff_version": "0.1.2",
326+
},
327+
)
328+
self.assert_status_code(response, 400)
329+
self.assertEqual(
330+
"You can define a diff_version only for the lead motion",
331+
response.json["message"],
332+
)

tests/system/action/motion/test_create_forwarded.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,6 +2538,28 @@ def test_forward_multiple_motions_with_mediafiles_and_amendments_in_1_transactio
25382538
},
25392539
)
25402540

2541+
def test_forward_with_diff_version(self) -> None:
2542+
self.create_meeting()
2543+
self.create_meeting(4)
2544+
self.create_motion(1, 1, motion_data={"diff_version": "0.1.2"})
2545+
self.set_models(
2546+
{
2547+
"motion_state/1": {"allow_motion_forwarding": True},
2548+
"committee/60": {"forward_to_committee_ids": [63]},
2549+
}
2550+
)
2551+
response = self.request(
2552+
"motion.create_forwarded",
2553+
{
2554+
"title": "Motion 2",
2555+
"text": "text",
2556+
"meeting_id": 4,
2557+
"origin_id": 1,
2558+
},
2559+
)
2560+
self.assert_status_code(response, 200)
2561+
self.assert_model_exists("motion/2", {"diff_version": "0.1.2"})
2562+
25412563
def test_forward_with_deleted_submitters(self) -> None:
25422564
self.create_meeting(1)
25432565
self.create_meeting(4)

0 commit comments

Comments
 (0)