Skip to content

DEP-262: add SUPER_ADMIN role and associated functionality to db; remove staff_user tenant_id column - #2843

Merged
NatSquared merged 6 commits into
mainfrom
DEP-262-add-super-admin-role-db
May 7, 2026
Merged

DEP-262: add SUPER_ADMIN role and associated functionality to db; remove staff_user tenant_id column#2843
NatSquared merged 6 commits into
mainfrom
DEP-262-add-super-admin-role-db

Conversation

@NatSquared

Copy link
Copy Markdown
Collaborator

Issue #: 🎟️ DEP-262

Description of changes:

User Guide update ticket (if applicable):

  • Feature Sync SUPER_ADMIN tenant membership and protect super admins in user management

    • Added a migration to create the SUPER_ADMIN group, the super_admin role, and their mapping so super admins can be represented in tenant memberships.
    • Updated the API to add or remove SUPER_ADMIN group membership based on the user's Keycloak roles during login/request processing, including unit tests for assignment and removal.
    • Updated the user management UI to recognize Super Admin as a composite role and prevent administrators and super admins from being deactivated, while showing the correct permission messaging.
    • Removed the tenant_id column from staff_user table, as tenant membership is determined by group memberships rather than a direct column on the user model, making the column redundant.
    • Yes, a user guide update ticket has been created. (Link to ticket)
    • No, a user guide update ticket is not required.

Common component changes:

    • Yes, I have updated CONTRIBUTING.md and the docblocks to document any changes to the common components.
    • No, there are no changes to the common components.

@codecov-commenter

codecov-commenter commented May 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.24832% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.16%. Comparing base (4c7ac72) to head (6a62c00).

Files with missing lines Patch % Lines
api/src/api/services/staff_user_service.py 89.85% 7 Missing ⚠️
.../src/api/services/user_group_membership_service.py 91.66% 4 Missing ⚠️
...ponents/userManagement/userDetails/UserDetails.tsx 69.23% 4 Missing ⚠️
api/src/api/resources/staff_user.py 0.00% 2 Missing ⚠️
web/src/services/userService/api/index.tsx 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2843      +/-   ##
==========================================
+ Coverage   74.96%   75.16%   +0.19%     
==========================================
  Files         517      517              
  Lines       19932    20055     +123     
  Branches     1612     1723     +111     
==========================================
+ Hits        14942    15074     +132     
+ Misses       4982     4972      -10     
- Partials        8        9       +1     
Flag Coverage Δ
api 85.31% <89.84%> (+0.27%) ⬆️
web 63.42% <71.42%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
api/src/api/__init__.py 92.03% <100.00%> (+0.07%) ⬆️
api/src/api/models/base_model.py 98.11% <100.00%> (ø)
api/src/api/models/staff_user.py 91.78% <100.00%> (-0.22%) ⬇️
api/src/api/schemas/staff_user.py 100.00% <ø> (ø)
api/src/api/utils/constants.py 80.00% <100.00%> (+1.05%) ⬆️
api/src/api/utils/enums.py 100.00% <100.00%> (ø)
...s/userManagement/listing/UserManagementContext.tsx 70.90% <ø> (ø)
...s/userManagement/listing/UserManagementListing.tsx 84.21% <ø> (ø)
...ts/userManagement/userDetails/UserStatusButton.tsx 64.51% <100.00%> (+2.44%) ⬆️
web/src/models/user.ts 100.00% <ø> (ø)
... and 5 more

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@NatSquared
NatSquared requested a review from jareth-whitney May 5, 2026 00:54

@jareth-whitney jareth-whitney left a comment

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 is great, I think it will help with some of the login issues I've been experiencing. No dealbreakers here, you're good to merge.

I believe, from reading your PR, that we will always have a tenant_id for a user based on data from another table or app state, but please verify that's the case. Also, can you imagine a scenario where a bad actor could spoof their Keycloak role, triggering super_admin privilege? I'm guessing not, but it's worth thinking about for a moment.

)


def downgrade():

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.

So remove all user_group_memberships where the role ID is equal to super_admin. Yes that makes sense.

def upgrade():
_drop_matching_foreign_keys('staff_users', 'tenant_id', 'tenant')
with op.batch_alter_table('staff_users', schema=None) as batch_op:
batch_op.drop_column('tenant_id')

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.

Are we removing tenant ID from the staff_users table because it's a redundant link? I.e. you can extract the users from the tenant, therefor the tenant doesn't need to be nested in the user? Otherwise it seems like it could be useful to have available.

Comment thread api/tests/conftest.py
factory_user_group_membership_model(str(user.external_id), group_id=CompositeRoleId.TEAM_MEMBER.value)
claims = copy.deepcopy(TestJwtClaims.team_member_role.value)
claims['sub'] = str(user.external_id)

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.

Thank you for updating the unit tests thoroughly.

Comment thread CHANGELOG.MD

- **Feature** Sync SUPER_ADMIN tenant membership and protect super admins in user management [🎟️ DEP-262](https://citz-gdx.atlassian.net/browse/DEP-262)
- Added a migration to create the `SUPER_ADMIN` group, the `super_admin` role, and their mapping so super admins can be represented in tenant memberships.
- Updated the API to add or remove `SUPER_ADMIN` group membership based on the user's Keycloak roles during login/request processing, including unit tests for assignment and removal.

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.

I think this should be safe if we're qualifying the information that we're receiving from Keycloak. I just want to make sure that there's no way a bad actor could spoof these credentials in order to gain super_admin access. If it's just textbook OAuth/SAML then please ignore.

@sonarqubecloud

sonarqubecloud Bot commented May 6, 2026

Copy link
Copy Markdown

@NatSquared
NatSquared merged commit 739ecb8 into main May 7, 2026
16 checks passed
@NatSquared
NatSquared deleted the DEP-262-add-super-admin-role-db branch May 7, 2026 00:00
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