entc/gen: adding DenyMutationOperation privacy rule helper (#441)

Signed-off-by: Alex Snast <alexsn@fb.com>
This commit is contained in:
Alex Snast
2020-04-20 14:28:00 +03:00
committed by GitHub
parent 88ae8eded2
commit 0ef1b2dcff
25 changed files with 242 additions and 2 deletions

View File

@@ -148,6 +148,16 @@ type fixedDecisionRule struct{ err error }
func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err }
func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err }
// DenyMutationOperation returns a rule denying specifies mutation operation.
func DenyMutationOperation(op ent.Op) MutationRule {
return MutationRuleFunc(func(_ context.Context, m ent.Mutation) error {
if m.Op().Is(op) {
return Denyf("ent/privacy: operation %s is not allowed", m.Op())
}
return Skip
})
}
// The CarQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type CarQueryRuleFunc func(context.Context, *ent.CarQuery) error