MM-32396 Create endpoint for listing all the roles (#16988)
* Create an endpoint for listing roles * Add function to client model * Create tests for listing roles endpoint * Apply code review suggestions * Restore GetAllRoles app method * Use AppContext instead of App * Minor fix * Refactor according to new changes Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
25257d6ef6
Коммит
e70c5a605a
22
api4/role.go
22
api4/role.go
@@ -19,12 +19,34 @@ var notAllowedPermissions = []string{
|
||||
}
|
||||
|
||||
func (api *API) InitRole() {
|
||||
api.BaseRoutes.Roles.Handle("", api.APISessionRequired(getAllRoles)).Methods("GET")
|
||||
api.BaseRoutes.Roles.Handle("/{role_id:[A-Za-z0-9]+}", api.APISessionRequiredTrustRequester(getRole)).Methods("GET")
|
||||
api.BaseRoutes.Roles.Handle("/name/{role_name:[a-z0-9_]+}", api.APISessionRequiredTrustRequester(getRoleByName)).Methods("GET")
|
||||
api.BaseRoutes.Roles.Handle("/names", api.APISessionRequiredTrustRequester(getRolesByNames)).Methods("POST")
|
||||
api.BaseRoutes.Roles.Handle("/{role_id:[A-Za-z0-9]+}/patch", api.APISessionRequired(patchRole)).Methods("PUT")
|
||||
}
|
||||
|
||||
func getAllRoles(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionManageSystem) {
|
||||
c.SetPermissionError(model.PermissionManageSystem)
|
||||
return
|
||||
}
|
||||
|
||||
roles, err := c.App.GetAllRoles()
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(roles)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getAllRoles", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
func getRole(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.RequireRoleId()
|
||||
if c.Err != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user