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

Function assert_visible

nodedb/src/control/server/pgwire/ddl/explain_ddl.rs:158–207  ·  view source on GitHub ↗

`SELECT nodedb_assert_visible(' ', ' ', ' ')` Test helper: returns true/false whether a row is visible to a user under RLS.

(
    state: &SharedState,
    _identity: &AuthenticatedIdentity,
    parts: &[&str],
)

Source from the content-addressed store, hash-verified

156///
157/// Test helper: returns true/false whether a row is visible to a user under RLS.
158pub fn assert_visible(
159 state: &SharedState,
160 _identity: &AuthenticatedIdentity,
161 parts: &[&str],
162) -> PgWireResult<Vec<Response>> {
163 // Parse: nodedb_assert_visible('collection', 'row_id', 'user_id')
164 if parts.len() < 4 {
165 return Err(sqlstate_error(
166 "42601",
167 "syntax: SELECT nodedb_assert_visible('<collection>', '<row_id>', '<user_id>')",
168 ));
169 }
170
171 let collection = parts[1].trim_matches('\'').trim_end_matches(',');
172 let _row_id = parts[2].trim_matches('\'').trim_end_matches(',');
173 let user_id = parts[3].trim_matches('\'').trim_end_matches(')');
174
175 // Build AuthContext for the target user.
176 let target_identity = crate::control::security::identity::AuthenticatedIdentity {
177 user_id: user_id.parse().unwrap_or(0),
178 username: user_id.to_string(),
179 tenant_id: crate::types::TenantId::new(1),
180 auth_method: crate::control::security::identity::AuthMethod::Trust,
181 roles: vec![crate::control::security::identity::Role::ReadWrite],
182 is_superuser: false,
183 default_database: None,
184 accessible_databases: crate::control::security::identity::DatabaseSet::Some(
185 smallvec::smallvec![nodedb_types::id::DatabaseId::DEFAULT],
186 ),
187 };
188 let auth_ctx = crate::control::server::session_auth::build_auth_context(&target_identity);
189
190 // Check if RLS policies would filter this user.
191 let rls_bytes = state.rls.combined_read_predicate_with_auth(
192 target_identity.tenant_id.as_u64(),
193 collection,
194 &auth_ctx,
195 );
196
197 let visible = rls_bytes.is_some_and(|b| b.is_empty()); // No filters = visible.
198
199 let schema = Arc::new(vec![text_field("visible")]);
200 let mut enc = DataRowEncoder::new(schema.clone());
201 let _ = enc.encode_field(&visible.to_string());
202
203 Ok(vec![Response::Query(QueryResponse::new(
204 schema,
205 stream::iter(vec![Ok(enc.take_row())]),
206 ))])
207}

Callers

nothing calls this directly

Calls 9

build_auth_contextFunction · 0.85
to_stringMethod · 0.80
sqlstate_errorFunction · 0.70
lenMethod · 0.45
parseMethod · 0.45
as_u64Method · 0.45
is_emptyMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected