@@ -10,21 +10,21 @@ use std::sync::Arc;
1010
1111use bytes:: Bytes ;
1212
13+ use super :: authorization:: { self , ACTION } ;
1314use crate :: cache:: image:: manager:: { Error , ImageCacheService } ;
1415use crate :: models:: user:: UserId ;
15- use crate :: services:: user:: Repository ;
1616
1717pub struct Service {
1818 image_cache_service : Arc < ImageCacheService > ,
19- user_repository : Arc < Box < dyn Repository > > ,
19+ authorization_service : Arc < authorization :: Service > ,
2020}
2121
2222impl Service {
2323 #[ must_use]
24- pub fn new ( image_cache_service : Arc < ImageCacheService > , user_repository : Arc < Box < dyn Repository > > ) -> Self {
24+ pub fn new ( image_cache_service : Arc < ImageCacheService > , authorization_service : Arc < authorization :: Service > ) -> Self {
2525 Self {
2626 image_cache_service,
27- user_repository ,
27+ authorization_service ,
2828 }
2929 }
3030
@@ -39,8 +39,11 @@ impl Service {
3939 /// * The image is too big.
4040 /// * The user quota is met.
4141 pub async fn get_image_by_url ( & self , url : & str , user_id : & UserId ) -> Result < Bytes , Error > {
42- let user = self . user_repository . get_compact ( user_id) . await . ok ( ) ;
42+ self . authorization_service
43+ . authorize ( ACTION :: GetImageByUrl , Some ( * user_id) )
44+ . await
45+ . map_err ( |_| Error :: Unauthenticated ) ?;
4346
44- self . image_cache_service . get_image_by_url ( url, user ) . await
47+ self . image_cache_service . get_image_by_url ( url, * user_id ) . await
4548 }
4649}
0 commit comments