From 47f2c7ff526652d5bae96031c32fe787144a4dda Mon Sep 17 00:00:00 2001 From: yokowu <18836617@qq.com> Date: Mon, 18 Aug 2025 18:33:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AF=B9=E8=AF=9D,=E8=A1=A5=E5=85=A8?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E8=B7=B3=E8=BF=87=E6=9D=83=E9=99=90=E9=AA=8C?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/ent/rule/rule.go | 15 +++++++++++---- backend/internal/proxy/repo/proxy.go | 2 ++ backend/pro | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/backend/ent/rule/rule.go b/backend/ent/rule/rule.go index 06e7377..80ef4bd 100644 --- a/backend/ent/rule/rule.go +++ b/backend/ent/rule/rule.go @@ -29,12 +29,18 @@ func SkipPermission(ctx context.Context) context.Context { } type PermissionHook struct { - next ent.Mutator + logger *slog.Logger + next ent.Mutator } // Mutate implements ent.Mutator. func (p PermissionHook) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - slog.With("mType", fmt.Sprintf("%T", m)).With("op", m.Op().String()).With("type", m.Type()).InfoContext(ctx, "[PermissionHook] mutate") + p.logger.With( + "mType", fmt.Sprintf("%T", m), + "op", m.Op().String(), + "type", m.Type(), + ).DebugContext(ctx, "[PermissionHook] mutate") + if v := ctx.Value(skipPermissionCheckKey{}); v != nil { return p.next.Mutate(ctx, m) } @@ -80,9 +86,9 @@ func (p PermissionHook) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, var _ ent.Mutator = PermissionHook{} -func PermissionHookFunc() ent.Hook { +func PermissionHookFunc(logger *slog.Logger) ent.Hook { return func(next ent.Mutator) ent.Mutator { - return PermissionHook{next: next} + return PermissionHook{logger: logger, next: next} } } @@ -108,6 +114,7 @@ func PermissionInterceptor(logger *slog.Logger) ent.Interceptor { } logger = logger.With("type", fmt.Sprintf("%T", q)) + logger.DebugContext(ctx, "[PermissionInterceptor] query") switch qq := q.(type) { case *db.UserGroupQuery: diff --git a/backend/internal/proxy/repo/proxy.go b/backend/internal/proxy/repo/proxy.go index 98799aa..58bf79c 100644 --- a/backend/internal/proxy/repo/proxy.go +++ b/backend/internal/proxy/repo/proxy.go @@ -18,6 +18,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/task" "github.com/chaitin/MonkeyCode/backend/db/taskrecord" "github.com/chaitin/MonkeyCode/backend/domain" + "github.com/chaitin/MonkeyCode/backend/ent/rule" "github.com/chaitin/MonkeyCode/backend/pkg/diff" "github.com/chaitin/MonkeyCode/backend/pkg/entx" ) @@ -77,6 +78,7 @@ func (r *ProxyRepo) ValidateApiKey(ctx context.Context, key string) (*db.ApiKey, } func (r *ProxyRepo) Record(ctx context.Context, record *domain.RecordParam) error { + ctx = rule.SkipPermission(ctx) if record.TaskID == "" { return fmt.Errorf("task_id is empty") } diff --git a/backend/pro b/backend/pro index 6fc2307..8f5db34 160000 --- a/backend/pro +++ b/backend/pro @@ -1 +1 @@ -Subproject commit 6fc2307dbf9348b868375a951baae6c1ede485de +Subproject commit 8f5db34f9b017c6abcce81c5ad7e8b3cb6bbd41e