Trait medal::db_conn::MedalConnection

source ·
pub trait MedalConnection {
Show 76 methods // Required methods fn reconnect(config: &Config) -> Self; fn dbtype(&self) -> &'static str; fn migration_already_applied(&self, name: &str) -> bool; fn apply_migration(&mut self, name: &str, contents: &str); fn code_exists(&self, code: &str) -> bool; fn get_session(&self, key: &str) -> Option<SessionUser>; fn new_session(&self, key: &str) -> SessionUser; fn session_set_activity_dates( &self, session_id: i32, account_created: Option<Timespec>, last_login: Option<Timespec>, last_activity: Option<Timespec>, ); fn save_session(&self, session: SessionUser); fn get_session_or_new(&self, key: &str) -> Result<SessionUser, ()>; fn get_user_by_id(&self, user_id: i32) -> Option<SessionUser>; fn get_user_and_group_by_id( &self, user_id: i32, ) -> Option<(SessionUser, Option<Group>)>; fn get_user_and_group_by_logincode( &self, logincode: &str, ) -> Option<(SessionUser, Option<Group>)>; fn set_webauthn_passkey_registration( &self, user_id: i32, passkey_registration: &str, ); fn get_webauthn_passkey_registration(&self, user_id: i32) -> Option<String>; fn check_webauthn_cred_id_in_use(&self, cred_id: &str) -> bool; fn add_webauthn_passkey( &self, user_id: i32, cred_id: &str, passkey: &str, name: &str, ) -> i32; fn delete_webauthn_passkey(&self, session_id: i32, passkey_id: i32); fn get_webauthn_passkey_names_for_user( &self, user_id: i32, ) -> Vec<(i32, String)>; fn get_all_webauthn_passkeys(&self) -> Vec<String>; fn get_all_webauthn_credentials(&self) -> Vec<String>; fn store_webauthn_auth_challenge( &self, challenge: &str, authentication: &str, ) -> i32; fn get_webauthn_auth_challenge_by_id(&self, auth_id: i32) -> Option<String>; fn login( &self, session: Option<&str>, username: &str, password: &str, ) -> Result<String, ()>; fn login_with_code( &self, session: Option<&str>, logincode: &str, ) -> Result<String, ()>; fn login_with_key( &self, session: Option<&str>, cred_id: &str, ) -> Result<String, ()>; fn login_foreign( &self, session: Option<&str>, provider_id: &str, foreign_id: &str, _: (bool, bool, &str, &str, Option<i32>, &Option<String>), ) -> Result<(String, Option<Timespec>), ()>; fn create_user_with_groupcode( &self, session: Option<&str>, groupcode: &str, ) -> Result<String, ()>; fn update_or_create_group_with_users(&self, group: Group, admin: i32); fn add_admin_to_group(&self, group: &mut Group, admin: i32); fn logout(&self, session: &str); fn signup( &self, session_token: &str, username: &str, email: &str, password_hash: String, salt: &str, ) -> SignupResult; fn load_submission( &self, session: &SessionUser, task: i32, subtask: Option<&str>, ) -> Option<Submission>; fn get_all_submissions( &self, session_id: i32, task: i32, subtask: Option<&str>, ) -> Vec<Submission>; fn submit_submission(&self, submission: Submission); fn get_grade_by_submission(&self, submission_id: i32) -> Grade; fn get_contest_groups_grades( &self, session_id: i32, contest_id: i32, ) -> (Vec<String>, Vec<(Group, Vec<(UserInfo, Vec<Grade>)>)>); fn get_taskgroup_user_grade( &self, session_id: i32, taskgroup_id: i32, ) -> Grade; fn get_contest_user_grades( &self, session_id: i32, contest_id: i32, ) -> Vec<Grade>; fn export_contest_results_to_file( &self, contest_id: i32, taskgroups_ids: &[(i32, String)], filename: &str, ); fn insert_contest_annotations( &self, contest_id: i32, annotations: Vec<(i32, Option<String>)>, ) -> i32; fn get_submission_by_id_complete_shallow_contest( &self, submission_id: i32, ) -> Option<(Submission, Task, Taskgroup, Contest)>; fn get_contest_list(&self) -> Vec<Contest>; fn get_contest_list_with_group_member_participations( &self, session_id: i32, ) -> Vec<Contest>; fn get_contest_by_id(&self, contest_id: i32) -> Option<Contest>; fn get_contest_by_id_partial(&self, contest_id: i32) -> Option<Contest>; fn get_contest_by_id_complete(&self, contest_id: i32) -> Option<Contest>; fn get_participation( &self, session_id: i32, contest_id: i32, ) -> Option<Participation>; fn get_own_participation( &self, session_id: i32, contest_id: i32, ) -> Option<Participation>; fn get_all_participations_complete( &self, session_id: i32, ) -> Vec<(Participation, Contest)>; fn count_all_stars(&self, session_id: i32) -> i32; fn count_all_stars_by_contest(&self, session_id: i32) -> Vec<(i32, i32)>; fn has_participation_by_contest_file( &self, session_id: i32, location: &str, filename: &str, ) -> bool; fn new_participation( &self, session_id: i32, contest_id: i32, team: Option<i32>, ) -> Result<Participation, ()>; fn get_task_by_id(&self, task_id: i32) -> Option<Task>; fn get_task_by_id_complete( &self, task_id: i32, ) -> Option<(Task, Taskgroup, Contest)>; fn get_submission_to_validate( &self, tasklocation: &str, subtask: Option<&str>, ) -> i32; fn find_next_submission_to_validate(&self, userid: i32, taskgroupid: i32); fn add_group(&self, group: &mut Group); fn save_group(&self, group: &mut Group); fn get_groups(&self, session_id: i32) -> Vec<Group>; fn get_groups_complete(&self, session_id: i32) -> Vec<Group>; fn get_group(&self, session_id: i32) -> Option<Group>; fn group_has_protected_participations(&self, session_id: i32) -> bool; fn get_group_complete(&self, group_id: i32) -> Option<Group>; fn delete_user(&self, user_id: i32); fn delete_all_users_for_group(&self, group_id: i32); fn delete_group(&self, group_id: i32); fn delete_participation(&self, user_id: i32, contest_id: i32); fn remove_old_users_and_groups( &self, maxstudentage: Timespec, maxteacherage: Option<Timespec>, maxage: Option<Timespec>, ) -> Result<(i32, i32, i32, i32), ()>; fn count_temporary_sessions(&self, maxage: Timespec) -> i32; fn remove_temporary_sessions(&self, maxage: Timespec, limit: Option<u32>); fn get_search_users( &self, _: (Option<i32>, Option<String>, Option<String>, Option<String>, Option<String>, Option<String>), ) -> Result<Vec<(i32, Option<String>, Option<String>, Option<String>, Option<String>, Option<String>)>, Vec<(i32, String, String, String)>>; fn get_debug_information(&self) -> String; fn reset_all_contest_visibilities(&self); fn reset_all_taskgroup_visibilities(&self);
}
Expand description

