feat(ECR-019): ContentSafety FilterRule 只读并 Closed
新增 filter_rules、admin.content_safety.read、列表/详情/试匹配 API 与 admin-h5「安全」页;禁审核写/UGC/真支付。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
"github.com/yuxingu/digital-psychology/apps/api/internal/repository"
|
||||
)
|
||||
|
||||
var ErrFilterRuleNotFound = errString("filter rule not found")
|
||||
|
||||
// ListFilterRules returns FilterRule catalog.
|
||||
func (s *Service) ListFilterRules(ctx context.Context) ([]repository.FilterRuleRow, error) {
|
||||
items, err := s.Repo.ListFilterRules(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if items == nil {
|
||||
items = []repository.FilterRuleRow{}
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
// GetFilterRule loads one rule.
|
||||
func (s *Service) GetFilterRule(ctx context.Context, id uuid.UUID) (*repository.FilterRuleRow, error) {
|
||||
row, err := s.Repo.GetFilterRule(ctx, id)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrFilterRuleNotFound
|
||||
}
|
||||
return row, err
|
||||
}
|
||||
|
||||
// EvaluateContent runs read-only filter preview.
|
||||
func (s *Service) EvaluateContent(ctx context.Context, text string) ([]repository.FilterMatch, error) {
|
||||
return s.Repo.EvaluateFilterRules(ctx, text)
|
||||
}
|
||||
@@ -25,6 +25,7 @@ const (
|
||||
PermMembershipCodesRead = "admin.membership.codes.read"
|
||||
PermMembershipCodesWrite = "admin.membership.codes.write"
|
||||
PermAskRead = "admin.ask.read"
|
||||
PermContentSafetyRead = "admin.content_safety.read"
|
||||
)
|
||||
|
||||
var knownPermissions = map[string]struct{}{
|
||||
@@ -33,7 +34,7 @@ var knownPermissions = map[string]struct{}{
|
||||
PermContentWrite: {}, PermRolesRead: {}, PermRolesWrite: {},
|
||||
PermUsersStatusWrite: {}, PermMembershipPlansRead: {}, PermMembershipPlansWrite: {},
|
||||
PermMembershipCodesRead: {}, PermMembershipCodesWrite: {},
|
||||
PermAskRead: {},
|
||||
PermAskRead: {}, PermContentSafetyRead: {},
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
Reference in New Issue
Block a user