Skip to content

fix(roles): support system permissions in roles permissions add/list and add remove#20

Open
chrisaddams wants to merge 1 commit into
mainfrom
fix/system-permissions-add-remove
Open

fix(roles): support system permissions in roles permissions add/list and add remove#20
chrisaddams wants to merge 1 commit into
mainfrom
fix/system-permissions-add-remove

Conversation

@chrisaddams

Copy link
Copy Markdown
Contributor

Summary

System permissions (e.g. `anythink_subscription_plans:*`) are defined globally without a corresponding entity row — their `entity_id` is `null`. Three gaps surfaced when trying to manage them via the CLI:

  • `roles permissions add` hard-failed because the entity lookup returned 404, so granting `anythink_subscription_plans:read` was impossible from the CLI.
  • `roles permissions list` filtered out any permission whose `entity_id` was `null`, so even when a system permission was assigned through the admin UI it was invisible.
  • There was no `roles permissions remove` at all.

Changes

  • `add`: catches the 404 from `GetEntityAsync`, then matches by exact name + `entity_id == null` so we only grant true system permissions and not anything that happens to share a name.
  • `list`: drops the `entity_id.HasValue` filter — system permissions now appear in the same table as entity-scoped ones.
  • `remove`: new command, mirrors `add`'s signature (`<role_id> --actions read,...`) and uses the same shared resolution helpers.

Verified locally

  • `anythink roles permissions add 7 anythink_subscription_plans --actions read` → "Added read"
  • `anythink roles permissions list 7` → shows `anythink_subscription_plans read`
  • `anythink roles permissions remove 7 anythink_subscription_plans --actions read` → "Removed read"
  • Round-trip add → list → remove → list all behave correctly against a tenant with no `anythink_subscription_plans` entity row.

…and add a remove command

System permissions (such as anythink_subscription_plans:*) are defined
globally without a corresponding entity row — their entity_id is null.
Three related gaps showed up when trying to manage them via the CLI:

- roles permissions add hard-failed when the named entity didn't exist,
  so granting anythink_subscription_plans:read was impossible.
- roles permissions list filtered out any permission whose entity_id was
  null, so even when a system permission was assigned through the admin
  UI it was invisible to the CLI.
- There was no roles permissions remove, so toggling off was impossible
  without dropping into the API directly.

This change makes the entity lookup tolerant of a 404, falls back to
matching permissions by exact name + entity_id == null when the entity
isn't found (so we only grant true system permissions, not anything
that happens to share a name), drops the entity_id filter from list,
and adds a parallel remove command.
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.

1 participant