From d7b1913bc3591fb9d61ba7ac5dd44443fd89c450 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 30 Oct 2024 23:28:26 +0800 Subject: [PATCH] :bug: Fix check perm panic --- .idea/workspace.xml | 91 +++++++++------------------ pkg/internal/http/api/accounts_api.go | 2 +- pkg/internal/http/exts/auth.go | 2 +- 3 files changed, 30 insertions(+), 65 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6e686be..9026300 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,45 +4,10 @@ - @@ -214,7 +178,8 @@ - true diff --git a/pkg/internal/http/api/accounts_api.go b/pkg/internal/http/api/accounts_api.go index 6298480..5c15d37 100644 --- a/pkg/internal/http/api/accounts_api.go +++ b/pkg/internal/http/api/accounts_api.go @@ -60,7 +60,7 @@ func getUserinfo(c *fiber.Ctx) error { First(&data).Error; err != nil { return fiber.NewError(fiber.StatusInternalServerError, err.Error()) } else { - data.PermNodes = c.Locals("permissions").(map[string]any) + data.PermNodes = user.PermNodes } var resp fiber.Map diff --git a/pkg/internal/http/exts/auth.go b/pkg/internal/http/exts/auth.go index b4d911f..a2b0e15 100644 --- a/pkg/internal/http/exts/auth.go +++ b/pkg/internal/http/exts/auth.go @@ -19,7 +19,7 @@ func EnsureGrantedPerm(c *fiber.Ctx, key string, val any) error { if err := EnsureAuthenticated(c); err != nil { return err } - perms := c.Locals("permissions").(map[string]any) + perms := c.Locals("user").(*sec.UserInfo).PermNodes if !services.HasPermNode(perms, key, val) { return fiber.NewError(fiber.StatusForbidden, fmt.Sprintf("missing permission: %s", key)) }