This trait abstracts the database connection and provides function for all actions to be performed on the database in the medal platform.

Required Methods§

source

fn reconnect(config: &Config) -> Self

source

fn dbtype(&self) -> &'static str

source

fn migration_already_applied(&self, name: &str) -> bool

source

fn apply_migration(&mut self, name: &str, contents: &str)

source

fn code_exists(&self, code: &str) -> bool

source

fn get_session(&self, key: &str) -> Option<SessionUser>

Try to get session associated to the session token key.

Returns an Option that can contain the SessionUser of the session if the session exists and is not expired or None otherwise.

source

fn new_session(&self, key: &str) -> SessionUser

Create a new anonymous session with the session token key.

Returns the SessionUser of the session.

source

fn session_set_activity_dates( &self, session_id: i32, account_created: Option<Timespec>, last_login: Option<Timespec>, last_activity: Option<Timespec>, )

Set activity date (for testing purposes)

source

fn save_session(&self, session: SessionUser)

Saves the session data of session in the database.

source

fn get_session_or_new(&self, key: &str) -> Result<SessionUser, ()>

Combination of get_session and new_session.

This method can still fail in case of database error in order to bubble them up to the webframework

source

fn get_user_by_id(&self, user_id: i32) -> Option<SessionUser>

Try to get session associated to the id user_id.

