You've already forked agentic-coding-workflow
完善 MCP 工具
This commit is contained in:
@@ -54,7 +54,7 @@ func (s *templateService) Create(ctx context.Context, userID uuid.UUID, name, co
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (s *templateService) Update(ctx context.Context, userID, id uuid.UUID, name, content string) error {
|
||||
func (s *templateService) Update(ctx context.Context, userID uuid.UUID, isAdmin bool, id uuid.UUID, name, content string) error {
|
||||
t, err := s.repo.GetPromptTemplate(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -62,8 +62,8 @@ func (s *templateService) Update(ctx context.Context, userID, id uuid.UUID, name
|
||||
if t == nil {
|
||||
return errs.New(errs.CodeChatTemplateNotFound, "template not found")
|
||||
}
|
||||
if t.Scope == TemplateScopeUser && (t.OwnerID == nil || *t.OwnerID != userID) {
|
||||
return errs.New(errs.CodeForbidden, "not template owner")
|
||||
if err := checkTemplateWriteAccess(t, userID, isAdmin); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.repo.UpdatePromptTemplate(ctx, id, name, content); err != nil {
|
||||
return err
|
||||
@@ -77,7 +77,7 @@ func (s *templateService) Update(ctx context.Context, userID, id uuid.UUID, name
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *templateService) Delete(ctx context.Context, userID, id uuid.UUID) error {
|
||||
func (s *templateService) Delete(ctx context.Context, userID uuid.UUID, isAdmin bool, id uuid.UUID) error {
|
||||
t, err := s.repo.GetPromptTemplate(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -85,8 +85,8 @@ func (s *templateService) Delete(ctx context.Context, userID, id uuid.UUID) erro
|
||||
if t == nil {
|
||||
return errs.New(errs.CodeChatTemplateNotFound, "template not found")
|
||||
}
|
||||
if t.Scope == TemplateScopeUser && (t.OwnerID == nil || *t.OwnerID != userID) {
|
||||
return errs.New(errs.CodeForbidden, "not template owner")
|
||||
if err := checkTemplateWriteAccess(t, userID, isAdmin); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.repo.DeletePromptTemplate(ctx, id); err != nil {
|
||||
return err
|
||||
@@ -100,6 +100,18 @@ func (s *templateService) Delete(ctx context.Context, userID, id uuid.UUID) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkTemplateWriteAccess 是 Update/Delete 共用的写权限判定:
|
||||
// user 模板仅 owner;system 模板仅 admin。
|
||||
func checkTemplateWriteAccess(t *PromptTemplate, userID uuid.UUID, isAdmin bool) error {
|
||||
if t.Scope == TemplateScopeUser && (t.OwnerID == nil || *t.OwnerID != userID) {
|
||||
return errs.New(errs.CodeForbidden, "not template owner")
|
||||
}
|
||||
if t.Scope == TemplateScopeSystem && !isAdmin {
|
||||
return errs.New(errs.CodeForbidden, "admin only: system-scoped template")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *templateService) tryAudit(ctx context.Context, e audit.Entry) {
|
||||
if err := s.auditor.Record(ctx, e); err != nil {
|
||||
s.log.Warn("audit record failed", "action", e.Action, "err", err)
|
||||
|
||||
Reference in New Issue
Block a user