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

Tidy up organisation-related code #3178

Merged
merged 5 commits into from
Oct 1, 2024
Merged

Conversation

yndajas
Copy link
Member

@yndajas yndajas commented Sep 19, 2024

Trello

This tidies up a bunch of organisation-related code, mostly stuff spotted while working on adding autocomplete to the organisation fields. In particular:

  • removing and/or consolidating unused or redundant methods/scopes
  • adding a default scope

This application is owned by the publishing platform team. Please let us know in #govuk-publishing-platform when you raise any PRs.

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

Follow these steps if you are doing a Rails upgrade.

@yndajas yndajas force-pushed the simplify-organisation-selection branch 3 times, most recently from 9a7bc28 to 037f5b3 Compare October 1, 2024 10:15
@yndajas yndajas changed the title Simplify organisation selection Tidy up organisation-related code Oct 1, 2024
@yndajas yndajas changed the base branch from main to fix-missing-assertions October 1, 2024 10:18
@yndajas yndajas force-pushed the simplify-organisation-selection branch from 037f5b3 to cc6539d Compare October 1, 2024 10:19
@yndajas yndajas marked this pull request as ready for review October 1, 2024 10:19
@yndajas yndajas force-pushed the simplify-organisation-selection branch from cc6539d to 28b1e03 Compare October 1, 2024 10:22
Base automatically changed from fix-missing-assertions to main October 1, 2024 10:44
Copy link
Contributor

@Gweaton Gweaton left a comment

Choose a reason for hiding this comment

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

Looks good, just a couple of questions

app/helpers/users_helper.rb Show resolved Hide resolved
app/helpers/role_organisations_helper.rb Show resolved Hide resolved
app/helpers/organisation_helper.rb Outdated Show resolved Hide resolved
These aren't used anywhere and have no tests
We order them by name in a few places. In the organisations index
they're in whatever order the database returns them in, which feels odd.
This adds a sensible default for now, similar to other models
(`ApiUser`, `Doorkeeper::Application`, and `SupportedPermission`)
The use of a non-standard dash here made some test failure output hard
to read. I think this was using an em dash instead of en, or en instead
of hyphen, but I think we can just use the standard dash and leave it to
the browser to render appropriately
This wasn't being used in the organisations index. We had custom logic
which resulted in organisations without abbreviations having empty
brackets after their name, which looked odd. This method separates the
name and abbreviation with a dash rather than putting the abbreviation
in brackets, but there doesn't seem to be an obvious reason why both
uses can't be the same

The dash used in the method was a non-standard character, so that's
fixed here
These are essentially doing the same thing, so there's no need to have
multiple methods for them

I've deleted a test from a controller spec that duplicates a helper test
added here

I had considered removing the `Organisation` policy scope. The scope
gives GOV.UK admins access to all organisations and everyone else access
to none, but is only used in places that are accessible only to GOV.UK
admins (also based on the organisation policy), so it felt like a bit of
a double-authorisation situation. However, George and I felt a bit
uneasy about the potential for the `options_for_organisation_select`
method being used elsewhere in future, and the authorisation therefore
being skipped. As a result, we've retained the double authorisation, and
I've included a scope-based context in the helper tests

Another thing I spotted is that the `User` model has a
`manageable_organisations` method, in turn relying on e.g.
`Roles::Admin.manageable_organisations_for` or
`Roles::SuperOrganisationAdmin.manageable_organisations_for`. This is
used for filtering users by organisation in the users page/table, rather
than populating a select field when creating/editing users, but the name
makes the remits a little hard to differentiate without close inspection
@yndajas yndajas force-pushed the simplify-organisation-selection branch from 28b1e03 to 8075a72 Compare October 1, 2024 13:22
@yndajas yndajas merged commit 05213cd into main Oct 1, 2024
15 checks passed
@yndajas yndajas deleted the simplify-organisation-selection branch October 1, 2024 13:36
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