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

Allow Per-department permissions #1362

Merged
merged 12 commits into from
Aug 20, 2024
Merged

Allow Per-department permissions #1362

merged 12 commits into from
Aug 20, 2024

Conversation

KludgeKML
Copy link
Contributor

@KludgeKML KludgeKML commented Jul 30, 2024

Adds the ability to mark a service as owned by one or more organisations, allowing users from those organisations that have been granted access to Local Links Manager in signon to view and edit links for those services. Other existing actions, and the ability to set owners, now only available with the new GDS Editor permission.

A menu option to Switch app has been added, consistent with Whitehall.

New tests are Request/System specs - we have not updated old Controller/Feature tests in this app, that has been captured as technical debt for updating later.

⚠️ WARNING: merging PR without first updating existing GDS users of LLM with the new permission will result in them losing the ability to view local authorities and services. Update their permissions before merging! ⚠️

  • Update permissions

https://trello.com/c/1eUXHHBz/22-restrict-access-to-a-specific-service

Screenshots

View of the services page when logged in as a user (note main menu does not offer the broken links or council options)

Screenshot 2024-08-14 at 11 24 26

View of an owned service page when logged in as a user (note main menu does not offer the broken links or council options, update owners link is not available in sidebar)

Screenshot 2024-08-14 at 11 24 34

View of the edit link page for an owned service page when logged in as a user (note main menu does not offer the broken links or council options, delete option is not available)

Screenshot 2024-08-14 at 11 24 43

View of an owned service page when logged in with GDS Editor permissions (update owners link is available in sidebar)

Screenshot 2024-08-14 at 11 22 05

New Update Owners form, available on when logged in with GDS Editor permissions

Screenshot 2024-08-14 at 11 22 19

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

@KludgeKML KludgeKML changed the title Add ADR about per-department permissions Allow Per-department permissions Aug 5, 2024
@KludgeKML KludgeKML force-pushed the per-department-permissions branch 4 times, most recently from d641dab to e07357d Compare August 12, 2024 15:17
@KludgeKML KludgeKML marked this pull request as ready for review August 12, 2024 15:17
@KludgeKML KludgeKML force-pushed the per-department-permissions branch 2 times, most recently from 6bee9d0 to 2534848 Compare August 12, 2024 15:45
Copy link
Contributor

@leenagupte leenagupte left a comment

Choose a reason for hiding this comment

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

This is looking really good.

I especially like the use of system and request tests.

I've left a few inline comments, but there isn't anything major.

One thing I have noticed though, that Local links manager doesn't have a way to get users back to Sign-on to choose another app, e.g. a departmental publisher wanting to go into Whitehall.

See the "switch app" menu option in Whitehall:
Screenshot 2024-08-13 at 14 13 54

Compared to Local links manager:
Screenshot 2024-08-13 at 14 14 11

If we are opening this up to non-GDS people, we probably need to add something so that they don't get trapped.

spec/support/authentication.rb Outdated Show resolved Hide resolved
spec/controllers/services_controller_spec.rb Outdated Show resolved Hide resolved
spec/features/services/service_show_spec.rb Show resolved Hide resolved
app/views/layouts/application.html.erb Outdated Show resolved Hide resolved
spec/support/authentication.rb Show resolved Hide resolved
app/controllers/links_controller.rb Outdated Show resolved Hide resolved
spec/requests/edit_link_page_spec.rb Outdated Show resolved Hide resolved
spec/requests/council_page_spec.rb Show resolved Hide resolved
app/controllers/services_controller.rb Outdated Show resolved Hide resolved
app/controllers/services_controller.rb Outdated Show resolved Hide resolved
@KludgeKML KludgeKML force-pushed the per-department-permissions branch 2 times, most recently from c84644d to b218f4b Compare August 14, 2024 13:37
KludgeKML and others added 4 commits August 14, 2024 14:59
- Add Switch app option
- Add check so that without the GDS Editor permission,
  a user won't see the Broken Links or Councils links
- Add new System test to check this
- Update authentication support file to simplify it
- Include authentication by default in all test types
- Add infer test type to RSpec

Co-authored-by: Ramya Vidapanakal <[email protected]>
@KludgeKML KludgeKML force-pushed the per-department-permissions branch 5 times, most recently from dac392d to c3d417c Compare August 14, 2024 15:19
Copy link
Contributor

@leenagupte leenagupte left a comment

Choose a reason for hiding this comment

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

Thanks for updating how permissions are checked so that they follow a consistent pattern 🎉

I've resolved all the comments from the previous review. Thanks for fixing.🥇

The only thing that's still a bit of a brain twister is the logic for permissions in the controllers. I've tried to think of ways to simplify the logic in inline comments, but it's tricky. I think it might be easier to follow if permissions are specifically applied to controller actions. i.e. actions a, b, and c require "gds_editor", d, e and f require "gds_editor" or "organisation", and if the action doesn't require any then, don't mention it. It might make the code a bit more verbose, but there wouldn't be any need to figure out what needs what.

