mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* Implementing structured logging
* Changes to en.json to allow refactor to run.
* Fixing global logger
* Structured logger initalization.
* Add caller.
* Do some log redirection.
* Auto refactor
* Cleaning up l4g reference and removing dependancy.
* Removing junk.
* Copyright headers.
* Fixing tests
* Revert "Changes to en.json to allow refactor to run."
This reverts commit fd8249e99b.
* Fixing some auto refactor strangeness and typo.
* Making keys more human readable.
93 lines
2.1 KiB
Go
93 lines
2.1 KiB
Go
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
package app
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
"net/http"
|
|
|
|
"github.com/mattermost/mattermost-server/model"
|
|
)
|
|
|
|
func (a *App) GetRole(id string) (*model.Role, *model.AppError) {
|
|
if result := <-a.Srv.Store.Role().Get(id); result.Err != nil {
|
|
return nil, result.Err
|
|
} else {
|
|
return result.Data.(*model.Role), nil
|
|
}
|
|
}
|
|
|
|
func (a *App) GetRoleByName(name string) (*model.Role, *model.AppError) {
|
|
if result := <-a.Srv.Store.Role().GetByName(name); result.Err != nil {
|
|
return nil, result.Err
|
|
} else {
|
|
return result.Data.(*model.Role), nil
|
|
}
|
|
}
|
|
|
|
func (a *App) GetRolesByNames(names []string) ([]*model.Role, *model.AppError) {
|
|
if result := <-a.Srv.Store.Role().GetByNames(names); result.Err != nil {
|
|
return nil, result.Err
|
|
} else {
|
|
return result.Data.([]*model.Role), nil
|
|
}
|
|
}
|
|
|
|
func (a *App) PatchRole(role *model.Role, patch *model.RolePatch) (*model.Role, *model.AppError) {
|
|
// If patch is a no-op then short-circuit the store.
|
|
if patch.Permissions != nil && reflect.DeepEqual(*patch.Permissions, role.Permissions) {
|
|
return role, nil
|
|
}
|
|
|
|
role.Patch(patch)
|
|
role, err := a.UpdateRole(role)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return role, err
|
|
}
|
|
|
|
func (a *App) UpdateRole(role *model.Role) (*model.Role, *model.AppError) {
|
|
if result := <-a.Srv.Store.Role().Save(role); result.Err != nil {
|
|
return nil, result.Err
|
|
} else {
|
|
a.sendUpdatedRoleEvent(role)
|
|
|
|
return role, nil
|
|
}
|
|
}
|
|
|
|
func (a *App) CheckRolesExist(roleNames []string) *model.AppError {
|
|
roles, err := a.GetRolesByNames(roleNames)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, name := range roleNames {
|
|
nameFound := false
|
|
for _, role := range roles {
|
|
if name == role.Name {
|
|
nameFound = true
|
|
break
|
|
}
|
|
}
|
|
if !nameFound {
|
|
return model.NewAppError("CheckRolesExist", "app.role.check_roles_exist.role_not_found", nil, "role="+name, http.StatusBadRequest)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (a *App) sendUpdatedRoleEvent(role *model.Role) {
|
|
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_ROLE_UPDATED, "", "", "", nil)
|
|
message.Add("role", role.ToJson())
|
|
|
|
a.Go(func() {
|
|
a.Publish(message)
|
|
})
|
|
}
|