MCPcopy Create free account
hub / github.com/actiontech/dtle / UpdateRoleV2

Function UpdateRoleV2

api/handler/v2/role.go:93–115  ·  view source on GitHub ↗

@Id UpdateRoleV2 @Description update Role info. @Tags Role @Accept application/json @Security ApiKeyAuth @Param Role body models.UpdateRoleReqV2 true "Role info" @Success 200 {object} models.UpdateRoleRespV2 @Router /v2/role/update [post]

(c echo.Context)

Source from the content-addressed store, hash-verified

91// @Success 200 {object} models.UpdateRoleRespV2
92// @Router /v2/role/update [post]
93func UpdateRoleV2(c echo.Context) error {
94 logger := handler.NewLogger().Named("UpdateRoleV2")
95 reqParam := new(models.UpdateRoleReqV2)
96 if err := handler.BindAndValidate(logger, c, reqParam); err != nil {
97 return c.JSON(http.StatusInternalServerError, models.BuildBaseResp(err))
98 }
99 if reqParam.Name == common.DefaultRole {
100 return c.JSON(http.StatusForbidden, models.BuildBaseResp(fmt.Errorf("admin role does not support modification")))
101 }
102 tenant, _ := GetUserName(c)
103 if !roleAccess(tenant, reqParam.Tenant) {
104 return c.JSON(http.StatusForbidden, models.BuildBaseResp(fmt.Errorf("current user cannot update tenant [ %v ] role [ %v ]", reqParam.Tenant, reqParam.Name)))
105 }
106 err := UpdateRoleInfo(logger, &common.Role{
107 Tenant: reqParam.Tenant,
108 Name: reqParam.Name,
109 ObjectUsers: reqParam.OperationUsers,
110 ObjectType: reqParam.OperationObjectType,
111 Authority: reqParam.Authority,
112 }, false)
113
114 return c.JSON(http.StatusOK, models.UpdateRoleRespV2{BaseResp: models.BuildBaseResp(err)})
115}
116
117func UpdateRoleInfo(logger g.LoggerType, role *common.Role, create bool) error {
118 storeManager, err := common.NewStoreManager([]string{handler.ConsulAddr}, logger)

Callers

nothing calls this directly

Calls 6

NewLoggerFunction · 0.92
BindAndValidateFunction · 0.92
BuildBaseRespFunction · 0.92
GetUserNameFunction · 0.85
roleAccessFunction · 0.85
UpdateRoleInfoFunction · 0.85

Tested by

no test coverage detected