Skip to content

Commit

Permalink
return an error when renaming users from OIDC
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Jan 31, 2025
1 parent e172c29 commit efdf42c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions hscontrol/db/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func (hsdb *HSDatabase) RenameUser(uid types.UserID, newName string) error {
})
}

var ErrCannotChangeOIDCUser = errors.New("cannot edit OIDC user")

// RenameUser renames a User. Returns error if the User does
// not exist or if another User exists with the new name.
func RenameUser(tx *gorm.DB, uid types.UserID, newName string) error {
Expand All @@ -94,6 +96,10 @@ func RenameUser(tx *gorm.DB, uid types.UserID, newName string) error {
return err
}

if oldUser.Provider == util.RegisterMethodOIDC {
return ErrCannotChangeOIDCUser
}

oldUser.Name = newName

if err := tx.Save(&oldUser).Error; err != nil {
Expand Down

0 comments on commit efdf42c

Please sign in to comment.