✨ add i18n support
This commit is contained in:
299
common/ent/privacy/privacy.go
Normal file
299
common/ent/privacy/privacy.go
Normal file
@@ -0,0 +1,299 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package privacy
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"schisandra-album-cloud-microservices/common/ent"
|
||||
|
||||
"entgo.io/ent/entql"
|
||||
"entgo.io/ent/privacy"
|
||||
)
|
||||
|
||||
var (
|
||||
// Allow may be returned by rules to indicate that the policy
|
||||
// evaluation should terminate with allow decision.
|
||||
Allow = privacy.Allow
|
||||
|
||||
// Deny may be returned by rules to indicate that the policy
|
||||
// evaluation should terminate with deny decision.
|
||||
Deny = privacy.Deny
|
||||
|
||||
// Skip may be returned by rules to indicate that the policy
|
||||
// evaluation should continue to the next rule.
|
||||
Skip = privacy.Skip
|
||||
)
|
||||
|
||||
// Allowf returns a formatted wrapped Allow decision.
|
||||
func Allowf(format string, a ...any) error {
|
||||
return privacy.Allowf(format, a...)
|
||||
}
|
||||
|
||||
// Denyf returns a formatted wrapped Deny decision.
|
||||
func Denyf(format string, a ...any) error {
|
||||
return privacy.Denyf(format, a...)
|
||||
}
|
||||
|
||||
// Skipf returns a formatted wrapped Skip decision.
|
||||
func Skipf(format string, a ...any) error {
|
||||
return privacy.Skipf(format, a...)
|
||||
}
|
||||
|
||||
// DecisionContext creates a new context from the given parent context with
|
||||
// a policy decision attach to it.
|
||||
func DecisionContext(parent context.Context, decision error) context.Context {
|
||||
return privacy.DecisionContext(parent, decision)
|
||||
}
|
||||
|
||||
// DecisionFromContext retrieves the policy decision from the context.
|
||||
func DecisionFromContext(ctx context.Context) (error, bool) {
|
||||
return privacy.DecisionFromContext(ctx)
|
||||
}
|
||||
|
||||
type (
|
||||
// Policy groups query and mutation policies.
|
||||
Policy = privacy.Policy
|
||||
|
||||
// QueryRule defines the interface deciding whether a
|
||||
// query is allowed and optionally modify it.
|
||||
QueryRule = privacy.QueryRule
|
||||
// QueryPolicy combines multiple query rules into a single policy.
|
||||
QueryPolicy = privacy.QueryPolicy
|
||||
|
||||
// MutationRule defines the interface which decides whether a
|
||||
// mutation is allowed and optionally modifies it.
|
||||
MutationRule = privacy.MutationRule
|
||||
// MutationPolicy combines multiple mutation rules into a single policy.
|
||||
MutationPolicy = privacy.MutationPolicy
|
||||
// MutationRuleFunc type is an adapter which allows the use of
|
||||
// ordinary functions as mutation rules.
|
||||
MutationRuleFunc = privacy.MutationRuleFunc
|
||||
|
||||
// QueryMutationRule is an interface which groups query and mutation rules.
|
||||
QueryMutationRule = privacy.QueryMutationRule
|
||||
)
|
||||
|
||||
// QueryRuleFunc type is an adapter to allow the use of
|
||||
// ordinary functions as query rules.
|
||||
type QueryRuleFunc func(context.Context, ent.Query) error
|
||||
|
||||
// Eval returns f(ctx, q).
|
||||
func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||
return f(ctx, q)
|
||||
}
|
||||
|
||||
// AlwaysAllowRule returns a rule that returns an allow decision.
|
||||
func AlwaysAllowRule() QueryMutationRule {
|
||||
return privacy.AlwaysAllowRule()
|
||||
}
|
||||
|
||||
// AlwaysDenyRule returns a rule that returns a deny decision.
|
||||
func AlwaysDenyRule() QueryMutationRule {
|
||||
return privacy.AlwaysDenyRule()
|
||||
}
|
||||
|
||||
// ContextQueryMutationRule creates a query/mutation rule from a context eval func.
|
||||
func ContextQueryMutationRule(eval func(context.Context) error) QueryMutationRule {
|
||||
return privacy.ContextQueryMutationRule(eval)
|
||||
}
|
||||
|
||||
// OnMutationOperation evaluates the given rule only on a given mutation operation.
|
||||
func OnMutationOperation(rule MutationRule, op ent.Op) MutationRule {
|
||||
return privacy.OnMutationOperation(rule, op)
|
||||
}
|
||||
|
||||
// DenyMutationOperationRule returns a rule denying specified mutation operation.
|
||||
func DenyMutationOperationRule(op ent.Op) MutationRule {
|
||||
rule := MutationRuleFunc(func(_ context.Context, m ent.Mutation) error {
|
||||
return Denyf("ent/privacy: operation %s is not allowed", m.Op())
|
||||
})
|
||||
return OnMutationOperation(rule, op)
|
||||
}
|
||||
|
||||
// The ScaAuthPermissionRuleQueryRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a query rule.
|
||||
type ScaAuthPermissionRuleQueryRuleFunc func(context.Context, *ent.ScaAuthPermissionRuleQuery) error
|
||||
|
||||
// EvalQuery return f(ctx, q).
|
||||
func (f ScaAuthPermissionRuleQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||
if q, ok := q.(*ent.ScaAuthPermissionRuleQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected query type %T, expect *ent.ScaAuthPermissionRuleQuery", q)
|
||||
}
|
||||
|
||||
// The ScaAuthPermissionRuleMutationRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a mutation rule.
|
||||
type ScaAuthPermissionRuleMutationRuleFunc func(context.Context, *ent.ScaAuthPermissionRuleMutation) error
|
||||
|
||||
// EvalMutation calls f(ctx, m).
|
||||
func (f ScaAuthPermissionRuleMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||
if m, ok := m.(*ent.ScaAuthPermissionRuleMutation); ok {
|
||||
return f(ctx, m)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.ScaAuthPermissionRuleMutation", m)
|
||||
}
|
||||
|
||||
// The ScaAuthRoleQueryRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a query rule.
|
||||
type ScaAuthRoleQueryRuleFunc func(context.Context, *ent.ScaAuthRoleQuery) error
|
||||
|
||||
// EvalQuery return f(ctx, q).
|
||||
func (f ScaAuthRoleQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||
if q, ok := q.(*ent.ScaAuthRoleQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected query type %T, expect *ent.ScaAuthRoleQuery", q)
|
||||
}
|
||||
|
||||
// The ScaAuthRoleMutationRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a mutation rule.
|
||||
type ScaAuthRoleMutationRuleFunc func(context.Context, *ent.ScaAuthRoleMutation) error
|
||||
|
||||
// EvalMutation calls f(ctx, m).
|
||||
func (f ScaAuthRoleMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||
if m, ok := m.(*ent.ScaAuthRoleMutation); ok {
|
||||
return f(ctx, m)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.ScaAuthRoleMutation", m)
|
||||
}
|
||||
|
||||
// The ScaAuthUserQueryRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a query rule.
|
||||
type ScaAuthUserQueryRuleFunc func(context.Context, *ent.ScaAuthUserQuery) error
|
||||
|
||||
// EvalQuery return f(ctx, q).
|
||||
func (f ScaAuthUserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||
if q, ok := q.(*ent.ScaAuthUserQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected query type %T, expect *ent.ScaAuthUserQuery", q)
|
||||
}
|
||||
|
||||
// The ScaAuthUserMutationRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a mutation rule.
|
||||
type ScaAuthUserMutationRuleFunc func(context.Context, *ent.ScaAuthUserMutation) error
|
||||
|
||||
// EvalMutation calls f(ctx, m).
|
||||
func (f ScaAuthUserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||
if m, ok := m.(*ent.ScaAuthUserMutation); ok {
|
||||
return f(ctx, m)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.ScaAuthUserMutation", m)
|
||||
}
|
||||
|
||||
// The ScaAuthUserDeviceQueryRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a query rule.
|
||||
type ScaAuthUserDeviceQueryRuleFunc func(context.Context, *ent.ScaAuthUserDeviceQuery) error
|
||||
|
||||
// EvalQuery return f(ctx, q).
|
||||
func (f ScaAuthUserDeviceQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||
if q, ok := q.(*ent.ScaAuthUserDeviceQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected query type %T, expect *ent.ScaAuthUserDeviceQuery", q)
|
||||
}
|
||||
|
||||
// The ScaAuthUserDeviceMutationRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a mutation rule.
|
||||
type ScaAuthUserDeviceMutationRuleFunc func(context.Context, *ent.ScaAuthUserDeviceMutation) error
|
||||
|
||||
// EvalMutation calls f(ctx, m).
|
||||
func (f ScaAuthUserDeviceMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||
if m, ok := m.(*ent.ScaAuthUserDeviceMutation); ok {
|
||||
return f(ctx, m)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.ScaAuthUserDeviceMutation", m)
|
||||
}
|
||||
|
||||
// The ScaAuthUserSocialQueryRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a query rule.
|
||||
type ScaAuthUserSocialQueryRuleFunc func(context.Context, *ent.ScaAuthUserSocialQuery) error
|
||||
|
||||
// EvalQuery return f(ctx, q).
|
||||
func (f ScaAuthUserSocialQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||
if q, ok := q.(*ent.ScaAuthUserSocialQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected query type %T, expect *ent.ScaAuthUserSocialQuery", q)
|
||||
}
|
||||
|
||||
// The ScaAuthUserSocialMutationRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a mutation rule.
|
||||
type ScaAuthUserSocialMutationRuleFunc func(context.Context, *ent.ScaAuthUserSocialMutation) error
|
||||
|
||||
// EvalMutation calls f(ctx, m).
|
||||
func (f ScaAuthUserSocialMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||
if m, ok := m.(*ent.ScaAuthUserSocialMutation); ok {
|
||||
return f(ctx, m)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.ScaAuthUserSocialMutation", m)
|
||||
}
|
||||
|
||||
type (
|
||||
// Filter is the interface that wraps the Where function
|
||||
// for filtering nodes in queries and mutations.
|
||||
Filter interface {
|
||||
// Where applies a filter on the executed query/mutation.
|
||||
Where(entql.P)
|
||||
}
|
||||
|
||||
// The FilterFunc type is an adapter that allows the use of ordinary
|
||||
// functions as filters for query and mutation types.
|
||||
FilterFunc func(context.Context, Filter) error
|
||||
)
|
||||
|
||||
// EvalQuery calls f(ctx, q) if the query implements the Filter interface, otherwise it is denied.
|
||||
func (f FilterFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||
fr, err := queryFilter(q)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return f(ctx, fr)
|
||||
}
|
||||
|
||||
// EvalMutation calls f(ctx, q) if the mutation implements the Filter interface, otherwise it is denied.
|
||||
func (f FilterFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||
fr, err := mutationFilter(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return f(ctx, fr)
|
||||
}
|
||||
|
||||
var _ QueryMutationRule = FilterFunc(nil)
|
||||
|
||||
func queryFilter(q ent.Query) (Filter, error) {
|
||||
switch q := q.(type) {
|
||||
case *ent.ScaAuthPermissionRuleQuery:
|
||||
return q.Filter(), nil
|
||||
case *ent.ScaAuthRoleQuery:
|
||||
return q.Filter(), nil
|
||||
case *ent.ScaAuthUserQuery:
|
||||
return q.Filter(), nil
|
||||
case *ent.ScaAuthUserDeviceQuery:
|
||||
return q.Filter(), nil
|
||||
case *ent.ScaAuthUserSocialQuery:
|
||||
return q.Filter(), nil
|
||||
default:
|
||||
return nil, Denyf("ent/privacy: unexpected query type %T for query filter", q)
|
||||
}
|
||||
}
|
||||
|
||||
func mutationFilter(m ent.Mutation) (Filter, error) {
|
||||
switch m := m.(type) {
|
||||
case *ent.ScaAuthPermissionRuleMutation:
|
||||
return m.Filter(), nil
|
||||
case *ent.ScaAuthRoleMutation:
|
||||
return m.Filter(), nil
|
||||
case *ent.ScaAuthUserMutation:
|
||||
return m.Filter(), nil
|
||||
case *ent.ScaAuthUserDeviceMutation:
|
||||
return m.Filter(), nil
|
||||
case *ent.ScaAuthUserSocialMutation:
|
||||
return m.Filter(), nil
|
||||
default:
|
||||
return nil, Denyf("ent/privacy: unexpected mutation type %T for mutation filter", m)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user