Skip to content

Provider admin#75

Open
chrisarridge wants to merge 13 commits intodevelopfrom
ca/provider-admin
Open

Provider admin#75
chrisarridge wants to merge 13 commits intodevelopfrom
ca/provider-admin

Conversation

@chrisarridge
Copy link
Copy Markdown
Contributor

This PR refactors and enabled provider admin functionality which closes #56:

  • New models are created for provider admin that allow us to a) describe a tool and it's providing organisation, b) link users to tools; c) link reporting organisations to tools. Together this provides the change to connect user permissions.
  • The provider admin code in the FGA validator and database provider is refactored to accommodate these changes.
  • Route code is modified and tests added to check the solution - as part of this some changes to the test configuration and SuiteCRM mock object were made.
  • A small fix to correct a failing test was also made at the beginning of the PR.

Note: I've added tests and then the feature work to made the tests pass, but this creates a failing repo at the test commits. Before merging I'll squash the feature and test commits together.

This commit fixes an apparently failing test of the delete user endpoint
that prevents the last admin user from being deleted from a reporting
organisation (test_delete_user_role_cannot_delete_last_admin_user).
This adds an integration test for the provider admin changes to
the PostgreSQL FGA provider database.
This commit adds the provider admin database models, database migration,
and associated code to support refactored provider admin functionality.
The provider_admin role is now generated dynamically by finding the users
of a tool (ToolUserDbModel) that has authorisation to access a reporting
organisation (ToolAuthorisationDbModel).  It also adds an integrity check
whereby a user cannot be associated with a tool and also have an
authorisation (admin, editor or contributor) for a reporting organisation.
This adds a unit test to ensure that provider admins permissions
are correctly parsed and validated by the FGA validator.  This commit
does not add checks for other role types, but this could be done in
the future.
This commit modifies the FGA validator to change the fine-grained
authorisations granted to provider admins.
Update the mock configuration and add additional SuiteCRM mocked
responses to test the revised provider admin functionality.
Adds tests that check provider admin works correctly on user endpoints.
This commit adds the necessary changes to implement provider admin in
user endpoints.  This essentially involves making sure that the new FGA
integrity exception is correctly handled in the dependencies.
This commit adds/updates reporting org endpoint tests for new provider
admin functionality.
This commit adds a new unit test that users have the correct permissions
for changing the visibility of a dataset.  This requires a change to the
mock suitecrm object so that it can return a dataset by ID and to
handle an update_record() call.
@chrisarridge chrisarridge requested a review from simon-20 April 13, 2026 11:38
@chrisarridge chrisarridge changed the title Ca/provider admin Provider admin Apr 13, 2026
reporting_org: UUID


class ToolUserDbModel(SQLModel, table=True):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This all looks good, my only thought so far is that ToolUserDbModel may (going forward) have the potential to be confusing, because the clients/customers of the 3rd party tools are also aptly described as "(3rd party) tool users". I wonder if ToolAdminUserDbModel might be more explanatory? Maybe that was discounted for another reason?

class ToolUserDbModel(SQLModel, table=True):
id: UUID = Field(primary_key=True, default_factory=lambda: uuid4())
tool: UUID = Field(foreign_key="tooldbmodel.id")
user: UUID
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add index?

.where(ToolUserDbModel.user == user)
).all()

if user_db_fgas and providers_reporting_orgs:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will block people from being both a provider admin for a tool, and also associated with a govern organisation in the normal way - is that correct? But some 3rd party tool providers publish datasets (whether or not they should or need to I don't know, but they do), so we might need to think that use-case through.

]

if len(associations) > 1:
if collections.Counter([association.user for association in associations]).most_common(1)[0][1] > 1:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This would also pick up if the FGA database gets into an error state where a user has two entries in there for the same org. I'm not suggesting this code needs to be changed, just flagging.

"delete-dataset",
]
permissions[FineGrainedAuthorisationRole.PROVIDER_ADMIN] = [
*permissions[FineGrainedAuthorisationRole.EDITOR],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this change in the requirements for provider admin permissions documented somewhere?

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.

Refactor provider admin

2 participants