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

Limit the number of users on an instance #30236

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

techknowlogick
Copy link
Member

Fix #29975

WIP as it should have tests & am unsure if there is enough documentation

@techknowlogick techknowlogick added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Apr 1, 2024
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 1, 2024
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 1, 2024
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/docs labels Apr 1, 2024
custom/conf/app.example.ini Outdated Show resolved Hide resolved
docs/content/administration/config-cheat-sheet.en-us.md Outdated Show resolved Hide resolved
models/user/user.go Outdated Show resolved Hide resolved
@@ -729,6 +734,15 @@ func createUser(ctx context.Context, u *User, createdByAdmin bool, overwriteDefa
return committer.Commit()
}

func HitCreationLimit(ctx context.Context) bool {
Copy link
Member

Choose a reason for hiding this comment

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

NoMoreUsersAllowed?

@delvh delvh changed the title Limit the number of users on an instace Limit the number of users on an instance Apr 1, 2024
Co-authored-by: delvh <dev.lh@web.de>
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 2, 2024
@delvh
Copy link
Member

delvh commented Apr 2, 2024

I am unsure if there is enough documentation

I mean, what more do you want to document about it?
Given our remaining documentation, it is already covered to a satisfactory extent.
You can of course add more documentation, but I don't see where or what.

But the tests would be nice, to ensure it doesn't just break at one point.

func HitCreationLimit(ctx context.Context) bool {
// don't bother calling DB if limit not set
if setting.Service.MaxUserCreationLimit < 0 ||
int64(setting.Service.MaxUserCreationLimit) < CountUsers(ctx, &CountUserFilter{}) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it be a concurrent limit? Deactivated users should not be counted.

Copy link
Member

Choose a reason for hiding this comment

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

However, doing this means we also need to keep the user count in mind when re-activating a user, and the CountUsers must ignore deactivated users.

Copy link
Member

Choose a reason for hiding this comment

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

I think this feature should be similar to "you have 10 user licenses". Usually if someone leaves, you just deactivate the account and get 1 license back. This would not be possible with the current code.

func HitCreationLimit(ctx context.Context) bool {
// don't bother calling DB if limit not set
if setting.Service.MaxUserCreationLimit < 0 ||
int64(setting.Service.MaxUserCreationLimit) < CountUsers(ctx, &CountUserFilter{}) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this feature should be similar to "you have 10 user licenses". Usually if someone leaves, you just deactivate the account and get 1 license back. This would not be possible with the current code.

@@ -717,6 +717,13 @@ func ActivatePost(ctx *context.Context) {
return
}

// Check the number of users already in the system, and if there are too many forbid any new ones.
if user_model.HitCreationLimit(ctx) {
Copy link
Member

Choose a reason for hiding this comment

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

If the user is created auto-active there is no limit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/docs modifies/go Pull requests that update Go code size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Limit the Number of Users a Gitea Deployment Can Have
4 participants