rule

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowIfAdmin

func AllowIfAdmin() privacy.QueryMutationRule

AllowIfAdmin is a rule that returns Allow decision if the viewer is admin.

func DenyFieldsMutationRule

func DenyFieldsMutationRule(ctx context.Context, m ent.Mutation, fields ...string) error

DenyFieldsMutationRule 禁止修改特定字段的 Mutation 规则 参数说明: ctx: 上下文 m: 传入的对象,在 Mutation 阶段它是具体的 Mutation 实例 fields: 需要保护(禁止修改)的字段名

func DenyIfNoViewer

func DenyIfNoViewer() privacy.QueryMutationRule

DenyIfNoViewer is a rule that denies the operation if there is no viewer in the context.

func GetClientFromMutation

func GetClientFromMutation(m ent.Mutation) (any, bool)

GetClientFromMutation 通过反射从 m 上调用 Client 方法。 返回 (client, true) 表示成功获取;否则返回 (nil, false)。

func LimitFieldAccessRule

func LimitFieldAccessRule(ctx context.Context, m ent.Mutation, field string, requiredPermission string) error

LimitFieldAccessRule 限制特定字段的访问修改权限 参数说明: ctx: 上下文 m: 传入的对象,在 Mutation 阶段它是具体的 Mutation 实例 field: 需要保护的字段名 requiredPermission: 修改该字段所需的权限标识

func OwnerOnlyRule

func OwnerOnlyRule(ctx context.Context, f Filter) error

func PermissionRule

func PermissionRule(ctx context.Context, f Filter) error

PermissionRule 是一个通用的数据权限过滤规则,用于在查询时注入基于数据权限范围的过滤条件。 该规则会根据当前 ViewerContext 中的数据权限信息,动态添加过滤谓词,确保数据访问符合权限要求。 适用于包含 org_unit_id 和 created_by 字段的实体查询。

func SoftDeleteRule

func SoftDeleteRule(ctx context.Context, f Filter) error

SoftDeleteRule 注入软删除过滤规则,隐藏已软删除的数据记录

func TenantFilterRule

func TenantFilterRule(ctx context.Context, f Filter) error

TenantFilterRule 是一个通用的租户过滤规则,用于在查询时注入租户过滤条件。 该规则会根据当前 ViewerContext 中的租户信息,动态添加租户过滤谓词,确保数据隔离和安全性。 适用于包含 tenant_id 字段的实体查询。

Types

type Filter

type Filter interface {
	// Where applies a filter on the executed query/mutation.
	Where(entql.P)
}

Filter is the interface that wraps the Where function for filtering nodes in queries and mutations.

type TenantPrivacy

type TenantPrivacy[T uint32 | uint64] struct {
	// contains filtered or unexported fields
}

func (TenantPrivacy[T]) EvalMutation

func (f TenantPrivacy[T]) EvalMutation(ctx context.Context, m ent.Mutation) error

func (TenantPrivacy[T]) EvalQuery

func (f TenantPrivacy[T]) EvalQuery(ctx context.Context, query ent.Query) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL