Skip to content

Commit

Permalink
Merge #719: Missing authorization logic in the get_site method of the…
Browse files Browse the repository at this point in the history
… settings service

ef72487 feat: added authorization logic to the get_site method (Mario)

Pull request description:

ACKs for top commit:
  josecelano:
    ACK ef72487

Tree-SHA512: 80f73f81533276c3b179ee7f568713d5ff39b5f059eea167cbd040a827a1e352ee4fa759466d694168b2d086a71fbd8a3bc745d987f5cc8567adeacb94d5f550
  • Loading branch information
josecelano committed Aug 20, 2024
2 parents 146cd54 + ef72487 commit ba52eed
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/services/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub enum ACTION {
GetSettings,
GetSettingsSecret,
GetPublicSettings,
GetSiteName,
AddTag,
DeleteTag,
GetTags,
Expand Down Expand Up @@ -236,6 +237,7 @@ impl Default for CasbinConfiguration {
admin, GetSettings
admin, GetSettingsSecret
admin, GetPublicSettings
admin, GetSiteName
admin, AddTag
admin, DeleteTag
admin, GetTags
Expand All @@ -252,6 +254,7 @@ impl Default for CasbinConfiguration {
registered, GetCategories
registered, GetImageByUrl
registered, GetPublicSettings
registered, GetSiteName
registered, GetTags
registered, AddTorrent
registered, GetTorrent
Expand All @@ -263,6 +266,7 @@ impl Default for CasbinConfiguration {
guest, GetLicensePage
guest, GetCategories
guest, GetPublicSettings
guest, GetSiteName
guest, GetTags
guest, GetTorrent
guest, GetTorrentInfo
Expand Down
8 changes: 6 additions & 2 deletions src/services/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ impl Service {
/// # Errors
///
/// It returns an error if the user does not have the required permissions.
pub async fn get_site_name(&self) -> String {
self.configuration.get_site_name().await
pub async fn get_site_name(&self, maybe_user_id: Option<UserId>) -> Result<String, ServiceError> {
self.authorization_service
.authorize(ACTION::GetSiteName, maybe_user_id)
.await?;

Ok(self.configuration.get_site_name().await)
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/web/api/server/v1/contexts/settings/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ pub async fn get_public_handler(

/// Get website name.
#[allow(clippy::unused_async)]
pub async fn get_site_name_handler(State(app_data): State<Arc<AppData>>) -> Response {
let site_name = app_data.settings_service.get_site_name().await;

Json(responses::OkResponseData { data: site_name }).into_response()
pub async fn get_site_name_handler(
State(app_data): State<Arc<AppData>>,
ExtractOptionalLoggedInUser(maybe_user_id): ExtractOptionalLoggedInUser,
) -> Response {
match app_data.settings_service.get_site_name(maybe_user_id).await {
Ok(site_name) => Json(responses::OkResponseData { data: site_name }).into_response(),
Err(error) => error.into_response(),
}
}

0 comments on commit ba52eed

Please sign in to comment.