headless_lms_server/domain/exercise_services/submission_sharing.rs
1//! Sharing exercise-slide submissions via unguessable-token links.
2//!
3//! A legacy "paste" is modelled as a share capability on an existing
4//! `exercise_slide_submission`, not as a separate stored copy of the answer.
5
6use crate::prelude::*;
7use models::exercise_slide_submission_shares::ExerciseSlideSubmissionShare;
8
9/// Mints a new share for the given submission; the returned `id` is the unguessable
10/// token embedded in the shareable URL.
11///
12/// Not idempotent: minting twice creates two independent, individually revocable
13/// shares. Callers must have verified that the submission belongs to the user.
14pub async fn share_submission(
15 conn: &mut PgConnection,
16 exercise_slide_submission_id: Uuid,
17 created_by: Uuid,
18) -> Result<ExerciseSlideSubmissionShare, ControllerError> {
19 let share = models::exercise_slide_submission_shares::insert(
20 conn,
21 exercise_slide_submission_id,
22 created_by,
23 )
24 .await?;
25 Ok(share)
26}