From 9d8069d70d154d1666ca8cad669fa9c20e0d8885 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 28 May 2024 16:22:15 +0200 Subject: [PATCH] refactor: [#448] remove user_authorization type and related methods --- src/databases/database.rs | 5 +---- src/databases/mysql.rs | 10 +--------- src/databases/sqlite.rs | 10 +--------- src/models/user.rs | 7 ------- 4 files changed, 3 insertions(+), 29 deletions(-) diff --git a/src/databases/database.rs b/src/databases/database.rs index 378101fc..a19970be 100644 --- a/src/databases/database.rs +++ b/src/databases/database.rs @@ -11,7 +11,7 @@ use crate::models::torrent::{Metadata, TorrentListing}; use crate::models::torrent_file::{DbTorrent, Torrent, TorrentFile}; use crate::models::torrent_tag::{TagId, TorrentTag}; use crate::models::tracker_key::TrackerKey; -use crate::models::user::{User, UserAuthentication, UserAuthorization, UserCompact, UserId, UserProfile}; +use crate::models::user::{User, UserAuthentication, UserCompact, UserId, UserProfile}; use crate::services::torrent::CanonicalInfoHashGroup; /// Database tables to be truncated when upgrading from v1.0.0 to v2.0.0. @@ -136,9 +136,6 @@ pub trait Database: Sync + Send { /// Get `UserAuthentication` from `user_id`. async fn get_user_authentication_from_id(&self, user_id: UserId) -> Result; - /// Get `UserAuthorization` from `user_id`. - async fn get_user_authorization_from_id(&self, user_id: UserId) -> Result; - /// Get `UserProfile` from `username`. async fn get_user_profile_from_username(&self, username: &str) -> Result; diff --git a/src/databases/mysql.rs b/src/databases/mysql.rs index 837a689e..d28f1ae7 100644 --- a/src/databases/mysql.rs +++ b/src/databases/mysql.rs @@ -18,7 +18,7 @@ use crate::models::torrent_file::{ }; use crate::models::torrent_tag::{TagId, TorrentTag}; use crate::models::tracker_key::TrackerKey; -use crate::models::user::{User, UserAuthentication, UserAuthorization, UserCompact, UserId, UserProfile}; +use crate::models::user::{User, UserAuthentication, UserCompact, UserId, UserProfile}; use crate::services::torrent::{CanonicalInfoHashGroup, DbTorrentInfoHash}; use crate::utils::clock::{self, datetime_now, DATETIME_FORMAT}; use crate::utils::hex::from_bytes; @@ -129,14 +129,6 @@ impl Database for Mysql { .map_err(|_| database::Error::UserNotFound) } - async fn get_user_authorization_from_id(&self, user_id: UserId) -> Result { - query_as::<_, UserAuthorization>("SELECT user_id, administrator FROM torrust_users WHERE user_id = ?") - .bind(user_id) - .fetch_one(&self.pool) - .await - .map_err(|_| database::Error::UserNotFound) - } - async fn get_user_profile_from_username(&self, username: &str) -> Result { query_as::<_, UserProfile>(r#"SELECT user_id, username, COALESCE(email, "") as email, email_verified, COALESCE(bio, "") as bio, COALESCE(avatar, "") as avatar FROM torrust_user_profiles WHERE username = ?"#) .bind(username) diff --git a/src/databases/sqlite.rs b/src/databases/sqlite.rs index 733d7e77..421292d6 100644 --- a/src/databases/sqlite.rs +++ b/src/databases/sqlite.rs @@ -18,7 +18,7 @@ use crate::models::torrent_file::{ }; use crate::models::torrent_tag::{TagId, TorrentTag}; use crate::models::tracker_key::TrackerKey; -use crate::models::user::{User, UserAuthentication, UserAuthorization, UserCompact, UserId, UserProfile}; +use crate::models::user::{User, UserAuthentication, UserCompact, UserId, UserProfile}; use crate::services::torrent::{CanonicalInfoHashGroup, DbTorrentInfoHash}; use crate::utils::clock::{self, datetime_now, DATETIME_FORMAT}; use crate::utils::hex::from_bytes; @@ -130,14 +130,6 @@ impl Database for Sqlite { .map_err(|_| database::Error::UserNotFound) } - async fn get_user_authorization_from_id(&self, user_id: UserId) -> Result { - query_as::<_, UserAuthorization>("SELECT user_id, administrator FROM torrust_users WHERE user_id = ?") - .bind(user_id) - .fetch_one(&self.pool) - .await - .map_err(|_| database::Error::UserNotFound) - } - async fn get_user_profile_from_username(&self, username: &str) -> Result { query_as::<_, UserProfile>("SELECT * FROM torrust_user_profiles WHERE username = ?") .bind(username) diff --git a/src/models/user.rs b/src/models/user.rs index 0995cdbb..8347357c 100644 --- a/src/models/user.rs +++ b/src/models/user.rs @@ -22,13 +22,6 @@ pub struct UserAuthentication { pub password_hash: String, } -#[allow(clippy::module_name_repetitions)] -#[derive(Debug, Serialize, Deserialize, Clone, sqlx::FromRow)] -pub struct UserAuthorization { - pub user_id: UserId, - pub administrator: bool, -} - #[allow(clippy::module_name_repetitions)] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, sqlx::FromRow)] pub struct UserProfile {