Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing authorization logic in the get_site method of the settings service #719

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(),
}
}
Loading