Skip to content

Commit

Permalink
feat(topic source editor): change API endpoint to handle review state…
Browse files Browse the repository at this point in the history
… field of description
  • Loading branch information
yonadavGit committed Feb 1, 2024
1 parent 9e9af3f commit 72a86bd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion reader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3201,7 +3201,7 @@ def reorder_topics(request):
results.append(topic.contents())
return jsonResponse({"topics": results})

@catch_error_as_json
@staff_member_required
def topic_ref_api(request, tref):
"""
API to get RefTopicLinks, as well as creating, editing, and deleting of RefTopicLinks
Expand Down
23 changes: 22 additions & 1 deletion sefaria/helper/topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,13 @@ def rebuild_topic_toc(topic_obj, orig_slug="", category_changed=False):
library.get_topic_toc_json(rebuild=True)
library.get_topic_toc_category_mapping(rebuild=True)

def _calculate_approved_review_state(current, requested):
if current == "reviewed":
return "reviewed"
if requested == "edited":
return "edited"
if requested == "reviewed":
return "reviewed"
def edit_topic_source(slug, orig_tref, new_tref="", creating_new_link=True,
interface_lang='en', linkType='about', description={}):
"""
Expand Down Expand Up @@ -1166,9 +1173,23 @@ def edit_topic_source(slug, orig_tref, new_tref="", creating_new_link=True,
link.ref = new_tref

current_descriptions = getattr(link, 'descriptions', {})

requested_review_state = description.get("review_state")
current_review_state = current_descriptions.get(interface_lang).get("review_state")
approved_review_state = None

if requested_review_state and current_review_state:
approved_review_state = _calculate_approved_review_state(current_review_state, requested_review_state)

current_descriptions_in_lang = current_descriptions.get(interface_lang)
for key in description.keys():
if current_descriptions_in_lang.get(key) != description.get(key):
if key == "review_state":
requested_review_state = description.get("review_state")
current_review_state = current_descriptions_in_lang.get("review_state")
approved_review_state = _calculate_approved_review_state(current_review_state, requested_review_state)
if current_review_state:
current_descriptions_in_lang[key] = approved_review_state
elif current_descriptions_in_lang.get(key) != description.get(key):
current_descriptions_in_lang[key] = description.get(key)
link.descriptions = current_descriptions
# if current_descriptions.get(interface_lang, {}) != description: # has description in this language changed?
Expand Down

0 comments on commit 72a86bd

Please sign in to comment.