Skip to content

Commit

Permalink
feat: [#615] authorization layer added for add torrent method of the …
Browse files Browse the repository at this point in the history
…torrent service
  • Loading branch information
mario-nt committed Aug 3, 2024
1 parent 1c607c2 commit b5171bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 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,
AddTorrent,
}

pub struct Service {
Expand Down Expand Up @@ -184,10 +185,12 @@ impl CasbinConfiguration {
admin, DeleteTorrent
admin, BanUser
admin, GetImageByUrl
admin, AddTorrent
registered, GetCategories
registered, GetImageByUrl
registered, GetPublicSettings
registered, GetTags
registered, AddTorrent
guest, GetCategories
guest, GetTags
guest, GetAboutPage
Expand Down
5 changes: 3 additions & 2 deletions src/services/torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ impl Index {
add_torrent_req: AddTorrentRequest,
user_id: UserId,
) -> Result<AddTorrentResponse, ServiceError> {
// Guard that the users exists
let _user = self.user_repository.get_compact(&user_id).await?;
self.authorization_service
.authorize(ACTION::AddTorrent, Some(user_id))
.await?;

let metadata = self.validate_and_build_metadata(&add_torrent_req).await?;

Expand Down

0 comments on commit b5171bf

Please sign in to comment.