Skip to content
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

Merged
merged 1 commit into from
Dec 24, 2021

Conversation

gaoxk
Copy link
Contributor

@gaoxk gaoxk commented Dec 23, 2021

Notion ticket link

https://www.notion.so/uwblueprintexecs/a658c933d18c48d4b43fd99bda2bd3b4?v=ba22ac93d09040ff8219c60ac7caabdb&p=fc6fd704b0674be19c756b4a1c30ef6c)

Implementation description

  • swapped out _get_story_translations_user_translating and _get_story_translations_user_reviewing for flexible query builder
  • added checks to get_stories_available_for_translation and get_story_translations_available_for_review
    • if there exists ongoing story translations with same language+role for user, return []
    • this could be swapped with an error message that could be displayed, but the designs for that are TBD.
  • passed in user_id for admin's UserProfile view to relative mutations

Steps to test

Homepage View

Translate

  1. login as planetread+dwightdeisenhower@uwblueprint.org
  2. observe ongoing no English US, but ongoing English UK and German translations.
  3. go to browse stories. set TRANSLATOR role.
  4. Observe that no results show for English UK and German filters.
  5. set language to English US. Notice results. complete flow and verify new (and correct) story translation in table. (note this tests the modified create_translation!)

Review

  1. stay on same user
  2. observe no ongoing review of English UK, but an ongoing English US
  3. go to browse stories. set REVIEWER role.
  4. Observe that no results show for English US.
  5. set language to English UK. Notice results. complete flow and verify it assigned the user correctly. (note this tests the modified assign_user_as_reviewer!)

Admin UserProfile View

erase & reseed db

docker exec -it planet-read_py-backend_1 /bin/bash -c "python -m tools.insert_test_data erase"
docker exec -it planet-read_py-backend_1 /bin/bash -c "python -m tools.insert_test_data"

Translate

  1. go to http://localhost:3000/user/4 . observe ongoing no English US, but ongoing English UK and German translations.
  2. attempt to assign English US. Notice results. complete flow and verify new (and correct) story translation in table.
  3. attempt to assign English UK and German. Notice empty results for all levels

Review

  1. Stay on the same page. observe no ongoing review of English UK, but an ongoing English US
  2. attempt to assign English UK. Notice results for level 3. complete flow and verify it assigned the user correctly.
  3. attempt to assign English US. Notice empty results for all levels

What should reviewers focus on?

  • does it work?

Checklist

  • My PR name is descriptive and in imperative tense
  • My commit messages are descriptive and in imperative tense. My commits are atomic and trivial commits are squashed or fixup'd into non-trivial commits
  • For backend changes, I have run the appropriate linters: 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>"
  • I have requested a review from the PL, as well as other devs who have background knowledge on this PR or who will be building on top of this PR

@@ -51,3 +59,10 @@ def resolve_story_translation_tests(root, info, language, level, stage, story_ti
return services["story"].get_story_translation_tests(
user, language, level, stage, story_title
)


def _select_user_id_for_available_translations_query(user_id):
Copy link
Contributor Author

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

Copy link
Collaborator

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 of searching_user_id? i'm not sure if it's more readable or not

and consequently something like _target_user_id_for_available_translations_query for the helper

Copy link
Contributor Author

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 !

@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made this change to make the function header more readable

@github-actions
Copy link

github-actions bot commented Dec 23, 2021

Visit the preview URL for this PR (updated for commit 4d1d49a):

https://planet-read-uwbp--pr229-fix-dont-return-tran-lhgz5wmi.web.app

(expires Fri, 31 Dec 2021 04:36:26 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Copy link
Collaborator

@Puepis Puepis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -51,3 +59,10 @@ def resolve_story_translation_tests(root, info, language, level, stage, story_ti
return services["story"].get_story_translation_tests(
user, language, level, stage, story_title
)


def _select_user_id_for_available_translations_query(user_id):
Copy link
Collaborator

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 of searching_user_id? i'm not sure if it's more readable or not

and consequently something like _target_user_id_for_available_translations_query for the helper


stories = (
Story.query.filter(Story.level == level)
.filter(~Story.translated_languages.contains(language))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a q: what does the ~Story... syntax mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

negation! this reads as return story translations where translated_languages does not contain language

@gaoxk gaoxk merged commit 6e3fb13 into main Dec 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants