Skip to content

Commit

Permalink
refactor: [torrust#448] remove user_authorization type and related me…
Browse files Browse the repository at this point in the history
…thods
  • Loading branch information
mario-nt committed May 28, 2024
1 parent a9a461e commit 9d8069d
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 29 deletions.
5 changes: 1 addition & 4 deletions src/databases/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<UserAuthentication, Error>;

/// Get `UserAuthorization` from `user_id`.
async fn get_user_authorization_from_id(&self, user_id: UserId) -> Result<UserAuthorization, Error>;

/// Get `UserProfile` from `username`.
async fn get_user_profile_from_username(&self, username: &str) -> Result<UserProfile, Error>;

Expand Down
10 changes: 1 addition & 9 deletions src/databases/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<UserAuthorization, database::Error> {
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<UserProfile, database::Error> {
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)
Expand Down
10 changes: 1 addition & 9 deletions src/databases/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<UserAuthorization, database::Error> {
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<UserProfile, database::Error> {
query_as::<_, UserProfile>("SELECT * FROM torrust_user_profiles WHERE username = ?")
.bind(username)
Expand Down
7 changes: 0 additions & 7 deletions src/models/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9d8069d

Please sign in to comment.