MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / resolve_trigger_identity

Function resolve_trigger_identity

nodedb/src/control/trigger/fire_common.rs:109–131  ·  view source on GitHub ↗

Resolve the effective identity for a trigger execution. - INVOKER (default): uses the caller's identity (passthrough). - DEFINER: creates a synthetic identity from the trigger's owner. The tenant is always the trigger's tenant — DEFINER cannot cross tenants.

(
    trigger: &StoredTrigger,
    caller: &AuthenticatedIdentity,
    tenant_id: TenantId,
)

Source from the content-addressed store, hash-verified

107/// - DEFINER: creates a synthetic identity from the trigger's owner.
108/// The tenant is always the trigger's tenant — DEFINER cannot cross tenants.
109pub(crate) fn resolve_trigger_identity(
110 trigger: &StoredTrigger,
111 caller: &AuthenticatedIdentity,
112 tenant_id: TenantId,
113) -> AuthenticatedIdentity {
114 match trigger.security {
115 TriggerSecurity::Invoker => caller.clone(),
116 TriggerSecurity::Definer => {
117 // Create a synthetic identity for the trigger owner.
118 // The owner is a superuser within the trigger's tenant scope.
119 AuthenticatedIdentity {
120 user_id: 0, // System-generated; not a real user ID
121 username: trigger.owner.clone(),
122 tenant_id,
123 auth_method: AuthMethod::Trust,
124 roles: vec![Role::TenantAdmin],
125 is_superuser: true,
126 default_database: None,
127 accessible_databases: crate::control::security::identity::DatabaseSet::All,
128 }
129 }
130 }
131}
132
133/// Execute BEFORE triggers that may mutate the NEW row.
134///

Callers 3

fire_triggersFunction · 0.85
execute_before_batchFunction · 0.85

Calls 1

cloneMethod · 0.45

Tested by

no test coverage detected