Skip to content

Commit 3d2f6e5

Browse files
committed
feat: [torrust#448] new authorization service
1 parent d170247 commit 3d2f6e5

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/services/authorization.rs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
3+
4+
let user_compact = self.user_repository.get_compact(&user_profile.user_id).await?;
5+
6+
7+
*/
8+
use std::sync::Arc;
9+
10+
use crate::databases::database::{Database, Error};
11+
use crate::models::user::{UserAuthorization, UserId};
12+
use crate::services::user::DbUserRepository;
13+
pub struct Service {
14+
user_repository: Arc<DbUserRepository>,
15+
}
16+
17+
impl Service {
18+
pub fn new(user_repository: Arc<DbUserRepository>) -> Self {
19+
Self { user_repository }
20+
}
21+
22+
// Check user exists in database
23+
/* pub async fn user_exists_in_database(&self, user_id: &UserId) -> {
24+
let user_authorization = self.
25+
} */
26+
27+
// Check if the user has a role with enough privilages
28+
29+
//Delete token from localStorage if user does not exist - FRONTEND
30+
}
31+
32+
pub struct DbUserAuthorizationRepository {
33+
database: Arc<Box<dyn Database>>,
34+
}
35+
36+
impl DbUserAuthorizationRepository {
37+
#[must_use]
38+
pub fn new(database: Arc<Box<dyn Database>>) -> Self {
39+
Self { database }
40+
}
41+
42+
/// Get user authorization data from user id.
43+
///
44+
/// # Errors
45+
///
46+
/// This function will return an error if unable to get the user
47+
/// authorization data from the database.
48+
pub async fn get_user_authorization_from_id(&self, user_id: &UserId) -> Result<UserAuthorization, Error> {
49+
self.database.get_user_authorization_from_id(*user_id).await
50+
}
51+
}

src/services/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! App services.
22
pub mod about;
33
pub mod authentication;
4+
pub mod authorization;
45
pub mod category;
56
pub mod hasher;
67
pub mod proxy;

0 commit comments

Comments
 (0)