Skip to content

Commit

Permalink
feat: [#615] authorization layer added to the get torrent info method…
Browse files Browse the repository at this point in the history
… of the torrent service
  • Loading branch information
mario-nt committed Aug 3, 2024
1 parent 1342dce commit f8e7570
Show file tree
Hide file tree
Showing 2 changed files with 8 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 @@ -49,6 +49,7 @@ pub enum ACTION {
AddTorrent,
GetCanonicalInfoHash,
GenerateTorrentInfoListing,
GetTorrentInfo,
}

pub struct Service {
Expand Down Expand Up @@ -192,6 +193,7 @@ impl CasbinConfiguration {
admin, AddTorrent
admin, GetCanonicalInfoHash
admin, GenerateTorrentInfoListing
admin, GetTorrentInfo
registered, GetCategories
registered, GetImageByUrl
registered, GetPublicSettings
Expand All @@ -200,6 +202,7 @@ impl CasbinConfiguration {
registered, AddTorrent
registered, GetCanonicalInfoHash
registered, GenerateTorrentInfoListing
registered, GetTorrentInfo
guest, GetCategories
guest, GetTags
guest, GetAboutPage
Expand All @@ -208,6 +211,7 @@ impl CasbinConfiguration {
guest, GetTorrent
guest, GetCanonicalInfoHash
guest, GenerateTorrentInfoListing
guest, GetTorrentInfo
",
),
}
Expand Down
4 changes: 4 additions & 0 deletions src/services/torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ impl Index {
info_hash: &InfoHash,
opt_user_id: Option<UserId>,
) -> Result<TorrentResponse, ServiceError> {
self.authorization_service
.authorize(ACTION::GetTorrentInfo, opt_user_id)
.await?;

let torrent_listing = self.torrent_listing_generator.one_torrent_by_info_hash(info_hash).await?;

let torrent_response = self
Expand Down

0 comments on commit f8e7570

Please sign in to comment.