Returns an Option that can contain the SessionUser of the session if the session exists or None otherwise.

source

fn get_user_and_group_by_id( &self, user_id: i32, ) -> Option<(SessionUser, Option<Group>)>

Try to get session and user group associated to the id user_id.

Returns an Option that can contain a pair of SessionUser and Option<Group> of the session and optionally the group if the session exists or None otherwise.

source

fn get_user_and_group_by_logincode( &self, logincode: &str, ) -> Option<(SessionUser, Option<Group>)>

source

fn set_webauthn_passkey_registration( &self, user_id: i32, passkey_registration: &str, )

source

fn get_webauthn_passkey_registration(&self, user_id: i32) -> Option<String>

source

fn check_webauthn_cred_id_in_use(&self, cred_id: &str) -> bool

source

fn add_webauthn_passkey( &self, user_id: i32, cred_id: &str, passkey: &str, name: &str, ) -> i32

source

fn delete_webauthn_passkey(&self, session_id: i32, passkey_id: i32)

source

fn get_webauthn_passkey_names_for_user( &self, user_id: i32, ) -> Vec<(i32, String)>

source

fn get_all_webauthn_passkeys(&self) -> Vec<String>

source

fn get_all_webauthn_credentials(&self) -> Vec<String>

source

fn store_webauthn_auth_challenge( &self, challenge: &str, authentication: &str, ) -> i32

source

fn get_webauthn_auth_challenge_by_id(&self, auth_id: i32) -> Option<String>

source

fn login( &self, session: Option<&str>, username: &str, password: &str, ) -> Result<String, ()>

Try to login in the user with username and password.

Returns a Result that either contains the new session token for the user if the login was successfull or no value if the login was not successfull.

source

fn login_with_code( &self, session: Option<&str>, logincode: &str, ) -> Result<String, ()>

source

fn login_with_key( &self, session: Option<&str>, cred_id: &str, ) -> Result<String, ()>

source

fn login_foreign( &self, session: Option<&str>, provider_id: &str, foreign_id: &str, _: (bool, bool, &str, &str, Option<i32>, &Option<String>), ) -> Result<(String, Option<Timespec>), ()>

source

fn create_user_with_groupcode( &self, session: Option<&str>, groupcode: &str, ) -> Result<String, ()>

source

fn update_or_create_group_with_users(&self, group: Group, admin: i32)

source

fn add_admin_to_group(&self, group: &mut Group, admin: i32)

source

fn logout(&self, session: &str)

Logs out the user identified by session token session by resetting the uesr’s session token in the database to NULL.

source

fn signup( &self, session_token: &str, username: &str, email: &str, password_hash: String, salt: &str, ) -> SignupResult

source

fn load_submission( &self, session: &SessionUser, task: i32, subtask: Option<&str>, ) -> Option<Submission>

source

fn get_all_submissions( &self, session_id: i32, task: i32, subtask: Option<&str>, ) -> Vec<Submission>

source

fn submit_submission(&self, submission: Submission)

source

fn get_grade_by_submission(&self, submission_id: i32) -> Grade

source

fn get_contest_groups_grades( &self, session_id: i32, contest_id: i32, ) -> (Vec<String>, Vec<(Group, Vec<(UserInfo, Vec<Grade>)>)>)

source

fn get_taskgroup_user_grade(&self, session_id: i32, taskgroup_id: i32) -> Grade

source

fn get_contest_user_grades( &self, session_id: i32, contest_id: i32, ) -> Vec<Grade>

source

fn export_contest_results_to_file( &self, contest_id: i32, taskgroups_ids: &[(i32, String)], filename: &str, )

source

fn insert_contest_annotations( &self, contest_id: i32, annotations: Vec<(i32, Option<String>)>, ) -> i32

