diff options
author | 6543 <6543@obermui.de> | 2021-06-27 20:47:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-27 19:47:35 +0100 |
commit | 0b27b93728fd3cf2ecc82ac6a2b5859270543ef2 (patch) | |
tree | adbbc5eaec25e5e2c88068d45e3fa75435431dfe /models/user_test.go | |
parent | 2a98ec1c3cd2f8396f3b5148fc8c796802f9c236 (diff) | |
download | gitea-0b27b93728fd3cf2ecc82ac6a2b5859270543ef2.tar.gz gitea-0b27b93728fd3cf2ecc82ac6a2b5859270543ef2.zip |
Make allowed Visiblity modes configurable for Users (#16271)
Now that #16069 is merged, some sites may wish to enforce that users are all public, limited or private, and/or disallow users from becoming private.
This PR adds functionality and settings to constrain a user's ability to change their visibility.
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/user_test.go')
-rw-r--r-- | models/user_test.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/models/user_test.go b/models/user_test.go index 39a1b3c989..34c465c586 100644 --- a/models/user_test.go +++ b/models/user_test.go @@ -11,6 +11,7 @@ import ( "testing" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" "github.com/stretchr/testify/assert" @@ -189,6 +190,7 @@ func TestDeleteUser(t *testing.T) { func TestEmailNotificationPreferences(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) + for _, test := range []struct { expected string userID int64 @@ -467,3 +469,23 @@ ssh-dss AAAAB3NzaC1kc3MAAACBAOChCC7lf6Uo9n7BmZ6M8St19PZf4Tn59NriyboW2x/DZuYAz3ib } } } + +func TestUpdateUser(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + + user.KeepActivityPrivate = true + assert.NoError(t, UpdateUser(user)) + user = AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + assert.True(t, user.KeepActivityPrivate) + + setting.Service.AllowedUserVisibilityModesSlice = []bool{true, false, false} + user.KeepActivityPrivate = false + user.Visibility = structs.VisibleTypePrivate + assert.Error(t, UpdateUser(user)) + user = AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + assert.True(t, user.KeepActivityPrivate) + + user.Email = "no mail@mail.org" + assert.Error(t, UpdateUser(user)) +} |