rubyforgood / mutual-aid

Mutual aid management platform for groups who build, support, and strengthen community resilience.
https://github.com/rubyforgood/mutual-aid/projects/4
MIT License
54 stars 62 forks source link

Make NavBarPolicy allow Feedback only for Admins #996

Closed bobmazanec closed 2 years ago

bobmazanec commented 2 years ago

Why

To fix #992, show the Feedback NavBar button only to Admins & Sys-Admins

I chose those approach after seeing that the route triggered by the Feedback button uses the SoftwareFeedbacksController is derived from AdminController, which allows actions only by users with either the admin or sys_admin role. That is, I inferred the UI was incorrectly offering the button.

What

Change NavBarPolicy#visible_buttons to include Feedback only for Users with either the admin or sys_admin.

How

Moved adding Feedback to the allow-list from the line with NavBarPolicy#visible_buttons's simple non-nil check to the line guarded with the call to ApplicationPolicy#can_admin?

Testing

The PR modifies existing examples, removing the expectation for Feedback's presence for neighbor cases.

With modified examples, without modified code - 2 failures

image

With modified examples & code - 0 failures

image

Rubocop - no change

image

Outstanding Questions, Concerns and Other Notes

More about the specs than the bug: in my dev/repro environment, I noticed that my new User had the unset role. This was different from neighbor, but both are "neither admin nor sys_admin", so I simply modified the existing contexts.

Accessibility

None that I'm aware of.

Security

Very slight improvement—now the UI "advertises" one fewer route to non-{,sys}admin users.

Meta

This is my first PR here. I hope/believe I have read and understood the various guides, policies, etc. (humble apologies if not...) Constructive feedback welcome, of course.

Pre-Merge Checklist