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 user limits #22479

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

Add user limits #22479

wants to merge 18 commits into from

Conversation

licitdev
Copy link
Member

@licitdev licitdev commented May 13, 2024

Scope

What's changed:

  • Added user limits for Admin, App and API accesses
  • Limit can be used to restrict public registration

Potential Risks / Drawbacks

  • Needs further testing for edge cases

Review Notes / Questions

  • Todo Unit Tests

Implements the limits mentioned in issue #21981 for Public Registration #22125

Copy link

changeset-bot bot commented May 13, 2024

⚠️ No Changeset found

Latest commit: bf36721

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@licitdev licitdev marked this pull request as ready for review May 27, 2024 14:52
api/src/services/roles.test.ts Outdated Show resolved Hide resolved
packages/env/src/constants/directus-variables.ts Outdated Show resolved Hide resolved
Comment on lines 230 to 232
'USERS_ACTIVE_LIMIT_ADMIN_ACCESS',
'USERS_ACTIVE_LIMIT_APP_ACCESS',
'USERS_ACTIVE_LIMIT_API_ACCESS_ACCESS',
Copy link
Member

Choose a reason for hiding this comment

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

The order of words here is not very intuitive to me and the use of "active" and "access" feel redundant 🤔 Could we perhaps simplify to something like this: (similar and consistent with EXTENSIONS_LIMIT):

Suggested change
'USERS_ACTIVE_LIMIT_ADMIN_ACCESS',
'USERS_ACTIVE_LIMIT_APP_ACCESS',
'USERS_ACTIVE_LIMIT_API_ACCESS_ACCESS',
'ADMIN_USERS_LIMIT',
'APP_USERS_LIMIT',
'API_USERS_LIMIT',

Copy link
Member Author

Choose a reason for hiding this comment

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

Could we prefix with USERS instead?

Suggested change
'USERS_ACTIVE_LIMIT_ADMIN_ACCESS',
'USERS_ACTIVE_LIMIT_APP_ACCESS',
'USERS_ACTIVE_LIMIT_API_ACCESS_ACCESS',
'USERS_ADMIN_LIMIT',
'USERS_APP_LIMIT',
'USERS_API_LIMIT',

Copy link
Member

@br41nslug br41nslug May 29, 2024

Choose a reason for hiding this comment

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

Sure however i personally do prefer not trying to force such a prefix over readability. Imo it's a limit for "admin users", for which ADMIN_USERS_LIMIT make sense to me, but USERS_ADMIN_LIMIT makes me think twice about whether the "admin" applies to the limit or the user 🤔 In the end thats a tiny detail tho, either way would be an improvement over the longer form i think 😄

api/src/telemetry/utils/get-role-counts-by-roles.ts Outdated Show resolved Hide resolved
api/src/services/users.ts Show resolved Hide resolved
api/src/telemetry/utils/check-increased-user-limits.ts Outdated Show resolved Hide resolved
export async function checkIncreasedUserLimits(db: Knex, increasedUserCounts: UserCount): Promise<void> {
if (!increasedUserCounts.admin && !increasedUserCounts.app && !increasedUserCounts.api) return;

const userCounts = await getUserCount(db);
Copy link
Member

Choose a reason for hiding this comment

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

Im wondering if this is something we should cache for large database? 🤔 will do some testing on a larger DB

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah... Interesting! Are you thinking of caching the limits in Redis? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Im wondering if it would be necessary on large database with tons of users/roles 🤔 Not sure atm

@br41nslug br41nslug requested a review from paescuj May 30, 2024 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🔖 Ready
Development

Successfully merging this pull request may close these issues.

None yet

2 participants