Commit 2880f7c 1 parent 530f37a commit 2880f7c Copy full SHA for 2880f7c
File tree 3 files changed +19
-7
lines changed
web/api/server/v1/contexts/settings
3 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ pub enum ACTION {
44
44
GetAboutPage ,
45
45
GetLicensePage ,
46
46
GetImageByUrl ,
47
+ GetPublicSettings ,
47
48
}
48
49
49
50
pub struct Service {
@@ -174,18 +175,20 @@ impl CasbinConfiguration {
174
175
"
175
176
admin, AddCategory
176
177
admin, DeleteCategory
177
- admin, GetSettings
178
+ admin, GetPublicSettings
178
179
admin, GetSettingsSecret
179
180
admin, AddTag
180
181
admin, DeleteTag
181
182
admin, DeleteTorrent
182
183
admin, BanUser
183
184
admin, GetImageByUrl
184
185
registered, GetImageByUrl
186
+ registered, GetPublicSettings
185
187
guest, GetCategories
186
188
guest, GetTags
187
189
guest, GetAboutPage
188
190
guest, GetLicensePage
191
+ guest, GetPublicSettings
189
192
" ,
190
193
) ,
191
194
}
Original file line number Diff line number Diff line change @@ -62,9 +62,13 @@ impl Service {
62
62
/// # Errors
63
63
///
64
64
/// 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
+
66
70
let settings_lock = self . configuration . get_all ( ) . await ;
67
- extract_public_settings ( & settings_lock)
71
+ Ok ( extract_public_settings ( & settings_lock) )
68
72
}
69
73
70
74
/// 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;
6
6
use axum:: response:: { IntoResponse , Json , Response } ;
7
7
8
8
use crate :: common:: AppData ;
9
+ use crate :: web:: api:: server:: v1:: extractors:: optional_user_id:: ExtractOptionalLoggedInUser ;
9
10
use crate :: web:: api:: server:: v1:: extractors:: user_id:: ExtractLoggedInUser ;
10
11
use crate :: web:: api:: server:: v1:: responses;
11
12
@@ -30,10 +31,14 @@ pub async fn get_all_handler(
30
31
31
32
/// Get public Settings.
32
33
#[ 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
+ }
37
42
}
38
43
39
44
/// Get website name.
You can’t perform that action at this time.
0 commit comments