-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Origin/backend/enforce story translation stage logic #99
Origin/backend/enforce story translation stage logic #99
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! everything worked for me while testing. Rebase onto main branch, work on the feedback, and let me know when it's ready for re-review!
Comment.story_translation_content_id | ||
== comment["story_translation_content_id"] | ||
user_id = get_user_id_from_request() | ||
new_comment = Comment(**comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
20-37 should be wrapped in a try statement (see how it was previously wrapped)
story_translation_translator_id = story_translation.translator_id | ||
story_translation_reviewer_id = story_translation.reviewer_id | ||
|
||
is_translator = user_id == str(story_translation_translator_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than wrap str()
around story_translation_translator_id
and story_translation_reviewer_id
, can you wrap get_user_id_from_request()
with int()
on line 20 and leave a comment to remove it when get_user_id_from_request()
is updated to return ints? example comment
new_comment = Comment(**comment) | ||
new_comment.user_id = user_id | ||
|
||
story_translation_content = StoryTranslationContent.query.filter_by( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! this works, but getting story_translation_content and getting story_translation on line 29 are two database queries. Can you try using only 1 database query? You'll need to join StoryTranslation
and StoryTranslationContent
together.
self.logger.error( | ||
"Failed to update story translation content. Reason = {reason}".format( | ||
reason=(reason if reason else str(error)) | ||
story_translation_content = StoryTranslationContent.query.filter_by( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto comment about wrapping this in a try statement. You should always wrap any database interactions with try statements, because they could always fall through if the database has issues!
seed_db.sh
Outdated
@@ -1,45 +1,45 @@ | |||
# ***** How to Use: ***** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this a result of the linter?
96d0a66
to
1dec0b1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! feel free to merge after addressing nits. let me know if you have any questions about the nit
(((A relevant stackoverflow thread you might find interesting)))
|
||
max = ( | ||
db.session.query(func.max(Comment.comment_index)) | ||
story_translation = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice query! nit: I believe db.session.query(StoryTranslation).join(....
could be rewritten as StoryTranslation.query.join(...
. I think the latter option is more clear
db.session.bulk_update_mappings( | ||
StoryTranslationContent, story_translation_contents | ||
story_translation = ( | ||
db.session.query(StoryTranslation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto comment
story_translation = StoryTranslationContent.query.filter_by( | ||
id=story_translation_content.id | ||
).first() | ||
story_translation = StoryTranslationContent.query.filter_by( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I leave this one because it's in the deprecated function?
Notion ticket link
Enforce story translation stage logic
Implementation description
create_comment
incomment_service.py
): if the stage isTRANSLATE
, translators can leave comments and reviewers cannot; if the stage isREVIEW
, reviewers can leave comments and translators cannot; if the stage isPUBLISH
, no comments can be leftupdate_story_translation_contents
instory_service.py
): contents can be changed only if the stage isTRANSLATE
Steps to test
mutation { createComment (commentData: { storyTranslationContentId: 55, content: "", }) { ok comment { id storyTranslationContentId userId commentIndex time resolved content } } }
mutation { createComment (commentData: { storyTranslationContentId: 25, content: "", }) { ok comment { id storyTranslationContentId userId commentIndex time resolved content } } }
mutation { updateStoryTranslationContents (storyTranslationContents: { id: 55, translationContent: "hi", }) { story { id translationContent } } }
mutation { createComment (commentData: { storyTranslationContentId: 55, content: "", }) { ok comment { id storyTranslationContentId userId commentIndex time resolved content } } }
mutation { createComment (commentData: { storyTranslationContentId: 25, content: "", }) { ok comment { id storyTranslationContentId userId commentIndex time resolved content } } }
update story_translations set stage = 'REVIEW' where story_id = 6;
mutation { createComment (commentData: { storyTranslationContentId: 55, content: "", }) { ok comment { id storyTranslationContentId userId commentIndex time resolved content } } }
mutation { createComment (commentData: { storyTranslationContentId: 25, content: "", }) { ok comment { id storyTranslationContentId userId commentIndex time resolved content } } }
mutation { updateStoryTranslationContents (storyTranslationContents: { id: 55, translationContent: "hi", }) { story { id translationContent } } }
mutation { createComment (commentData: { storyTranslationContentId: 55, content: "", }) { ok comment { id storyTranslationContentId userId commentIndex time resolved content } } }
mutation { createComment (commentData: { storyTranslationContentId: 25, content: "", }) { ok comment { id storyTranslationContentId userId commentIndex time resolved content } } }
mutation { createComment (commentData: { storyTranslationContentId: 55, content: "", }) { ok comment { id storyTranslationContentId userId commentIndex time resolved content } } }
mutation { createComment (commentData: { storyTranslationContentId: 25, content: "", }) { ok comment { id storyTranslationContentId userId commentIndex time resolved content } } }
mutation { updateStoryTranslationContents (storyTranslationContents: { id: 55, translationContent: "hi", }) { story { id translationContent } } }
mutation { createComment (commentData: { storyTranslationContentId: 55, content: "", }) { ok comment { id storyTranslationContentId userId commentIndex time resolved content } } }
mutation { createComment (commentData: { storyTranslationContentId: 25, content: "", }) { ok comment { id storyTranslationContentId userId commentIndex time resolved content } } }
What should reviewers focus on?
Checklist
docker exec -it planet-read_py-backend_1 /bin/bash -c "black . && isort --profile black ."
and I have generated new migrations:flask db migrate -m "<your message>"