use db::conn::sea_orm::*; use db::attachment::attachments as att_entity; use db::attachment::attachments::OwnerType; use uuid::Uuid; use crate::error::{IssueError, IssueResult}; use crate::features::IssueService; pub fn require_authenticated(actor: Uuid) -> IssueResult<()> { if actor.is_nil() { return Err(IssueError::Unauthorized("authentication required".into())); } Ok(()) } pub async fn load_attachment( svc: &IssueService, owner_type: OwnerType, owner_id: Uuid, att_id: Uuid, ) -> IssueResult { let db = svc.db.reader(); let r = att_entity::Entity::find_by_id(att_id) .filter(att_entity::COLUMN.owner_type.eq(owner_type)) .filter(att_entity::COLUMN.owner_id.eq(owner_id)) .one(&db) .await? .ok_or_else(|| IssueError::NotFound(format!("attachment {att_id}")))?; Ok(r) }