Browse Source

Prevent edit conflicts for topic tags

merge-requests/74/head
Deimos 5 years ago
parent
commit
d07993bb11
  1. 1
      tildes/tildes/templates/intercooler/topic_tags_edit.jinja2
  2. 16
      tildes/tildes/views/api/web/topic.py

1
tildes/tildes/templates/intercooler/topic_tags_edit.jinja2

@ -12,6 +12,7 @@
data-ic-target="#sidebar .topic-tags"
data-js-remove-on-success
>
<input type="hidden" name="conflict_check" id="conflict_check" value="{{ topic.tags|join(",") }}">
{{ topic_tagging(value=topic.tags|join(', '), auto_focus=True, autocomplete_options=topic.group.common_topic_tags) }}
<div class="form-buttons">
<button class="btn btn-primary" type="submit">Save tags</button>

16
tildes/tildes/views/api/web/topic.py

@ -161,11 +161,23 @@ def get_topic_tags(request: Request) -> dict:
renderer="topic_tags.jinja2",
permission="tag",
)
@use_kwargs({"tags": String()})
def put_tag_topic(request: Request, tags: str) -> dict:
@use_kwargs({"tags": String(), "conflict_check": String()})
def put_tag_topic(request: Request, tags: str, conflict_check: str) -> dict:
"""Apply tags to a topic with Intercooler."""
# pylint: disable=too-many-branches
topic = request.context
# check for edit conflict by verifying tags didn't change after they loaded the form
if conflict_check:
conflict_check_tags = conflict_check.split(",")
else:
conflict_check_tags = []
if conflict_check_tags != topic.tags:
raise ValidationError(
{"tags": ["Someone else edited simultaneously, please cancel and retry"]}
)
if tags:
# split the tag string on commas
new_tags = tags.split(",")

Loading…
Cancel
Save