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

File diff suppressed because one or more lines are too long

View File

@@ -140,6 +140,16 @@ type fixedDecisionRule struct { err error }
func (f fixedDecisionRule) EvalQuery(context.Context, {{ $pkg }}.Query) error { return f.err }
func (f fixedDecisionRule) EvalMutation(context.Context, {{ $pkg }}.Mutation) error { return f.err }
// DenyMutationOperation returns a rule denying specifies mutation operation.
func DenyMutationOperation(op {{ $pkg }}.Op) MutationRule {
return MutationRuleFunc(func(_ context.Context, m {{ $pkg }}.Mutation) error {
if m.Op().Is(op) {
return Denyf("ent/privacy: operation %s is not allowed", m.Op())
}
return Skip
})
}
{{- range $n := $.Nodes }}
{{ $name := print $n.Name "QueryRuleFunc" }}
{{ $type := printf "*%s.%s" $pkg $n.QueryName }}

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 UserQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error

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 BlobQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type BlobQueryRuleFunc func(context.Context, *ent.BlobQuery) error

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 CardQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type CardQueryRuleFunc func(context.Context, *ent.CardQuery) error

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 CardQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type CardQueryRuleFunc func(context.Context, *ent.CardQuery) error

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 CardQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type CardQueryRuleFunc func(context.Context, *ent.CardQuery) error

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 UserQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error

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 UserQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error

View File

@@ -148,6 +148,16 @@ type fixedDecisionRule struct{ err error }
func (f fixedDecisionRule) EvalQuery(context.Context, entv1.Query) error { return f.err }
func (f fixedDecisionRule) EvalMutation(context.Context, entv1.Mutation) error { return f.err }
// DenyMutationOperation returns a rule denying specifies mutation operation.
func DenyMutationOperation(op entv1.Op) MutationRule {
return MutationRuleFunc(func(_ context.Context, m entv1.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, *entv1.CarQuery) error

View File

@@ -148,6 +148,16 @@ type fixedDecisionRule struct{ err error }
func (f fixedDecisionRule) EvalQuery(context.Context, entv2.Query) error { return f.err }
func (f fixedDecisionRule) EvalMutation(context.Context, entv2.Mutation) error { return f.err }
// DenyMutationOperation returns a rule denying specifies mutation operation.
func DenyMutationOperation(op entv2.Op) MutationRule {
return MutationRuleFunc(func(_ context.Context, m entv2.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, *entv2.CarQuery) error

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 GalaxyQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type GalaxyQueryRuleFunc func(context.Context, *ent.GalaxyQuery) error

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 GroupQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type GroupQueryRuleFunc func(context.Context, *ent.GroupQuery) error

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 CityQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type CityQueryRuleFunc func(context.Context, *ent.CityQuery) error

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 UserQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error

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 GroupQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type GroupQueryRuleFunc func(context.Context, *ent.GroupQuery) error

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 UserQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error

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 UserQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error

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 PetQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type PetQueryRuleFunc func(context.Context, *ent.PetQuery) error

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 NodeQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type NodeQueryRuleFunc func(context.Context, *ent.NodeQuery) error

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 CardQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type CardQueryRuleFunc func(context.Context, *ent.CardQuery) error

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 UserQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error

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 NodeQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type NodeQueryRuleFunc func(context.Context, *ent.NodeQuery) error

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

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 GroupQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type GroupQueryRuleFunc func(context.Context, *ent.GroupQuery) error