mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
prevent users from changing email addresses to restricted domains (#7765)
This commit is contained in:
committed by
Christopher Speller
parent
59fe809909
commit
71dd21ef3d
11
app/user.go
11
app/user.go
@@ -984,6 +984,17 @@ func (a *App) sendUpdatedUserEvent(user model.User, asAdmin bool) {
|
||||
}
|
||||
|
||||
func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User, *model.AppError) {
|
||||
if !CheckUserDomain(user, a.Config().TeamSettings.RestrictCreationToDomains) {
|
||||
result := <-a.Srv.Store.User().Get(user.Id)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
prev := result.Data.(*model.User)
|
||||
if !prev.IsLDAPUser() && !prev.IsSAMLUser() && user.Email != prev.Email {
|
||||
return nil, model.NewAppError("UpdateUser", "api.user.create_user.accepted_domain.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.User().Update(user, false); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
|
||||
@@ -137,6 +137,25 @@ func TestCreateProfileImage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateUserToRestrictedDomain(t *testing.T) {
|
||||
th := Setup()
|
||||
defer th.TearDown()
|
||||
|
||||
user := th.CreateUser()
|
||||
defer th.App.PermanentDeleteUser(user)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.TeamSettings.RestrictCreationToDomains = "foo.com"
|
||||
})
|
||||
|
||||
_, err := th.App.UpdateUser(user, false)
|
||||
assert.True(t, err == nil)
|
||||
|
||||
user.Email = "asdf@ghjk.l"
|
||||
_, err = th.App.UpdateUser(user, false)
|
||||
assert.False(t, err == nil)
|
||||
}
|
||||
|
||||
func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
th := Setup()
|
||||
defer th.TearDown()
|
||||
|
||||
Reference in New Issue
Block a user