Skip to content

Commit

Permalink
refactor: [torrust#448] fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-nt committed Mar 20, 2024
1 parent 37e3eb9 commit c5bbf9f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/services/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DbUserAuthorizationRepository>,
}

impl AuthorizationService {
impl AuthorizeService {
#[must_use]
pub fn new(user_authorization_repository: Arc<DbUserAuthorizationRepository>) -> 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
Expand All @@ -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 {
Expand Down

0 comments on commit c5bbf9f

Please sign in to comment.