Files
Harshil Sharma 87d983cc7f Sysadmin manage user settings (#27583)
* Opened modal from system console

* WIP

* WIP

* WIP

* Handled saving user

* Successfully updated user based settings

* WIP

* WIP

* All settings are updating well

* Fixed modal style

* Added admin mode indicators in modal

* Added confirmation dialog

* Lint fixes

* Added license check

* Added permission check

* Fixed i18n file order

* type fix

* Updated snapshots

* Handled performance debugging setting

* Some styling tweaks

* Fixed text alighnment

* Updated license required from professional to enterprise

* Handled long user names

* review fixes

* Added manage setting option in user list page context menu

* Added loader

* Minor reordering

* Removed confirm modal

* Updated snapshots for removed modal

* Added some tests

* Lint fix

* Used new selector in user detail page

* Used new selector in user list page

* Updated tests

* Fixed an incorrect default test
2024-07-12 10:22:04 +05:30

70 строки
1.7 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package users
import (
"strings"
"github.com/mattermost/mattermost/server/public/model"
)
// CheckUserDomain checks that a user's email domain matches a list of space-delimited domains as a string.
func CheckUserDomain(user *model.User, domains string) bool {
return CheckEmailDomain(user.Email, domains)
}
// CheckEmailDomain checks that an email domain matches a list of space-delimited domains as a string.
func CheckEmailDomain(email string, domains string) bool {
if domains == "" {
return true
}
domainArray := strings.Fields(strings.TrimSpace(strings.ToLower(strings.Replace(strings.Replace(domains, "@", " ", -1), ",", " ", -1))))
for _, d := range domainArray {
if strings.HasSuffix(strings.ToLower(email), "@"+d) {
return true
}
}
return false
}
func (us *UserService) sanitizeProfiles(users []*model.User, asAdmin bool) []*model.User {
for _, u := range users {
us.SanitizeProfile(u, asAdmin)
}
return users
}
func (us *UserService) SanitizeProfile(user *model.User, asAdmin bool) {
options := us.GetSanitizeOptions(asAdmin)
user.SanitizeProfile(options, asAdmin)
}
func (us *UserService) GetSanitizeOptions(asAdmin bool) map[string]bool {
options := us.config().GetSanitizeOptions()
if asAdmin {
options["email"] = true
options["fullname"] = true
options["authservice"] = true
}
return options
}
// IsUsernameTaken checks if the username is already used by another user. Return false if the username is invalid.
func (us *UserService) IsUsernameTaken(name string) bool {
if !model.IsValidUsername(name) {
return false
}
if _, err := us.store.GetByUsername(name); err != nil {
return false
}
return true
}