source

fn get_submission_by_id_complete_shallow_contest( &self, submission_id: i32, ) -> Option<(Submission, Task, Taskgroup, Contest)>

Returns the submission identified by submission_id, together with its grade, task, taskgroup and contest.

source

fn get_contest_list(&self) -> Vec<Contest>

Returns a Vec of /all/ contests ever defined.

source

fn get_contest_list_with_group_member_participations( &self, session_id: i32, ) -> Vec<Contest>

Returns a Vec of contests where participations exist.

source

fn get_contest_by_id(&self, contest_id: i32) -> Option<Contest>

Returns the contest identified by contest_id without any associated taskgroups. Panics if the contest does not exist.

source

fn get_contest_by_id_partial(&self, contest_id: i32) -> Option<Contest>

Returns the contest identified by contest_id with associated taskgroups but without any associated tasks of the taskgroups. Panics if the contest does not exist.

source

fn get_contest_by_id_complete(&self, contest_id: i32) -> Option<Contest>

Returns the contest identified by contest_id with associated taskgroups and all associated tasks of the taskgroups. Panics if the contest does not exist.

source

fn get_participation( &self, session_id: i32, contest_id: i32, ) -> Option<Participation>

Try to get the participation associated to the session id session_id and the contest id contest_id.

Returns an Option that can contain the Participation if it exists or None otherwise.

source

fn get_own_participation( &self, session_id: i32, contest_id: i32, ) -> Option<Participation>

Try to get the participation associated to the session token session and the contest id contest_id.

Returns an Option that can contain the Participation if it exists or None otherwise.

source

fn get_all_participations_complete( &self, session_id: i32, ) -> Vec<(Participation, Contest)>

Collect all the participation associated to the session token session.

Returns an Vec that contains pairs of all participations with their associated contests.

source

fn count_all_stars(&self, session_id: i32) -> i32

source

fn count_all_stars_by_contest(&self, session_id: i32) -> Vec<(i32, i32)>

source

fn has_participation_by_contest_file( &self, session_id: i32, location: &str, filename: &str, ) -> bool

source

fn new_participation( &self, session_id: i32, contest_id: i32, team: Option<i32>, ) -> Result<Participation, ()>

Start a new participation of the session identified by the session token session for the contest with the contest id contest_id. It checks whether the session is allowed to start the participation.

Returns an Result that either contains the new Participation if the checks succeded or no value if the checks failed.

source

fn get_task_by_id(&self, task_id: i32) -> Option<Task>

source

fn get_task_by_id_complete( &self, task_id: i32, ) -> Option<(Task, Taskgroup, Contest)>

source

fn get_submission_to_validate( &self, tasklocation: &str, subtask: Option<&str>, ) -> i32

source

fn find_next_submission_to_validate(&self, userid: i32, taskgroupid: i32)

source

fn add_group(&self, group: &mut Group)

source

fn save_group(&self, group: &mut Group)

source

fn get_groups(&self, session_id: i32) -> Vec<Group>

source

fn get_groups_complete(&self, session_id: i32) -> Vec<Group>

source

fn get_group(&self, session_id: i32) -> Option<Group>

source

fn group_has_protected_participations(&self, session_id: i32) -> bool

source

fn get_group_complete(&self, group_id: i32) -> Option<Group>

source

fn delete_user(&self, user_id: i32)

source

fn delete_all_users_for_group(&self, group_id: i32)

source

fn delete_group(&self, group_id: i32)

source

fn delete_participation(&self, user_id: i32, contest_id: i32)

source

fn remove_old_users_and_groups( &self, maxstudentage: Timespec, maxteacherage: Option<Timespec>, maxage: Option<Timespec>, ) -> Result<(i32, i32, i32, i32), ()>

source

fn count_temporary_sessions(&self, maxage: Timespec) -> i32

source

fn remove_temporary_sessions(&self, maxage: Timespec, limit: Option<u32>)

source

