diff --git a/src/app.rs b/src/app.rs index d7ad62da..b0f23b3e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -9,7 +9,7 @@ use crate::common::AppData; use crate::config::Configuration; use crate::databases::database; use crate::services::authentication::{DbUserAuthenticationRepository, JsonWebToken, Service}; -use crate::services::authorization::{AuthorizationService, DbUserAuthorizationRepository}; +use crate::services::authorization::{AuthorizeService, DbUserAuthorizationRepository}; use crate::services::category::{self, DbCategoryRepository}; use crate::services::tag::{self, DbTagRepository}; use crate::services::torrent::{ @@ -85,7 +85,7 @@ pub async fn run(configuration: Configuration, api_version: &Version) -> Running let banned_user_list = Arc::new(DbBannedUserList::new(database.clone())); // Services - let authorization_service = Arc::new(AuthorizationService::new(user_authorization_repository.clone())); + let authorization_service = Arc::new(AuthorizeService::new(user_authorization_repository.clone())); let tracker_service = Arc::new(tracker::service::Service::new(configuration.clone(), database.clone()).await); let tracker_statistics_importer = Arc::new(StatisticsImporter::new(configuration.clone(), tracker_service.clone(), database.clone()).await); diff --git a/src/common.rs b/src/common.rs index fa0763fa..193298ff 100644 --- a/src/common.rs +++ b/src/common.rs @@ -4,7 +4,7 @@ use crate::cache::image::manager::ImageCacheService; use crate::config::Configuration; use crate::databases::database::Database; use crate::services::authentication::{DbUserAuthenticationRepository, JsonWebToken, Service}; -use crate::services::authorization::{AuthorizationService, DbUserAuthorizationRepository}; +use crate::services::authorization::{AuthorizeService, DbUserAuthorizationRepository}; use crate::services::category::{self, DbCategoryRepository}; use crate::services::tag::{self, DbTagRepository}; use crate::services::torrent::{ @@ -24,7 +24,7 @@ pub struct AppData { pub json_web_token: Arc, pub auth: Arc, pub authentication_service: Arc, - pub authorization_service: Arc, + pub authorization_service: Arc, pub tracker_service: Arc, pub tracker_statistics_importer: Arc, pub mailer: Arc, @@ -62,7 +62,7 @@ impl AppData { json_web_token: Arc, auth: Arc, authentication_service: Arc, - authorization_service: Arc, + authorization_service: Arc, tracker_service: Arc, tracker_statistics_importer: Arc, mailer: Arc, diff --git a/src/services/authorization.rs b/src/services/authorization.rs index 58dda9cf..b653376d 100644 --- a/src/services/authorization.rs +++ b/src/services/authorization.rs @@ -4,17 +4,25 @@ use crate::databases::database::{Database, Error}; use crate::errors::ServiceError; use crate::models::user::{UserAuthorization, UserId}; -pub struct AuthorizationService { +pub struct AuthorizeService { user_authorization_repository: Arc, } -impl AuthorizationService { +impl AuthorizeService { + #[must_use] pub fn new(user_authorization_repository: Arc) -> Self { Self { user_authorization_repository, } } + /// Checks if the user has the right privileges to perform the requested action. + /// + /// # Errors + /// + /// This function will return an error if unable to get the user + /// authorization data from the database or if the user + /// does not have the right privileges to perform the action. pub async fn authorize_user(&self, user_id: UserId, admin_required: bool) -> Result<(), ServiceError> { // Checks if the user exists in the database let authorization_info = self @@ -24,13 +32,13 @@ impl AuthorizationService { //If admin privilages are required, it checks if the user is an admin if admin_required { - return self.authorize_admin_user(authorization_info).await; + self.authorize_admin_user(authorization_info).await; } else { Ok(()) } } - async fn authorize_admin_user(&self, user_authorization_info: UserAuthorization) -> Result<(), ServiceError> { + fn authorize_admin_user(&self, user_authorization_info: UserAuthorization) -> Result<(), ServiceError> { if user_authorization_info.administrator { Ok(()) } else { diff --git a/src/services/category.rs b/src/services/category.rs index db1ac4e8..628b594a 100644 --- a/src/services/category.rs +++ b/src/services/category.rs @@ -1,7 +1,7 @@ //! Category service. use std::sync::Arc; -use super::authorization::AuthorizationService; +use super::authorization::AuthorizeService; use crate::databases::database::{Category, Database, Error as DatabaseError}; use crate::errors::ServiceError; use crate::models::category::CategoryId; @@ -9,12 +9,12 @@ use crate::models::user::UserId; pub struct Service { category_repository: Arc, - authorization_service: Arc, + authorization_service: Arc, } impl Service { #[must_use] - pub fn new(category_repository: Arc, authorization_service: Arc) -> Service { + pub fn new(category_repository: Arc, authorization_service: Arc) -> Service { Service { category_repository, authorization_service, diff --git a/src/services/settings.rs b/src/services/settings.rs index 61b07443..248cb381 100644 --- a/src/services/settings.rs +++ b/src/services/settings.rs @@ -1,19 +1,19 @@ //! Settings service. use std::sync::Arc; -use super::authorization::AuthorizationService; +use super::authorization::AuthorizeService; use crate::config::{Configuration, ConfigurationPublic, TorrustIndex}; use crate::errors::ServiceError; use crate::models::user::UserId; pub struct Service { configuration: Arc, - authorization_service: Arc, + authorization_service: Arc, } impl Service { #[must_use] - pub fn new(configuration: Arc, authorization_service: Arc) -> Service { + pub fn new(configuration: Arc, authorization_service: Arc) -> Service { Service { configuration, authorization_service, diff --git a/src/services/tag.rs b/src/services/tag.rs index 08916dd5..7bd15e0f 100644 --- a/src/services/tag.rs +++ b/src/services/tag.rs @@ -1,7 +1,7 @@ //! Tag service. use std::sync::Arc; -use super::authorization::AuthorizationService; +use super::authorization::AuthorizeService; use crate::databases::database::{Database, Error as DatabaseError, Error}; use crate::errors::ServiceError; use crate::models::torrent_tag::{TagId, TorrentTag}; @@ -9,12 +9,12 @@ use crate::models::user::UserId; pub struct Service { tag_repository: Arc, - authorization_service: Arc, + authorization_service: Arc, } impl Service { #[must_use] - pub fn new(tag_repository: Arc, authorization_service: Arc) -> Service { + pub fn new(tag_repository: Arc, authorization_service: Arc) -> Service { Service { tag_repository, authorization_service,