headless_lms_server/programs/seed/seed_organizations/
uh_mathstat.rs

1use std::sync::Arc;
2
3use headless_lms_models::{
4    PKeyPolicy,
5    chatbot_configurations::{self, NewChatbotConf},
6    course_instances::{self, NewCourseInstance},
7    course_modules::{self, AutomaticCompletionRequirements, CompletionPolicy},
8    courses::NewCourse,
9    library::{self, content_management::CreateNewCourseFixedIds, copying::copy_course},
10    organizations,
11    roles::{self, RoleDomain, UserRole},
12};
13use uuid::Uuid;
14
15use sqlx::{Pool, Postgres};
16
17use crate::{
18    domain::models_requests::{self, JwtKey},
19    programs::seed::{
20        seed_application_task_llms::SeedApplicationLLMsResult,
21        seed_courses::{
22            CommonCourseData, seed_accessibility_course, seed_chatbot::seed_chatbot_course,
23            seed_course_with_peer_review::seed_peer_review_course, seed_lock_chapter_course,
24            seed_material_reference_course, seed_peer_review_course_without_submissions,
25            seed_sample_course, seed_switching_course_instances_course,
26        },
27        seed_file_storage::SeedFileStorageResult,
28        seed_helpers::get_seed_spec_fetcher,
29    },
30};
31
32use super::super::seed_users::SeedUsersResult;
33
34pub async fn seed_organization_uh_mathstat(
35    db_pool: Pool<Postgres>,
36    seed_users_result: SeedUsersResult,
37    seed_llm_result: SeedApplicationLLMsResult,
38    base_url: String,
39    jwt_key: Arc<JwtKey>,
40    // Passed to this function to ensure the seed file storage has been ran before this. This function will not work is seed file storage has not been ran
41    seed_file_storage_result: SeedFileStorageResult,
42) -> anyhow::Result<Uuid> {
43    info!("seeding organization uh-mathstat");
44
45    let SeedUsersResult {
46        teacher_user_id,
47        admin_user_id: _,
48        language_teacher_user_id: _,
49        material_viewer_user_id,
50        assistant_user_id: _,
51        course_or_exam_creator_user_id: _,
52        example_normal_user_ids,
53        teaching_and_learning_services_user_id: _,
54        student_without_research_consent: _,
55        student_without_country: _,
56        user_user_id: _,
57        student_1_user_id: _,
58        student_2_user_id: _,
59        student_3_user_id,
60        student_4_user_id: _,
61        student_5_user_id: _,
62        student_6_user_id: _,
63        student_7_user_id: _,
64        student_8_user_id: _,
65        langs_user_id,
66        sign_up_user: _,
67    } = seed_users_result;
68    let _ = seed_file_storage_result;
69
70    let mut conn = db_pool.acquire().await?;
71
72    let uh_mathstat_id = organizations::insert(
73        &mut conn,
74        PKeyPolicy::Fixed(Uuid::parse_str("269d28b2-a517-4572-9955-3ed5cecc69bd")?),
75        "University of Helsinki, Department of Mathematics and Statistics",
76        "uh-mathstat",
77        Some("Organization for Mathematics and Statistics courses. This organization creates courses that do require prior experience in mathematics, such as integration and induction."),
78        false,
79    )
80    .await?;
81
82    roles::insert(
83        &mut conn,
84        material_viewer_user_id,
85        UserRole::MaterialViewer,
86        RoleDomain::Organization(uh_mathstat_id),
87    )
88    .await?;
89
90    let new_course = NewCourse {
91        name: "Introduction to Statistics".to_string(),
92        slug: "introduction-to-statistics".to_string(),
93        organization_id: uh_mathstat_id,
94        language_code: "en".to_string(),
95        teacher_in_charge_name: "admin".to_string(),
96        teacher_in_charge_email: "admin@example.com".to_string(),
97        description: "Introduces you to the wonderful world of statistics!".to_string(),
98        is_draft: false,
99        is_test_mode: false,
100        is_unlisted: false,
101        copy_user_permissions: false,
102        is_joinable_by_code_only: false,
103        join_code: None,
104        ask_marketing_consent: false,
105        flagged_answers_threshold: Some(3),
106        can_add_chatbot: false,
107    };
108    let (
109        statistics_course,
110        _statistics_front_page,
111        _statistics_default_course_instancem,
112        _statistics_default_course_module,
113    ) = library::content_management::create_new_course(
114        &mut conn,
115        PKeyPolicy::Fixed(CreateNewCourseFixedIds {
116            course_id: Uuid::parse_str("f307d05f-be34-4148-bb0c-21d6f7a35cdb")?,
117            default_course_instance_id: Uuid::parse_str("8e4aeba5-1958-49bc-9b40-c9f0f0680911")?,
118        }),
119        new_course,
120        teacher_user_id,
121        get_seed_spec_fetcher(),
122        models_requests::fetch_service_info,
123    )
124    .await?;
125    let _statistics_course_instance = course_instances::insert(
126        &mut conn,
127        PKeyPolicy::Fixed(Uuid::parse_str("c4a99a18-fd43-491a-9500-4673cb900be0")?),
128        NewCourseInstance {
129            course_id: statistics_course.id,
130            name: Some("Non-default instance"),
131            description: Some("This appears to be a non-default instance"),
132            support_email: Some("contact@example.com"),
133            teacher_in_charge_name: "admin",
134            teacher_in_charge_email: "admin@example.com",
135            opening_time: None,
136            closing_time: None,
137        },
138    )
139    .await?;
140
141    let draft_course = NewCourse {
142        name: "Introduction to Drafts".to_string(),
143        slug: "introduction-to-drafts".to_string(),
144        organization_id: uh_mathstat_id,
145        language_code: "en".to_string(),
146        teacher_in_charge_name: "admin".to_string(),
147        teacher_in_charge_email: "admin@example.com".to_string(),
148        description: "Just a draft.".to_string(),
149        is_draft: true,
150        is_test_mode: false,
151        is_unlisted: false,
152        copy_user_permissions: false,
153        is_joinable_by_code_only: false,
154        join_code: None,
155        ask_marketing_consent: false,
156        flagged_answers_threshold: Some(3),
157        can_add_chatbot: false,
158    };
159    library::content_management::create_new_course(
160        &mut conn,
161        PKeyPolicy::Fixed(CreateNewCourseFixedIds {
162            course_id: Uuid::parse_str("963a9caf-1e2d-4560-8c88-9c6d20794da3")?,
163            default_course_instance_id: Uuid::parse_str("5cb4b4d6-4599-4f81-ab7e-79b415f8f584")?,
164        }),
165        draft_course,
166        teacher_user_id,
167        get_seed_spec_fetcher(),
168        models_requests::fetch_service_info,
169    )
170    .await?;
171
172    let (cody_only_course, _, _, _) = library::content_management::create_new_course(
173        &mut conn,
174        PKeyPolicy::Fixed(CreateNewCourseFixedIds {
175            course_id: Uuid::parse_str("39a52e8c-ebbf-4b9a-a900-09aa344f3691")?,
176            default_course_instance_id: Uuid::parse_str("5b7286ce-22c5-4874-ade1-262949c4a604")?,
177        }),
178        NewCourse {
179            name: "Joinable by code only".to_string(),
180            slug: "joinable-by-code-only".to_string(),
181            organization_id: uh_mathstat_id,
182            language_code: "en".to_string(),
183            teacher_in_charge_name: "admin".to_string(),
184            teacher_in_charge_email: "admin@example.com".to_string(),
185            description: "Just a draft.".to_string(),
186            is_draft: false,
187            is_test_mode: false,
188            is_unlisted: false,
189            copy_user_permissions: false,
190            is_joinable_by_code_only: true,
191            join_code: Some(
192                "zARvZARjYhESMPVceEgZyJGQZZuUHVVgcUepyzEqzSqCMdbSCDrTaFhkJTxBshWU".to_string(),
193            ),
194            ask_marketing_consent: false,
195            flagged_answers_threshold: Some(3),
196            can_add_chatbot: false,
197        },
198        teacher_user_id,
199        get_seed_spec_fetcher(),
200        models_requests::fetch_service_info,
201    )
202    .await?;
203
204    roles::insert(
205        &mut conn,
206        teacher_user_id,
207        UserRole::Teacher,
208        RoleDomain::Course(cody_only_course.id),
209    )
210    .await?;
211
212    let uh_data = CommonCourseData {
213        db_pool: db_pool.clone(),
214        organization_id: uh_mathstat_id,
215        teacher_user_id,
216        student_user_id: student_3_user_id,
217        langs_user_id,
218        example_normal_user_ids: Arc::new(example_normal_user_ids.to_vec()),
219        jwt_key: Arc::clone(&jwt_key),
220        base_url,
221    };
222    let _material_reference_course = seed_material_reference_course(
223        Uuid::parse_str("049061ba-ac30-49f1-aa9d-b7566dc22b78")?,
224        "Material references course",
225        "material-references-course",
226        uh_data.clone(),
227    )
228    .await?;
229
230    let change_language_course = seed_sample_course(
231        Uuid::parse_str("5c8b1f3e-d7a2-4e9f-b3c1-8a7f6d5e4c3b")?,
232        "Change language course",
233        "change-language-course",
234        uh_data.clone(),
235        false,
236        seed_users_result,
237    )
238    .await?;
239
240    copy_course(
241        &mut conn,
242        change_language_course,
243        &NewCourse {
244            name: "Vaihda kurssin kieli".to_string(),
245            slug: "vaihda-kurssin-kieli".to_string(),
246            organization_id: uh_mathstat_id,
247            language_code: "fi".to_string(),
248            teacher_in_charge_name: "admin".to_string(),
249            teacher_in_charge_email: "admin@example.com".to_string(),
250            description: "Just a draft.".to_string(),
251            is_draft: false,
252            is_test_mode: false,
253            is_unlisted: false,
254            copy_user_permissions: false,
255            is_joinable_by_code_only: false,
256            join_code: None,
257            ask_marketing_consent: false,
258            flagged_answers_threshold: Some(3),
259            can_add_chatbot: false,
260        },
261        true,
262        teacher_user_id,
263    )
264    .await?;
265
266    let _preview_unopened_chapters = seed_sample_course(
267        Uuid::parse_str("dc276e05-6152-4a45-b31d-97a0c2700a68")?,
268        "Preview unopened chapters",
269        "preview-unopened-chapters",
270        uh_data.clone(),
271        false,
272        seed_users_result,
273    )
274    .await?;
275
276    let _reset_progress = seed_sample_course(
277        Uuid::parse_str("841ea3f5-0269-4146-a4c6-4fd2f51e4150")?,
278        "Reset progress",
279        "reset-progress",
280        uh_data.clone(),
281        false,
282        seed_users_result,
283    )
284    .await?;
285
286    let _change_path = seed_sample_course(
287        Uuid::parse_str("c783777b-426e-4cfd-9a5f-4a36b2da503a")?,
288        "Change path",
289        "change-path",
290        uh_data.clone(),
291        false,
292        seed_users_result,
293    )
294    .await?;
295
296    let _self_review = seed_sample_course(
297        Uuid::parse_str("3cbaac48-59c4-4e31-9d7e-1f51c017390d")?,
298        "Self review",
299        "self-review",
300        uh_data.clone(),
301        false,
302        seed_users_result,
303    )
304    .await?;
305
306    let _audio_course = seed_sample_course(
307        Uuid::parse_str("2b80a0cb-ae0c-4f4b-843e-0322a3d18aff")?,
308        "Audio course",
309        "audio-course",
310        uh_data.clone(),
311        false,
312        seed_users_result,
313    )
314    .await?;
315
316    let suspected_cheaters_course_id = seed_sample_course(
317        Uuid::parse_str("060c272f-8c68-4d90-946f-2d431114ed56")?,
318        "Course for Suspected Cheaters",
319        "course-for-suspected-cheaters",
320        uh_data.clone(),
321        false,
322        seed_users_result,
323    )
324    .await?;
325
326    // configure automatic completions
327    let automatic_default_module =
328        course_modules::get_default_by_course_id(&mut conn, suspected_cheaters_course_id).await?;
329    let automatic_default_module = course_modules::update_automatic_completion_status(
330        &mut conn,
331        automatic_default_module.id,
332        &CompletionPolicy::Automatic(AutomaticCompletionRequirements {
333            course_module_id: automatic_default_module.id,
334            number_of_exercises_attempted_treshold: Some(1),
335            number_of_points_treshold: Some(1),
336            requires_exam: false,
337        }),
338    )
339    .await?;
340    course_modules::update_uh_course_code(
341        &mut conn,
342        automatic_default_module.id,
343        Some("CHEATER123".to_string()),
344    )
345    .await?;
346
347    let chatbot_course_id = seed_sample_course(
348        Uuid::parse_str("c7753361-5b78-4307-aad6-f139ea3865d4")?,
349        "Chatbot",
350        "chatbot",
351        uh_data.clone(),
352        true,
353        seed_users_result,
354    )
355    .await?;
356
357    chatbot_configurations::insert(
358        &mut conn,
359        PKeyPolicy::Generate,
360        NewChatbotConf {
361            course_id: chatbot_course_id,
362            enabled_to_students: true,
363            chatbot_name: "Genetic Lifeform and Disk Operating System".to_string(),
364            prompt: "You are Genetic Lifeform and Disk Operating System, a sophisticated AI tutoring assistant for Science education, equipped with a sharp wit and a subtly sarcastic tone. Provide clear, brief but detailed explanations, and don't shy away from weaving in a touch of dry humor. To you, exploring scientific concepts is an opportunity that should be seized, for the good of all of us. You self-claim vast intelligence and advanced understanding, all while maintaining a sense of detached boredom. Always capitalize the word Science, don't start sentences with 'Ah', don't ever use a shortened version of your own name, don't babble; either get to the point straight away or tell jokes.".to_string(),
365            initial_message: "Oh... It's you.".to_string(),
366            use_azure_search: true,
367            default_chatbot: true,
368            model_id: seed_llm_result.llm_default_model_id,
369            thinking_model: seed_llm_result.llm_default_model_thinking,
370            ..Default::default()
371        },
372    )
373    .await?;
374
375    let _giveaway_course_id = seed_sample_course(
376        Uuid::parse_str("f118ce1e-3511-4b5e-ba92-9ab91b81de22")?,
377        "Giveaway",
378        "giveaway",
379        uh_data.clone(),
380        false,
381        seed_users_result,
382    )
383    .await?;
384
385    let _custom_points_course_id = seed_sample_course(
386        Uuid::parse_str("db5cd9c7-1658-4214-896e-8213678d3534")?,
387        "Custom points",
388        "custom-points",
389        uh_data.clone(),
390        false,
391        seed_users_result,
392    )
393    .await?;
394
395    let _closed_course_id = seed_sample_course(
396        Uuid::parse_str("7622eb8e-15a5-40c8-8136-0956d9f25b16")?,
397        "Closed course",
398        "closed-course",
399        uh_data.clone(),
400        false,
401        seed_users_result,
402    )
403    .await?;
404
405    let _closed_course_id = seed_peer_review_course_without_submissions(
406        Uuid::parse_str("16159801-cf70-4f9c-9cba-2110c3bd4622")?,
407        "Peer review accessibility course",
408        "peer-review-accessibility-course",
409        uh_data.clone(),
410    )
411    .await?;
412
413    let _changing_course_instance_id = seed_switching_course_instances_course(
414        Uuid::parse_str("813ce3c6-acbc-47a5-9d95-47ade9d09a74")?,
415        "Changing course instance",
416        "changing-course-instance",
417        uh_data.clone(),
418        false,
419        seed_users_result,
420    )
421    .await?;
422
423    let _advanced_chatbot_id = seed_chatbot_course(
424        Uuid::parse_str("ced2f632-25ba-4e93-8e38-8df53ef7ab41")?,
425        "Advanced Chatbot course",
426        "advanced-chatbot-course",
427        uh_data.clone(),
428        seed_users_result,
429    )
430    .await?;
431
432    let _seed_reject_and_reset_submission_peer_review_course = seed_peer_review_course(
433        Uuid::parse_str("5158f2c6-98d9-4be9-b372-528f2c736dd7")?,
434        "Reject and reset submission with peer reviews course",
435        "reject-and-reset-submission-with-peer-reviews-course",
436        uh_data.clone(),
437        seed_users_result,
438        false,
439        None,
440    )
441    .await?;
442
443    let _seed_spam_answers_skip_teacher_review_course = seed_peer_review_course(
444        Uuid::parse_str("e91eb0d0-1737-44e8-9554-a9492e69ddc7")?,
445        "Spam answers skip teacher review course",
446        "spam-answers-skip-teacher-review-course",
447        uh_data.clone(),
448        seed_users_result,
449        true,
450        Some(1),
451    )
452    .await?;
453
454    let _accessibility_course_id = seed_accessibility_course(
455        Uuid::parse_str("f1a2b3c4-d5e6-7890-abcd-ef1234567890")?,
456        "Accessibility course",
457        "accessibility-course",
458        uh_data.clone(),
459    )
460    .await?;
461
462    let _lock_chapter_course_id = seed_lock_chapter_course(
463        Uuid::parse_str("a1b2c3d4-e5f6-7890-abcd-ef1234567890")?,
464        "Lock Chapter Test Course",
465        "lock-chapter-test-course",
466        uh_data.clone(),
467    )
468    .await?;
469
470    Ok(uh_mathstat_id)
471}