1use config;
16use db_objects::*;
17
18#[derive(Debug)]
19pub enum SignupResult {
20 SignedUp,
21 EmailTaken,
22 UsernameTaken,
23 UserLoggedIn,
24 EmptyFields,
25}
26
27pub trait MedalConnection {
30 fn reconnect(config: &config::Config) -> Self;
31
32 fn dbtype(&self) -> &'static str;
33
34 fn migration_already_applied(&self, name: &str) -> bool;
35 fn apply_migration(&mut self, name: &str, contents: &str);
36
37 fn code_exists(&self, code: &str) -> bool;
38
39 fn get_session(&self, key: &str) -> Option<SessionUser>;
44
45 fn new_session(&self, key: &str) -> SessionUser;
49 fn session_set_activity_dates(&self, session_id: i64, account_created: Option<time::Timespec>,
51 last_login: Option<time::Timespec>, last_activity: Option<time::Timespec>);
52 fn save_session(&self, session: SessionUser);
54 fn get_session_or_new(&self, key: &str) -> Result<SessionUser, ()>;
58
59 fn get_team_partners_by_contest_and_teamlead(&self, contest_id: i64, teamlead_id: i64) -> Vec<SessionUser>;
60
61 fn get_user_by_id(&self, user_id: i64) -> Option<SessionUser>;
65
66 fn get_user_and_group_by_id(&self, user_id: i64) -> Option<(SessionUser, Option<Group>)>;
71 fn get_user_and_group_by_logincode(&self, logincode: &str) -> Option<(SessionUser, Option<Group>)>;
72
73 fn set_webauthn_passkey_registration(&self, user_id: i64, passkey_registration: &str);
74 fn get_webauthn_passkey_registration(&self, user_id: i64) -> Option<String>;
75 fn check_webauthn_cred_id_in_use(&self, cred_id: &str) -> bool;
76 fn add_webauthn_passkey(&self, user_id: i64, cred_id: &str, passkey: &str, name: &str) -> i64;
77 fn delete_webauthn_passkey(&self, session_id: i64, passkey_id: i64);
78
79 fn get_webauthn_passkey_names_for_user(&self, user_id: i64) -> Vec<(i64, String)>;
80 fn get_all_webauthn_passkeys(&self) -> Vec<String>;
81 fn get_all_webauthn_credentials(&self) -> Vec<String>;
82 fn store_webauthn_auth_challenge(&self, challenge: &str, authentication: &str) -> i64;
83 fn get_webauthn_auth_challenge_by_id(&self, auth_id: i64) -> Option<String>;
84
85 fn update_grade(&self, session_token: &str, timediff: i32) -> bool;
90 fn login(&self, session: Option<&str>, username: &str, password: &str) -> Result<(String, i32), ()>;
91 fn login_with_code(&self, session: Option<&str>, logincode: &str) -> Result<(String, i32), ()>;
92 fn login_with_key(&self, session: Option<&str>, cred_id: &str) -> Result<(String, i32), ()>;
93 fn login_foreign(&self, session: Option<&str>, provider_id: &str, foreign_id: &str,
94 _: (bool, bool, &str, &str, Option<i32>, &Option<String>))
95 -> Result<(String, i32, Option<time::Timespec>), ()>;
96 fn create_user_with_groupcode(&self, session: Option<&str>, groupcode: &str) -> Result<String, ()>;
97 fn update_or_create_group_with_users(&self, group: Group, admin: i64);
98 fn new_logincode(&self, user_id: i64) -> Option<String>;
99 fn new_groupcode(&self, group_id: i64) -> Option<String>;
100 fn add_admin_to_group(&self, group: &mut Group, admin: i64);
101 fn remove_admin_from_group(&self, group: &mut Group, admin: i64);
102
103 fn logout(&self, session: &str);
106
107 fn signup(&self, session_token: &str, username: &str, email: &str, password_hash: String, salt: &str)
108 -> SignupResult;
109
110 fn load_submission(&self, session: &SessionUser, task_id: i64, subtask: Option<&str>) -> Option<Submission>;
111 fn get_all_submissions(&self, session_id: i64, task_id: i64, subtask: Option<&str>) -> Vec<Submission>;
112 fn submit_submission(&self, submission: Submission);
113 fn get_grade_by_user_and_task(&self, session_id: i64, task_id: i64) -> Grade;
114 fn get_contest_groups_grades(&self, session_id: i64, contest_id: i64)
115 -> (Vec<String>, Vec<(Group, Vec<(UserInfo, Vec<Grade>)>)>);
116 fn get_taskgroup_user_grade(&self, session_id: i64, taskgroup_id: i64) -> Grade;
117 fn get_contest_user_grades(&self, session_id: i64, contest_id: i64) -> Vec<Grade>;
118 fn export_contest_results_to_file(&self, contest_id: i64, taskgroups_ids: &[(i64, String)], filename: &str);
119
120 fn insert_contest_annotations(&self, contest_id: i64, annotations: Vec<(i64, Option<String>)>) -> i64;
121
122 fn get_submission_by_id_complete_shallow_contest(&self, submission_id: i64)
124 -> Option<(Submission, Task, Taskgroup, Contest)>;
125
126 fn get_contest_list(&self) -> Vec<Contest>;
128
129 fn get_contest_list_with_group_member_participations(&self, session_id: i64) -> Vec<Contest>;
131
132 fn get_contest_by_id(&self, contest_id: i64) -> Option<Contest>;
135
136 fn get_contest_by_id_partial(&self, contest_id: i64) -> Option<Contest>;
139
140 fn get_contest_by_id_complete(&self, contest_id: i64) -> Option<Contest>;
143
144 fn get_participation(&self, session_id: i64, contest_id: i64) -> Option<Participation>;
148
149 fn get_own_participation(&self, session_id: i64, contest_id: i64) -> Option<Participation>;
153
154 fn get_all_participations_complete(&self, session_id: i64) -> Vec<(Participation, Contest)>;
158
159 fn count_all_stars(&self, session_id: i64) -> i32;
160 fn count_all_stars_by_contest(&self, session_id: i64) -> Vec<(i64, i32)>;
161
162 fn has_participation_by_contest_file(&self, session_id: i64, location: &str, filename: &str) -> bool;
163 fn has_participation_by_contest_file_and_stars(&self, session_id: i64, location: &str, filename: &str, stars: i32)
164 -> bool;
165
166 fn new_participation(&self, session_id: i64, contest_id: i64, team: Option<i64>) -> Result<Participation, ()>;
172 fn move_participation_complete(&self, contest_id: i64, old_session_id: i64, new_session_id: i64);
173 fn get_task_by_id(&self, task_id: i64) -> Option<Task>;
174 fn get_task_by_id_complete(&self, task_id: i64) -> Option<(Task, Taskgroup, Contest)>;
175
176 fn get_submission_to_validate(&self, tasklocation: &str, subtask: Option<&str>) -> i64;
177 fn find_next_submission_to_validate(&self, user_id: i64, taskgroup_id: i64);
178
179 fn add_group(&self, group: &mut Group);
180 fn save_group(&self, group: &mut Group);
181 fn get_groups(&self, session_id: i64) -> Vec<Group>;
182 fn get_groups_complete(&self, session_id: i64) -> Vec<Group>;
183 fn get_group(&self, group_id: i64) -> Option<Group>;
184 fn group_has_protected_participations(&self, session_id: i64) -> bool;
185 fn get_group_complete(&self, group_id: i64) -> Option<Group>;
186
187 fn delete_user(&self, user_id: i64);
188 fn delete_all_users_for_group(&self, group_id: i64);
189 fn delete_group(&self, group_id: i64);
190 fn set_data_clearance_for_user(&self, user_id: i64, clearance_state: bool);
191 fn set_data_clearance_for_group(&self, group_id: i64, clearance_state: bool);
192 fn delete_participation(&self, user_id: i64, contest_id: i64);
193 fn remove_old_users_and_groups(&self, maxstudentage: time::Timespec, maxteacherage: Option<time::Timespec>,
194 maxage: Option<time::Timespec>)
195 -> Result<(i64, i64, i64, i64), ()>;
196 fn count_temporary_sessions(&self, maxage: time::Timespec) -> i64;
197 fn remove_temporary_sessions(&self, maxage: time::Timespec, limit: Option<i64>);
198
199 fn remove_autosaved_submissions(&self, maxage: time::Timespec, limit: Option<i64>);
200 fn remove_all_but_latest_submissions(&self, maxage: time::Timespec, limit: Option<i64>);
201
202 fn move_task_location(&self, old_location: &str, new_location: &str, contest: &str) -> Option<()>;
203 fn move_task_contest(&self, old_location: &str, new_location: &str, old_contest: &str, new_contest: &str)
204 -> Option<()>;
205 fn move_contest_location(&self, old_location: &str, new_location: &str) -> Option<()>;
206 fn move_task_submissions_grades(&self, old_location: &str, new_location: &str, old_contest: &str,
207 new_contest: &str)
208 -> Option<()>;
209
210 fn get_search_users(
211 &self,
212 _: (Option<i64>,
213 Option<String>,
214 Option<String>,
215 Option<String>,
216 Option<String>,
217 Option<String>,
218 Option<String>,
219 Option<String>))
220 -> (Vec<(i64, Option<String>, Option<String>, Option<String>, Option<String>, Option<String>)>,
221 Vec<(i64, String, String, String)>);
222
223 fn get_debug_information(&self) -> String;
224
225 fn reset_all_contest_visibilities(&self);
226 fn reset_all_taskgroup_visibilities(&self);
227}
228
229pub trait MedalObject<T: MedalConnection> {
230 fn save(&mut self, conn: &T);
231}