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

Fixes 500 error when viewing the "Tag Mods" page without having the role on the database #10515

Merged
merged 3 commits into from Oct 1, 2020
Merged

Fixes 500 error when viewing the "Tag Mods" page without having the role on the database #10515

merged 3 commits into from Oct 1, 2020

Conversation

diogoosorio
Copy link
Contributor

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

I think that the issue (#10060) is self-explanatory. What was happening with @msarit was that she was visiting the /admin/mods?state=tag_moderator without having a role named tag_moderator on the database.

The query class explicitly "blew up" in this condition. I tried to follow the approach proposed by @Zhao-Andy:

  1. The query class now doesn't raise an exception in the scenario above. Instead returns an empty result set

  2. The mods page now returns a generic "there are mods matching your search" warning if there are no mods matching the query

Related Tickets & Documents

#10060

QA Instructions, Screenshots, Recordings

  1. Go to the /admin/mods page

  2. Search by a random text string which yields no results and see that a "no results" message is rendered

  3. Delete the tag_moderator role from your database (Role.find_by(name: "tag_moderator").delete)

  4. Go to /admin/mods?state=tag_moderator

  5. See that a "no results" message is rendered

image

Added tests?

  • yes
  • no, because they aren't needed
  • no, because I need help

Added to documentation?

  • docs.forem.com
  • readme
  • no documentation needed

The current implementation of the query would yield an exception when
recieving an invalid state parameter. As per the [GH issue
discussion](#10060 (comment)),
Zhao recommended to change its behaviour and not trigger an exception in
this condition.

This commit does just that. If the state argument is invalid, the query
now returns an empty result set.
@diogoosorio diogoosorio requested review from a team and michael-tharrington and removed request for a team October 1, 2020 17:30
@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Oct 1, 2020
@fdocr fdocr requested review from a team, juliannatetreault and benhalpern and removed request for michael-tharrington and a team October 1, 2020 18:18
Copy link
Contributor

@fdocr fdocr left a comment

Choose a reason for hiding this comment

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

Thank you for the fix @diogoosorio. Tested it locally and seems to be working well

@@ -24,7 +24,7 @@ def self.call(relation: User.all, options: {})
end

def self.role_id_for(role)
Role.find_by!(name: role).id
Role.find_by(name: role)&.id
Copy link
Contributor

Choose a reason for hiding this comment

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

I always forget about this operator, nice 🙌

@pr-triage pr-triage bot added PR: partially-approved bot applied label for PR's where a single reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Oct 1, 2020
@fdocr fdocr requested a review from Zhao-Andy October 1, 2020 18:39
Copy link
Contributor

@juliannatetreault juliannatetreault left a comment

Choose a reason for hiding this comment

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

Awesome work, @diogoosorio ! This worked great locally. 🚀

@fdocr fdocr merged commit 3bc51a1 into forem:master Oct 1, 2020
@pr-triage pr-triage bot added PR: merged bot applied label for PR's that are merged and removed PR: partially-approved bot applied label for PR's where a single reviewer approves changes labels Oct 1, 2020
@diogoosorio diogoosorio deleted the diogoosorio/tag-mods-link-10060 branch October 1, 2020 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: merged bot applied label for PR's that are merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants