Added ownership and app existence validation to the user app secrets routes.
This commit is contained in:
@@ -68,10 +68,9 @@ where
|
||||
r#"
|
||||
INSERT INTO user_app_secrets (id, app_id, secret_hash, expires_at)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
ON CONFLICT (id, app_id) DO UPDATE SET
|
||||
secret_hash = EXCLUDED.secret_hash,
|
||||
expires_at = EXCLUDED.expires_at
|
||||
WHERE user_app_secrets.app_id = EXCLUDED.app_id
|
||||
RETURNING WITH (OLD AS old_row, NEW AS new_row)
|
||||
old_row.id AS "old_id?",
|
||||
new_row.id AS "id!",
|
||||
|
||||
@@ -57,6 +57,22 @@ where
|
||||
.map_err(DatabaseError::from)
|
||||
}
|
||||
|
||||
pub async fn find_owner_by_id<'e, E>(
|
||||
executor: E,
|
||||
app_id: Uuid,
|
||||
) -> Result<Option<Uuid>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
sqlx::query_scalar!(
|
||||
"SELECT user_id FROM user_apps WHERE id = $1 FOR SHARE",
|
||||
app_id,
|
||||
)
|
||||
.fetch_optional(executor)
|
||||
.await
|
||||
.map_err(DatabaseError::from)
|
||||
}
|
||||
|
||||
pub async fn upsert<'e, E>(
|
||||
executor: E,
|
||||
app: UserAppRow,
|
||||
|
||||
Reference in New Issue
Block a user