Skip to content

Commit

Permalink
feat: [#615] authorization layer implemented for the get torrent meth…
Browse files Browse the repository at this point in the history
…od of the torrent service
  • Loading branch information
mario-nt committed Aug 3, 2024
1 parent b5171bf commit 7bb6ff7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/services/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub enum ACTION {
GetLicensePage,
GetImageByUrl,
GetPublicSettings,
GetTorrent,
AddTorrent,
}

Expand Down Expand Up @@ -185,17 +186,20 @@ impl CasbinConfiguration {
admin, DeleteTorrent
admin, BanUser
admin, GetImageByUrl
admin, GetTorrent
admin, AddTorrent
registered, GetCategories
registered, GetImageByUrl
registered, GetPublicSettings
registered, GetTags
registered, GetTorrent
registered, AddTorrent
guest, GetCategories
guest, GetTags
guest, GetAboutPage
guest, GetLicensePage
guest, GetPublicSettings
guest, GetTorrent
",
),
}
Expand Down
2 changes: 2 additions & 0 deletions src/services/torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ impl Index {
/// This function will return an error if unable to get the torrent from the
/// database.
pub async fn get_torrent(&self, info_hash: &InfoHash, opt_user_id: Option<UserId>) -> Result<Torrent, ServiceError> {
self.authorization_service.authorize(ACTION::GetTorrent, opt_user_id).await?;

let mut torrent = self.torrent_repository.get_by_info_hash(info_hash).await?;

let tracker_url = self.get_tracker_url().await;
Expand Down

0 comments on commit 7bb6ff7

Please sign in to comment.