add rename function for roles
This commit is contained in:
@@ -488,3 +488,30 @@ func HandleHubSelfRoleRemove(response http.ResponseWriter, request *http.Request
|
||||
hubUser.Roles.Remove(roleId)
|
||||
response.WriteHeader(http.StatusAccepted)
|
||||
}
|
||||
|
||||
func PermissionSetRoleName(response http.ResponseWriter, request *http.Request) {
|
||||
_, hub, _, ok := hubPermissionContext(response, request, normal, types.PermissionSetRoleName)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
roleId, err := convertions.StringToUint8(request.FormValue("roleid"))
|
||||
if err != nil {
|
||||
http.Error(response, "bad roleid", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
newName := request.FormValue("newname")
|
||||
if newName == "" {
|
||||
http.Error(response, "name empty", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
hub.Mu.Lock()
|
||||
role := hub.Roles[roleId]
|
||||
if role == nil {
|
||||
http.Error(response, "no such role", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
role.Name = newName
|
||||
hub.Mu.Unlock()
|
||||
response.WriteHeader(http.StatusAccepted)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user