@@ -11,6 +11,7 @@ use pbkdf2::password_hash::rand_core::OsRng;
11
11
use tracing:: { debug, info} ;
12
12
13
13
use super :: authentication:: DbUserAuthenticationRepository ;
14
+ use super :: authorization:: { self , ACTION } ;
14
15
use crate :: config:: { Configuration , EmailOnSignup , PasswordConstraints } ;
15
16
use crate :: databases:: database:: { Database , Error } ;
16
17
use crate :: errors:: ServiceError ;
@@ -237,22 +238,22 @@ impl ProfileService {
237
238
}
238
239
239
240
pub struct BanService {
240
- user_repository : Arc < Box < dyn Repository > > ,
241
241
user_profile_repository : Arc < DbUserProfileRepository > ,
242
242
banned_user_list : Arc < DbBannedUserList > ,
243
+ authorization_service : Arc < authorization:: Service > ,
243
244
}
244
245
245
246
impl BanService {
246
247
#[ must_use]
247
248
pub fn new (
248
- user_repository : Arc < Box < dyn Repository > > ,
249
249
user_profile_repository : Arc < DbUserProfileRepository > ,
250
250
banned_user_list : Arc < DbBannedUserList > ,
251
+ authorization_service : Arc < authorization:: Service > ,
251
252
) -> Self {
252
253
Self {
253
- user_repository,
254
254
user_profile_repository,
255
255
banned_user_list,
256
+ authorization_service,
256
257
}
257
258
}
258
259
@@ -268,12 +269,7 @@ impl BanService {
268
269
pub async fn ban_user ( & self , username_to_be_banned : & str , user_id : & UserId ) -> Result < ( ) , ServiceError > {
269
270
debug ! ( "user with ID {user_id} banning username: {username_to_be_banned}" ) ;
270
271
271
- let user = self . user_repository . get_compact ( user_id) . await ?;
272
-
273
- // Check if user is administrator
274
- if !user. administrator {
275
- return Err ( ServiceError :: Unauthorized ) ;
276
- }
272
+ self . authorization_service . authorize ( ACTION :: BanUser , Some ( * user_id) ) . await ?;
277
273
278
274
let user_profile = self
279
275
. user_profile_repository
0 commit comments