use cratestack_core::{CratestackContext, CratestackError};
use crate::{ModelDescriptor, SqlValue, SqlxRuntime};
use super::upsert_sql::row_passes_update_policy;
pub(super) async fn authorize_existing_row<M, PK>(
runtime: &SqlxRuntime,
descriptor: &'static ModelDescriptor<M, PK>,
conflict_columns: &[(&'static str, SqlValue)],
predicate: Option<&'static str>,
ctx: &CratestackContext,
) -> Result<(), CratestackError> {
if !row_passes_update_policy(runtime.pool(), descriptor, conflict_columns, predicate, ctx)
.await?
{
return Err(CratestackError::Forbidden(
"update policy denied this upsert".to_owned(),
));
}
Ok(())
}