headless_lms_server/domain/credit_registration/
linking_mail_resend.rs1use headless_lms_credit_registration::account_linking;
5use utoipa::ToSchema;
6
7use crate::prelude::*;
8
9pub async fn ensure_resend_possible(
12 conn: &mut PgConnection,
13 app_conf: &ApplicationConfiguration,
14 course_id: Uuid,
15) -> Result<(), ControllerError> {
16 if !app_conf.suotar_configuration.is_account_linking_enabled() {
17 return Err(controller_err!(
18 BadRequest,
19 "Account linking is switched off.".to_string()
20 ));
21 }
22 let registers_credits = models::course_modules::get_by_course_id(conn, course_id)
23 .await?
24 .iter()
25 .any(|module| {
26 models::course_modules::registers_credits(
27 module.uh_course_code.as_deref(),
28 module.completions_can_be_registered_to_sisu,
29 )
30 });
31 if !registers_credits {
32 return Err(controller_err!(
33 BadRequest,
34 "This course has no module with a course code.".to_string()
35 ));
36 }
37 Ok(())
38}
39
40#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Copy, ToSchema)]
44#[serde(rename_all = "snake_case")]
45pub enum ResendOutcome {
46 Queued,
48 AlreadyMailedToEveryKnownAddress,
49 RefusedByRateCap,
51 JustSent,
53 NoAddressInStudyRegistry,
54 NotOnTheCourseRoster,
55 AlreadyLinked,
57 StudyRegistryUnavailable,
58 NoStudentNumberKnown,
60}
61
62impl From<account_linking::ResendOutcome> for ResendOutcome {
63 fn from(outcome: account_linking::ResendOutcome) -> Self {
64 use account_linking::ResendOutcome as Attempted;
65 match outcome {
66 Attempted::Queued => Self::Queued,
67 Attempted::AlreadyMailedToEveryKnownAddress => Self::AlreadyMailedToEveryKnownAddress,
68 Attempted::RefusedByRateCap => Self::RefusedByRateCap,
69 Attempted::JustSent => Self::JustSent,
70 Attempted::NoAddressInStudyRegistry => Self::NoAddressInStudyRegistry,
71 Attempted::NotOnTheCourseRoster => Self::NotOnTheCourseRoster,
72 Attempted::AlreadyLinked => Self::AlreadyLinked,
73 Attempted::StudyRegistryUnavailable => Self::StudyRegistryUnavailable,
74 }
75 }
76}