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

Show/hide buttons on NavBar based on user role #850

Merged
merged 2 commits into from
Feb 13, 2021
Merged

Conversation

solebared
Copy link
Collaborator

@solebared solebared commented Feb 3, 2021

Why

Required before we can re-enable user registration (#840).

What and How

  • Move the logic of which buttons to show out of NavBar.vue and into a new headless policy NavBarPolicy.
  • Custom method NavBarPolicy.visible_buttons returns an array of which buttons to show.
  • This array is sent to NavBar.vue which guards each button by checking against the array.

Testing

  • Added nav_bar_policy_spec.rb
  • Corresponding modifications to NavBar.spec.js
# spec/policies/nav_bar_policy_spec.rb
NavBarPolicy
  visible_buttons
    guest
      is expected to contain exactly "Login"
      in peer_to_peer mode
        is expected to contain exactly "Contributions" and "Login"
    neighbor
      is expected to contain exactly "Feedback" and "Logout"
      in peer_to_peer mode
        is expected to contain exactly "Contributions", "Feedback", and "Logout"
    admin
      is expected to contain exactly "Contributions", "Matches", "Admin", "Feedback", and "Logout"
    sys_admin
      is expected to contain exactly "Contributions", "Matches", "Admin", "Feedback", and "Logout"


// spec/javascript/components/NavBar.spec.js
NavBar
  visible buttons
    when not instructed to show additional buttons
      ✓ shows publicly accessible links
    when instructed to show Contributions
      ✓ includes specified buttons
    when instructed to show all admin buttons
      ✓ includes specified buttons

Next Steps

Outstanding Questions, Concerns and Other Notes

?

Pre-Merge Checklist

  • All new features have been described in the pull request
  • Security & accessibility have been considered
  • High quality tests have been added, or an explanation has been given why the features cannot be tested
  • New features have been documented, and the code is understandable and well commented
  • Entry added to CHANGELOG.md if appropriate
  • All outstanding questions and concerns have been resolved
  • Any next steps that seem like good ideas have been created as issues for future discussion & implementation

@solebared solebared mentioned this pull request Feb 3, 2021
30 tasks
Designed to hold all the logic around which buttons to show in the top
nav (except those shown at all times).

Not wired in yet; see subsequent commit.
Shifts intelligence around which buttons to show onto NavBarPolicy on
the server, simplifying the implementation in this component.
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.

5 participants