fn get_search_users( &self, _: (Option<i32>, Option<String>, Option<String>, Option<String>, Option<String>, Option<String>), ) -> Result<Vec<(i32, Option<String>, Option<String>, Option<String>, Option<String>, Option<String>)>, Vec<(i32, String, String, String)>>

source

fn get_debug_information(&self) -> String

source

fn reset_all_contest_visibilities(&self)

source

fn reset_all_taskgroup_visibilities(&self)

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl MedalConnection for Connection

source§

fn reconnect(config: &Config) -> Self

source§

fn dbtype(&self) -> &'static str

source§

fn migration_already_applied(&self, name: &str) -> bool

source§

fn apply_migration(&mut self, name: &str, contents: &str)

source§

fn code_exists(&self, code: &str) -> bool

source§

fn get_session(&self, key: &str) -> Option<SessionUser>

source§

fn save_session(&self, session: SessionUser)

source§

fn new_session(&self, session_token: &str) -> SessionUser

source§

fn session_set_activity_dates( &self, session_id: i32, account_created: Option<Timespec>, last_login: Option<Timespec>, last_activity: Option<Timespec>, )

source§

fn get_session_or_new(&self, key: &str) -> Result<SessionUser, ()>

source§

fn get_user_by_id(&self, user_id: i32) -> Option<SessionUser>

source§

fn get_user_and_group_by_id( &self, user_id: i32, ) -> Option<(SessionUser, Option<Group>)>

source§

fn get_user_and_group_by_logincode( &self, logincode: &str, ) -> Option<(SessionUser, Option<Group>)>

source§

fn set_webauthn_passkey_registration( &self, user_id: i32, passkey_registration: &str, )

source§

fn get_webauthn_passkey_registration(&self, user_id: i32) -> Option<String>

source§

fn check_webauthn_cred_id_in_use(&self, cred_id: &str) -> bool

source§

fn add_webauthn_passkey( &self, user_id: i32, cred_id: &str, passkey: &str, name: &str, ) -> i32

source§

fn delete_webauthn_passkey(&self, user_id: i32, passkey_id: i32)

source§

fn get_webauthn_passkey_names_for_user( &self, user_id: i32, ) -> Vec<(i32, String)>

source§

fn get_all_webauthn_passkeys(&self) -> Vec<String>

source§

fn get_all_webauthn_credentials(&self) -> Vec<String>

source§

fn store_webauthn_auth_challenge( &self, challenge: &str, authentication: &str, ) -> i32

source§

fn get_webauthn_auth_challenge_by_id(&self, auth_id: i32) -> Option<String>

source§

fn login( &self, _session: Option<&str>, username: &str, password: &str, ) -> Result<String, ()>

source§

fn login_with_code( &self, _session: Option<&str>, logincode: &str, ) -> Result<String, ()>

source§

fn login_with_key( &self, _session: Option<&str>, cred_id: &str, ) -> Result<String, ()>

source§

fn login_foreign( &self, _session: Option<&str>, provider_id: &str, foreign_id: &str, (is_teacher, is_admin, firstname, lastname, sex, school_name): (bool, bool, &str, &str, Option<i32>, &Option<String>), ) -> Result<(String, Option<Timespec>), ()>

source§

fn create_user_with_groupcode( &self, _session: Option<&str>, groupcode: &str, ) -> Result<String, ()>

source§

fn update_or_create_group_with_users(&self, group: Group, admin: i32)

source§

fn add_admin_to_group(&self, group: &mut Group, admin: i32)

source§

fn logout(&self, session: &str)

source§

fn signup( &self, session_token: &str, username: &str, email: &str, password_hash: String, salt: &str, ) -> SignupResult

source§

fn load_submission( &self, session: &SessionUser, task: i32, subtask: Option<&str>, ) -> Option<Submission>

source§

fn get_all_submissions( &self, session_id: i32, task: i32, subtask: Option<&str>, ) -> Vec<Submission>

source§

fn submit_submission(&self, submission: Submission)

source§

fn get_grade_by_submission(&self, submission_id: i32) -> Grade

source§

fn get_contest_groups_grades( &self, session_id: i32, contest_id: i32, ) -> (Vec<String>, Vec<(Group, Vec<(UserInfo, Vec<Grade>)>)>)

