mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-02-03 07:13:26 +08:00
fix: 对话,补全记录跳过权限验证
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Submodule backend/pro updated: 6fc2307dbf...8f5db34f9b
Reference in New Issue
Block a user