mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-14 15:16:49 +02:00
fix: allow admins to always rename users (#8715)
Do not apply the rename restriction of non-local users if the doer is an admin (changes via the admin interface). This is a conscious choice and the admin knows better if they make such changes.
Regression of c59a057297
Resolves forgejo/forgejo#3657
<!--start release-notes-assistant-->
## Release notes
<!--URL:https://codeberg.org/forgejo/forgejo-->
- Bug fixes
- [PR](https://codeberg.org/forgejo/forgejo/pulls/8715): <!--number 8715 --><!--line 0 --><!--description YWxsb3cgYWRtaW5zIHRvIGFsd2F5cyByZW5hbWUgdXNlcnM=-->allow admins to always rename users<!--description-->
<!--end release-notes-assistant-->
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8715
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
parent
e2dbbbfbc6
commit
b2469c2a9c
2 changed files with 9 additions and 2 deletions
|
@ -47,7 +47,8 @@ func renameUser(ctx context.Context, u *user_model.User, newUserName string, doe
|
||||||
}
|
}
|
||||||
|
|
||||||
// Non-local users are not allowed to change their username.
|
// Non-local users are not allowed to change their username.
|
||||||
if !u.IsOrganization() && !u.IsLocal() {
|
// If the doer is an admin, then allow the rename - they know better.
|
||||||
|
if !doerIsAdmin && !u.IsOrganization() && !u.IsLocal() {
|
||||||
return user_model.ErrUserIsNotLocal{
|
return user_model.ErrUserIsNotLocal{
|
||||||
UID: u.ID,
|
UID: u.ID,
|
||||||
Name: u.Name,
|
Name: u.Name,
|
||||||
|
|
|
@ -145,10 +145,16 @@ func TestRenameUser(t *testing.T) {
|
||||||
|
|
||||||
t.Run("Non-Local", func(t *testing.T) {
|
t.Run("Non-Local", func(t *testing.T) {
|
||||||
u := &user_model.User{
|
u := &user_model.User{
|
||||||
|
ID: 2,
|
||||||
|
Name: "old-name",
|
||||||
Type: user_model.UserTypeIndividual,
|
Type: user_model.UserTypeIndividual,
|
||||||
LoginType: auth.OAuth2,
|
LoginType: auth.OAuth2,
|
||||||
}
|
}
|
||||||
require.ErrorIs(t, RenameUser(db.DefaultContext, u, "user_rename"), user_model.ErrUserIsNotLocal{})
|
require.ErrorIs(t, RenameUser(db.DefaultContext, u, "user_rename2"), user_model.ErrUserIsNotLocal{UID: 2, Name: "old-name"})
|
||||||
|
|
||||||
|
t.Run("Admin", func(t *testing.T) {
|
||||||
|
require.NoError(t, AdminRenameUser(t.Context(), u, "user_rename2"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Same username", func(t *testing.T) {
|
t.Run("Same username", func(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue