-
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
Don’t return story translations if user already translating/reviewing for language #229
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,21 +70,13 @@ def create_story(self, story, content): | |
|
||
return new_story | ||
|
||
def get_stories_available_for_translation(self, language, level): | ||
stories = ( | ||
Story.query.filter(Story.level == level) | ||
.filter(~Story.translated_languages.contains(language)) | ||
.all() | ||
) | ||
return [story.to_dict(include_relationships=True) for story in stories] | ||
|
||
def create_translation(self, translation): | ||
try: | ||
new_story_translation = StoryTranslation(**translation.__dict__) | ||
story_translations_translating = ( | ||
self._get_story_translations_user_translating( | ||
new_story_translation.translator_id | ||
) | ||
self._get_story_translations_user_translating_query( | ||
new_story_translation.translator_id, isTranslator=True | ||
).all() | ||
) | ||
languages_currently_translating = self._get_story_translation_languages( | ||
story_translations_translating | ||
|
@@ -173,7 +165,9 @@ def create_translation_test(self, user_id, level, language): | |
raise error | ||
return new_story_translation | ||
|
||
def get_story_translations_by_user(self, user_id, is_translator, language, level): | ||
def get_story_translations_by_user( | ||
self, user_id, is_translator=None, language=None, level=None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. made this change to make the function header more readable |
||
): | ||
if is_translator is None: | ||
role_filter = (StoryTranslation.translator_id == user_id) | ( | ||
StoryTranslation.reviewer_id == user_id | ||
|
@@ -430,8 +424,10 @@ def get_story_translation(self, id): | |
raise error | ||
|
||
def assign_user_as_reviewer(self, user, story_translation): | ||
story_translations_reviewing = self._get_story_translations_user_reviewing( | ||
user.id | ||
story_translations_reviewing = ( | ||
self._get_story_translations_user_translating_query( | ||
user.id, isTranslator=False | ||
).all() | ||
) | ||
languages_currently_reviewing = self._get_story_translation_languages( | ||
story_translations_reviewing | ||
|
@@ -608,8 +604,40 @@ def update_story_translation_stage(self, story_translation_data, user_id): | |
self.logger.error(error) | ||
raise error | ||
|
||
def get_story_translations_available_for_review(self, language, level): | ||
def get_stories_available_for_translation(self, language, level, user_id): | ||
try: | ||
ongoing_translations = ( | ||
self._get_story_translations_user_translating_query( | ||
user_id, isTranslator=True | ||
) | ||
.filter(StoryTranslation.language == language) | ||
.all() | ||
) | ||
if len(ongoing_translations) > 0: | ||
return [] | ||
|
||
stories = ( | ||
Story.query.filter(Story.level == level) | ||
.filter(~Story.translated_languages.contains(language)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just a q: what does the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. negation! this reads as |
||
.all() | ||
) | ||
return [story.to_dict(include_relationships=True) for story in stories] | ||
except Exception as error: | ||
self.logger.error(str(error)) | ||
raise error | ||
|
||
def get_story_translations_available_for_review(self, language, level, user_id): | ||
try: | ||
ongoing_translations = ( | ||
self._get_story_translations_user_translating_query( | ||
user_id, isTranslator=False | ||
) | ||
.filter(StoryTranslation.language == language) | ||
.all() | ||
) | ||
if len(ongoing_translations) > 0: | ||
return [] | ||
|
||
stories = ( | ||
Story.query.join( | ||
StoryTranslation, Story.id == StoryTranslation.story_id | ||
|
@@ -848,18 +876,15 @@ def _get_num_approved_lines(self, translation_contents): | |
|
||
return count | ||
|
||
def _get_story_translations_user_translating(self, user_id): | ||
return ( | ||
StoryTranslation.query.filter(StoryTranslation.translator_id == user_id) | ||
.filter(StoryTranslation.stage != "PUBLISH") | ||
.all() | ||
) | ||
|
||
def _get_story_translations_user_reviewing(self, user_id): | ||
def _get_story_translations_user_translating_query(self, user_id, isTranslator): | ||
return ( | ||
StoryTranslation.query.filter(StoryTranslation.reviewer_id == user_id) | ||
StoryTranslation.query.filter(StoryTranslation.is_test == False) | ||
.filter( | ||
StoryTranslation.translator_id == user_id | ||
if isTranslator | ||
else StoryTranslation.reviewer_id == user_id | ||
) | ||
.filter(StoryTranslation.stage != "PUBLISH") | ||
.all() | ||
) | ||
|
||
def _get_story_translation_languages(self, story_translations): | ||
|
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.
Putting this here because moving it to story_service means adding the user service to the story service. Also, this sticks to the principle of keeping authentication out of the story services. lmk if you can think of a better name tho LOL
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.
what do you think about something like
target_user_id
instead ofsearching_user_id
? i'm not sure if it's more readable or notand consequently something like
_target_user_id_for_available_translations_query
for the helperThere 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.
I think the verb "select" makes more sense than "target" for the function name, but I will swap searching_user_id for target_user_id !