File tree Expand file tree Collapse file tree 3 files changed +19
-7
lines changed
web/api/server/v1/contexts/settings Expand file tree Collapse file tree 3 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ pub enum ACTION {
4444 GetAboutPage ,
4545 GetLicensePage ,
4646 GetImageByUrl ,
47+ GetPublicSettings ,
4748}
4849
4950pub struct Service {
@@ -174,18 +175,20 @@ impl CasbinConfiguration {
174175 "
175176 admin, AddCategory
176177 admin, DeleteCategory
177- admin, GetSettings
178+ admin, GetPublicSettings
178179 admin, GetSettingsSecret
179180 admin, AddTag
180181 admin, DeleteTag
181182 admin, DeleteTorrent
182183 admin, BanUser
183184 admin, GetImageByUrl
184185 registered, GetImageByUrl
186+ registered, GetPublicSettings
185187 guest, GetCategories
186188 guest, GetTags
187189 guest, GetAboutPage
188190 guest, GetLicensePage
191+ guest, GetPublicSettings
189192 " ,
190193 ) ,
191194 }
Original file line number Diff line number Diff line change @@ -62,9 +62,13 @@ impl Service {
6262 /// # Errors
6363 ///
6464 /// It returns an error if the user does not have the required permissions.
65- pub async fn get_public ( & self ) -> ConfigurationPublic {
65+ pub async fn get_public ( & self , opt_user_id : Option < UserId > ) -> Result < ConfigurationPublic , ServiceError > {
66+ self . authorization_service
67+ . authorize ( ACTION :: GetPublicSettings , opt_user_id)
68+ . await ?;
69+
6670 let settings_lock = self . configuration . get_all ( ) . await ;
67- extract_public_settings ( & settings_lock)
71+ Ok ( extract_public_settings ( & settings_lock) )
6872 }
6973
7074 /// It gets the site name from the settings.
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use axum::extract::State;
66use axum:: response:: { IntoResponse , Json , Response } ;
77
88use crate :: common:: AppData ;
9+ use crate :: web:: api:: server:: v1:: extractors:: optional_user_id:: ExtractOptionalLoggedInUser ;
910use crate :: web:: api:: server:: v1:: extractors:: user_id:: ExtractLoggedInUser ;
1011use crate :: web:: api:: server:: v1:: responses;
1112
@@ -30,10 +31,14 @@ pub async fn get_all_handler(
3031
3132/// Get public Settings.
3233#[ allow( clippy:: unused_async) ]
33- pub async fn get_public_handler ( State ( app_data) : State < Arc < AppData > > ) -> Response {
34- let public_settings = app_data. settings_service . get_public ( ) . await ;
35-
36- Json ( responses:: OkResponseData { data : public_settings } ) . into_response ( )
34+ pub async fn get_public_handler (
35+ State ( app_data) : State < Arc < AppData > > ,
36+ ExtractOptionalLoggedInUser ( opt_user_id) : ExtractOptionalLoggedInUser ,
37+ ) -> Response {
38+ match app_data. settings_service . get_public ( opt_user_id) . await {
39+ Ok ( public_settings) => Json ( responses:: OkResponseData { data : public_settings } ) . into_response ( ) ,
40+ Err ( error) => error. into_response ( ) ,
41+ }
3742}
3843
3944/// Get website name.
You can’t perform that action at this time.
0 commit comments