Add owning_organisations to ministers index links #3162
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently we have to expand links from the minsiters index content item to every ministerial department, and from there:
We then use the department role ids to filter the list of roles for each minister, so we can show a list of departments, the department's ministers, and their roles within the department.
Unfortuanetly, the ordered_roles for a department includes all the roles, not just ministerial roles. So there are a lot of them. The ministers index content item currently includes 1,745 roles:
The code in collections has to filter the roles for a minister based on this list of all the roles for the department:
https://github.com/alphagov/collections/blob/main/app/presenters/ministers_index_presenter.rb#L99
It would be simpler and more efficient if we could link directly from the role back to the departments the role belongs to. This information is already in the database, because organisations have ordered_role links to all the roles they own.
This commit introduces a reverse link for ordered_roles - owning_organisations. We can then use this in the expansion rules to include the owning_organisations for each role for each minister for each department.
There don't appear to be many tests for specific link expansion scenarios, but you can see this working by doing:
in a rails console and looking for the owning_organisations links.
The ordered_roles link expansion is left in place for now, as we need to update collections to use the new links before we can remove the old ordered_roles expansion.
This application is owned by the publishing platform team. Please let us know in #govuk-publishing-platform when you raise any PRs.