Skip to content

Count each permission only once in a user's permissionsCount - #6131

Closed
fraxachun wants to merge 1 commit into
mainfrom
claude/user-permissions-count-distinct
Closed

Count each permission only once in a user's permissionsCount#6131
fraxachun wants to merge 1 commit into
mainfrom
claude/user-permissions-count-distinct

Conversation

@fraxachun

Copy link
Copy Markdown
Contributor

Problem

The permissionsCount field resolver for a user counted getPermissions(user).length. A permission can be granted both by rule and manually, in which case getPermissions returns it twice — so the permissions count shown for a user in the admin users list could be inflated and even exceed the number of available permissions (e.g. "19 of 18 permissions").

Solution

Count distinct permissions by deduplicating on the permission name.

return new Set((await this.userService.getPermissions(user)).map((permission) => permission.permission)).size;

Adds a unit test covering a permission granted both by rule and manually.

Note

This is an independent bugfix, extracted from the user-permissions content-scope stack (#6114#6115#6116) so it can be reviewed and merged on its own. It does not depend on that stack.

🤖 Generated with Claude Code


Generated by Claude Code

A permission that is granted both by rule and manually was counted twice, so
the permissions count shown for a user in the admin could exceed the number of
available permissions. Count distinct permissions instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JVwZJtKmfrQq2VZmPAB76j
@fraxachun fraxachun closed this Aug 14, 2026
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