Skip to content

Commit 9b5cf45

Browse files
committed
feat: [#658] new users listing service
1 parent f48c4a2 commit 9b5cf45

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/services/authorization.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub enum ACTION {
5252
GetCanonicalInfoHash,
5353
ChangePassword,
5454
BanUser,
55+
GetUsers,
5556
}
5657

5758
pub struct Service {
@@ -248,6 +249,7 @@ impl Default for CasbinConfiguration {
248249
admin, GetCanonicalInfoHash
249250
admin, ChangePassword
250251
admin, BanUser
252+
admin, GetUsers
251253
registered, GetAboutPage
252254
registered, GetLicensePage
253255
registered, GetCategories

src/services/user.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,28 @@ impl BanService {
321321
}
322322
}
323323

324+
pub struct ListingService {
325+
user_profile_repository: Arc<DbUserProfileRepository>,
326+
authorization_service: Arc<authorization::Service>,
327+
}
328+
329+
impl ListingService {
330+
/// Gets all users.
331+
///
332+
/// # Errors
333+
///
334+
/// This function will return a:
335+
///
336+
/// * There is a database error retrieving the users
337+
pub async fn get_all(&self, maybe_user_id: Option<UserId>) -> Result<Vec<UserProfile>, ServiceError> {
338+
self.authorization_service.authorize(ACTION::GetUsers, maybe_user_id).await?;
339+
340+
let users = self.user_profile_repository.get_all_user_profiles().await?;
341+
342+
Ok(users)
343+
}
344+
}
345+
324346
#[cfg_attr(test, automock)]
325347
#[async_trait]
326348
pub trait Repository: Sync + Send {

0 commit comments

Comments
 (0)