source§

fn get_contest_user_grades( &self, session_id: i32, contest_id: i32, ) -> Vec<Grade>

source§

fn get_taskgroup_user_grade(&self, session_id: i32, taskgroup_id: i32) -> Grade

source§

fn export_contest_results_to_file( &self, contest_id: i32, taskgroups: &[(i32, String)], filename: &str, )

source§

fn insert_contest_annotations( &self, contest_id: i32, annotations: Vec<(i32, Option<String>)>, ) -> i32

source§

fn get_submission_by_id_complete_shallow_contest( &self, submission_id: i32, ) -> Option<(Submission, Task, Taskgroup, Contest)>

source§

fn get_contest_list(&self) -> Vec<Contest>

source§

fn get_contest_list_with_group_member_participations( &self, session_id: i32, ) -> Vec<Contest>

source§

fn get_contest_by_id(&self, contest_id: i32) -> Option<Contest>

source§

fn get_contest_by_id_complete(&self, contest_id: i32) -> Option<Contest>

source§

fn get_contest_by_id_partial(&self, contest_id: i32) -> Option<Contest>

source§

fn get_participation( &self, session_id: i32, contest_id: i32, ) -> Option<Participation>

source§

fn get_own_participation( &self, session_id: i32, contest_id: i32, ) -> Option<Participation>

source§

fn get_all_participations_complete( &self, session_id: i32, ) -> Vec<(Participation, Contest)>

source§

fn count_all_stars(&self, session_id: i32) -> i32

source§

fn count_all_stars_by_contest(&self, session_id: i32) -> Vec<(i32, i32)>

source§

fn has_participation_by_contest_file( &self, session_id: i32, location: &str, filename: &str, ) -> bool

source§

fn new_participation( &self, session_id: i32, contest_id: i32, team: Option<i32>, ) -> Result<Participation, ()>

source§

fn get_task_by_id(&self, task_id: i32) -> Option<Task>

source§

fn get_task_by_id_complete( &self, task_id: i32, ) -> Option<(Task, Taskgroup, Contest)>

source§

fn get_submission_to_validate( &self, tasklocation: &str, subtask: Option<&str>, ) -> i32

source§

fn find_next_submission_to_validate(&self, userid: i32, taskgroupid: i32)

source§

fn add_group(&self, group: &mut Group)

source§

fn save_group(&self, group: &mut Group)

source§

fn get_groups(&self, session_id: i32) -> Vec<Group>

source§

fn get_groups_complete(&self, _session_id: i32) -> Vec<Group>

source§

fn get_group(&self, group_id: i32) -> Option<Group>

source§

fn group_has_protected_participations(&self, group_id: i32) -> bool

source§

fn get_group_complete(&self, group_id: i32) -> Option<Group>

source§

fn delete_user(&self, user_id: i32)

source§

fn delete_all_users_for_group(&self, group_id: i32)

source§

fn delete_group(&self, group_id: i32)

source§

fn delete_participation(&self, user_id: i32, contest_id: i32)

source§

fn get_search_users( &self, (s_id, s_firstname, s_lastname, s_logincode, s_groupcode, s_pms_id): (Option<i32>, Option<String>, Option<String>, Option<String>, Option<String>, Option<String>), ) -> Result<Vec<(i32, Option<String>, Option<String>, Option<String>, Option<String>, Option<String>)>, Vec<(i32, String, String, String)>>

source§

fn remove_old_users_and_groups( &self, maxstudentage: Timespec, maxteacherage: Option<Timespec>, maxage: Option<Timespec>, ) -> Result<(i32, i32, i32, i32), ()>

source§

fn count_temporary_sessions(&self, maxage: Timespec) -> i32

source§

fn remove_temporary_sessions(&self, maxage: Timespec, limit: Option<u32>)

source§

fn get_debug_information(&self) -> String

source§

fn reset_all_contest_visibilities(&self)

source§

fn reset_all_taskgroup_visibilities(&self)

Implementors§