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