[BUG] First user created through reverse proxy should be admin

- Currently users created through the reverse proxy aren't created
trough the normal route of `createAndHandleCreatedUser` as this does a
lot of other routines which aren't necessary for the reverse proxy auth,
however one routine is important to have: the first created user should
be an admin. This patch adds that code
- Adds unit test.
- Resolves #4437
This commit is contained in:
Gusted 2024-07-17 15:54:57 +02:00
parent 3b8ac4388a
commit 0692cc2cc1
No known key found for this signature in database
GPG key ID: FD821B732837125F
2 changed files with 72 additions and 0 deletions

View file

@ -164,6 +164,11 @@ func (r *ReverseProxy) newUser(req *http.Request) *user_model.User {
IsActive: optional.Some(true),
}
// The first user created should be an admin.
if user_model.CountUsers(req.Context(), nil) == 0 {
user.IsAdmin = true
}
if err := user_model.CreateUser(req.Context(), user, &overwriteDefault); err != nil {
// FIXME: should I create a system notice?
log.Error("CreateUser: %v", err)