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

Function CreateRoleV2

api/handler/v2/role.go:64–83  ·  view source on GitHub ↗

@Id CreateRoleV2 @Description create Role. @Tags Role @Accept application/json @Security ApiKeyAuth @Param Role body models.CreateRoleReqV2 true "Role info" @Success 200 {object} models.CreateRoleRespV2 @Router /v2/role/create [post]

(c echo.Context)

Source from the content-addressed store, hash-verified

62// @Success 200 {object} models.CreateRoleRespV2
63// @Router /v2/role/create [post]
64func CreateRoleV2(c echo.Context) error {
65 logger := handler.NewLogger().Named("CreateRoleV2")
66 reqParam := new(models.CreateRoleReqV2)
67 if err := handler.BindAndValidate(logger, c, reqParam); err != nil {
68 return c.JSON(http.StatusInternalServerError, models.BuildBaseResp(err))
69 }
70 tenant, _ := GetUserName(c)
71 if !roleAccess(tenant, reqParam.Tenant) {
72 return c.JSON(http.StatusForbidden, models.BuildBaseResp(fmt.Errorf("current user cannot create tenant [ %v ] role [ %v ]", reqParam.Tenant, reqParam.Name)))
73 }
74 err := UpdateRoleInfo(logger, &common.Role{
75 Tenant: reqParam.Tenant,
76 Name: reqParam.Name,
77 ObjectUsers: reqParam.OperationUsers,
78 ObjectType: reqParam.OperationObjectType,
79 Authority: reqParam.Authority,
80 }, true)
81
82 return c.JSON(http.StatusOK, models.CreateRoleRespV2{BaseResp: models.BuildBaseResp(err)})
83}
84
85// @Id UpdateRoleV2
86// @Description update Role info.

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