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

Add owning_organisations to ministers index links #3162

Merged
merged 2 commits into from
Feb 25, 2025

Conversation

richardTowers
Copy link
Contributor

@richardTowers richardTowers commented Feb 25, 2025

Currently we have to expand links from the minsiters index content item to every ministerial department, and from there:

  • every minister in the department
    • every role the minister has
  • every role in the department

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:

curl --silent 'https://www.gov.uk/api/content/government/ministers' | jq -r '.links.ordered_ministerial_departments[].links.ordered_roles[].title' | wc -l

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:

Presenters::EditionPresenter.new(Edition.live.find_by(base_path: "/government/ministers")).expanded_links

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 repo is Continuously Deployed: make sure you follow the guidance ⚠️

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

Currently we have to expand links from the minsiters index content item
to every ministerial department, and from there:

- every minister in the department
  - every role the minister has
- every role in the department

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:

    curl --silent 'https://www.gov.uk/api/content/government/ministers' | jq -r '.links.ordered_ministerial_departments[].links.ordered_roles[].title' | wc -l

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:

    Presenters::EditionPresenter.new(Edition.live.find_by(base_path: "/government/ministers")).expanded_links

in a rails console and looking for the owning_organisations links.

This will affect expanded links for the ministers index page, as well as
all the Role content items (which directly have this link).

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.
In practice, we only expect these to appear on Role and MinistersIndex
content items, but the content schemas aren't clever enough to represent
that.
@richardTowers richardTowers force-pushed the ministers-index-expansion branch from 953dda4 to e69aa59 Compare February 25, 2025 13:53
Copy link
Member

@yndajas yndajas left a comment

Choose a reason for hiding this comment

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

Congratulations on winning the content schema test lottery 🎉

@richardTowers richardTowers merged commit 0084161 into main Feb 25, 2025
40 checks passed
@richardTowers richardTowers deleted the ministers-index-expansion branch February 25, 2025 14:14
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