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

Function ListActionV2

api/handler/v2/user.go:362–389  ·  view source on GitHub ↗

@Id ListActionV2 @Description list user action. @Tags user @Security ApiKeyAuth @Success 200 {object} models.ListActionRespV2 @Router /v2/user/list_action [get]

(c echo.Context)

Source from the content-addressed store, hash-verified

360// @Success 200 {object} models.ListActionRespV2
361// @Router /v2/user/list_action [get]
362func ListActionV2(c echo.Context) error {
363 logger := handler.NewLogger().Named("ListActionV2")
364
365 user, err := getCurrentUser(c)
366 if err != nil {
367 return c.JSON(http.StatusInternalServerError, models.BuildBaseResp(err))
368 }
369 storeManager, err := common.NewStoreManager([]string{handler.ConsulAddr}, logger)
370 if err != nil {
371 return c.JSON(http.StatusInternalServerError, models.BuildBaseResp(fmt.Errorf("consul_addr=%v; connect to consul failed: %v", handler.ConsulAddr, err)))
372 }
373 role, exists, err := storeManager.GetRole(user.Tenant, user.Role)
374 if nil != err {
375 return c.JSON(http.StatusInternalServerError, models.BuildBaseResp(fmt.Errorf("consul_addr=%v ; get role failed: %v", handler.ConsulAddr, err)))
376 }
377 if !exists {
378 return c.JSON(http.StatusInternalServerError, models.BuildBaseResp(fmt.Errorf("current user does not belong to any role")))
379 }
380 authority := make([]models.MenuItem, 0)
381 err = json.Unmarshal([]byte(role.Authority), &authority)
382 if nil != err {
383 return c.JSON(http.StatusInternalServerError, models.BuildBaseResp(err))
384 }
385 return c.JSON(http.StatusOK, &models.ListActionRespV2{
386 Authority: authority,
387 BaseResp: models.BuildBaseResp(nil),
388 })
389}
390
391func checkUserAccess(logger g.LoggerType, c echo.Context, operationUser string) (bool, error) {
392 storeManager, err := common.NewStoreManager([]string{handler.ConsulAddr}, logger)

Callers

nothing calls this directly

Calls 6

GetRoleMethod · 0.95
NewLoggerFunction · 0.92
BuildBaseRespFunction · 0.92
NewStoreManagerFunction · 0.92
getCurrentUserFunction · 0.85
UnmarshalMethod · 0.65

Tested by

no test coverage detected