I've also added a few other minor comments inline.

Comment on lines 6 to 7
before_action :redirect_unless_gds_editor, except: %i[update download_links_csv upload_links_csv]
before_action :forbid_unless_gds_editor, only: %i[update download_links_csv upload_links_csv]
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this a real brain teaser, probably because the list of links is the same in both actions. I get there, but it takes a while.

I think that as bad_homepage_url_and_status_csv is a file download, it should probably be forbidden if the user is not a gds_editor rather than a redirect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I've done is just been explicit about everything. There's an argument that we should do:

before_action blah_permission, only: [ etc]
before_action blah_permission 2, only: [ etc_a etc_b]
before_action blah_permission 3, except [listed above]

...because it means that if someone adds an action it always gets the final permission. But we don't add actions that frequently, so it might be better to only use only and always just list out all actions they apply to.

(I've also fixed the download to make it forbidden)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think perhaps this was made more confusing by having "unless" in the action name. Things being truthy can make the logic easier to follow.
i.e. rather than forbid_unless_gds_editor perhaps it could be named allow_if_gds_editor. Then even if an except was used there'd only be one negative in the logic. I think it was the double negatives that were causing the brain twisting.

spec/requests/bad_homepage_csv_spec.rb Outdated Show resolved Hide resolved
@@ -0,0 +1,16 @@
RSpec.describe "Services page" do
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the other routes have tests too? i.e. download_links_csv and upload_links_csv.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

Comment on lines 6 to 8
before_action :forbid_unless_permission, except: %i[index update_owner_form update_owner]
before_action :forbid_unless_gds_editor, only: %i[update_owner_form update_owner]
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still finding these permissions confusing. Using "except" and "only" is as confusing as reading "unless, else" for me, especially as the routes in both actions are almost the same.

So if I'm reading it correctly, everyone can see index, update_owner_form and update_owner?
But the exception for update_owner_form and update_owner are overwritten on the next line and restricted to gds_editor only?

Does update_owner_form and update_owner need to be covered by forbid_unless_permission if they're already covered by forbid_unless_gds_editor?

I for the controllers that the departments can access, I think it's only the create, update and destroy routes that need explicit permissions? The "GET" routes don't need to be restricted as everything else is restricted to only showing the data for the users organisation.

So perhaps all that's needed is the forbid_unless_gds_editor action?

before_action :forbid_unless_gds_editor, only: %i[update_owner_form update_owner]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As above, I've made this so it just uses only:

spec/requests/services_page_spec.rb Show resolved Hide resolved
KludgeKML and others added 2 commits August 19, 2024 11:01
- Auto-redirect to services page if not a GDS Editor,
  or forbid if it's not a navigable page.
- Edit link can be accessed by an owner.
- Add request tests to enforce these checks.
- Add shared examples to make tests simpler.

Co-authored-by: Ramya Vidapanakal <[email protected]>
KludgeKML and others added 3 commits August 19, 2024 11:56
- Only GDS Editors can see local authority list, or
  use local authority endpoints.
- Add request tests

Co-authored-by: Ramya Vidapanakal <[email protected]>
- GDS Editors can see list of all services, department
  users can only see their own services.
- All actions on services can only be performed by
  GDS Editors or users from owning departments.
- It's now legit for the services page not to have any
  services appearing because the current user might
  not belong to a department that owns any yet, and
  for GDS Editors a catastrophic loss of data shouldn't
  be a thing that a user has to detect.
- Make the upload services CSV work like the same
  one in the services controller (redirect to the service
  on a good import, redirect to the form on a bad one)

Co-authored-by: Ramya Vidapanakal <[email protected]>2
KludgeKML and others added 3 commits August 19, 2024 11:56
- Only GDS Editors can see this for the moment

Co-authored-by: Ramya Vidapanakal <[email protected]>
- Add owners to info block
- Turn council link into plain text, since it
  is confusing having two action links in the
  table row anyway, and department users
  shouldn't be able to see them

Co-authored-by: Ramya Vidapanakal <[email protected]>
- Use login_as_gds_editor because all old tests
  just assume you have all powers.
- Add default organisation for factory user

Co-authored-by: Ramya Vidapanakal <[email protected]>
Copy link
Contributor

@leenagupte leenagupte left a comment

Choose a reason for hiding this comment

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

Thanks for updating the controller permissions, I find them very easy to follow now. 🤩
Thank you bearing with me and making the changes and for adding the extra tests.
Everything looks great👍🥇

@KludgeKML KludgeKML merged commit cfd4f66 into main Aug 20, 2024
11 checks passed
@KludgeKML KludgeKML deleted the per-department-permissions branch August 20, 2024 12:48
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.

3 participants