Skip to content

Commit

Permalink
Org: Fixes removing linked people from an unordered list
Browse files Browse the repository at this point in the history
TYPE: Bugfix
LINK: OGC-1883
  • Loading branch information
Daverball authored Oct 22, 2024
1 parent 54af2cd commit bdc57ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/onegov/org/models/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,16 +672,8 @@ def populate_obj(self, obj: object, name: str) -> None:
if (v := people_values.get(person.id.hex)) is not None
]
else:
# if the people are not ordered we keep the order of the
# existing list and add the new people at the end
existing = dict(previous_people)
new_people = previous_people.copy()

for person_id, values in people_values.items():
if person_id not in existing:
new_people.append((person_id, values))

obj.content['people'] = new_people
# otherwise we just use the given order
obj.content['people'] = list(people_values.items())

field_macro = request.template_loader.macros['field']
# FIXME: It is not ideal that we have to pass a dummy form along to
Expand Down
17 changes: 17 additions & 0 deletions tests/onegov/org/test_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ class TopicForm(Form):
('6d120102d90344868eb32614cf3acb1a', (None, False)), # Troy _B_arnes
]

# plug in the current order into the field, since move_person
# does not update the field
field[0].form.person.data = 'f0281b558a5f43f6ac81589d79538a87'
field[1].form.person.data = 'aa37e9cc40ab402ea70b0d2b4d672de3'
field[2].form.person.data = '6d120102d90344868eb32614cf3acb1a'

# append new selection
field.append_entry()
field[3].form.person.data = 'adad98ff74e2497a9e1dfbba0a6bbe96'
form.populate_obj(topic)
Expand All @@ -271,6 +278,16 @@ class TopicForm(Form):
('adad98ff74e2497a9e1dfbba0a6bbe96', (None, False)), # Abed _N_adir
]

# remove a person
field[1].form.person.data = ''
form.populate_obj(topic)

assert topic.content['people'] == [
('f0281b558a5f43f6ac81589d79538a87', (None, False)), # Britta _P_erry
('6d120102d90344868eb32614cf3acb1a', (None, False)), # Troy _B_arnes
('adad98ff74e2497a9e1dfbba0a6bbe96', (None, False)), # Abed _N_adir
]


def test_person_link_move_function():

Expand Down

0 comments on commit bdc57ed

Please sign in to comment.