Skip to content

Commit

Permalink
Don't allow download of archived files
Browse files Browse the repository at this point in the history
  • Loading branch information
johnf committed Oct 13, 2024
1 parent cb88fc2 commit c21d291
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
16 changes: 15 additions & 1 deletion app/controllers/essences_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ def show
end

def download
if !@current_user.admin? && @essence.is_archived?
flash[:error] = 'This file is archived and can only be downloaded by admins'
redirect_to [@collection, @item, @essence]

return
end

Download.create! user: current_user, essence: @essence

location = Nabu::Catalog.instance.essence_url(@essence, as_attachment: true)
Expand All @@ -32,6 +39,13 @@ def download
end

def display
if !@current_user.admin? && @essence.is_archived?
flash[:error] = 'This file is archived and can only be displayed to admins'
redirect_to [@collection, @item, @essence]

return
end

location = Nabu::Catalog.instance.essence_url(@essence)
raise ActionController::RoutingError, 'Essence file not found' unless location

Expand Down Expand Up @@ -71,6 +85,6 @@ def essence_params


def find_essence
@essence = Essence.includes(:item => { item_agents: %i[agent_role user] }).find(params[:id])
@essence = Essence.includes(item: { item_agents: %i[agent_role user] }).find(params[:id])
end
end
4 changes: 4 additions & 0 deletions app/models/essence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ def title
filename
end

def is_archived?
filename.ends_with?('.mxf') || filename.ends_with?('.mkv')
end

def full_path
# TODO: probably want to change this to be filename at some point, non-urgent though
"#{item.full_path}/essences/#{id}"
Expand Down
6 changes: 4 additions & 2 deletions app/views/essences/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
%tr
%td.empty
%td.empty
- if can? :download, @essence
- if admin_user_signed_in?
= link_to 'Download', download_collection_item_essence_path(@collection, @item, @essence), download: true
- elsif [email protected]_archived? && can?(:download, @essence)
= link_to 'Download', download_collection_item_essence_path(@collection, @item, @essence), download: true
- else
%p No access rights to download essence.
Expand All @@ -79,7 +81,7 @@
%fieldset
%legend Preview
#media_item
- if can? :display, @essence
- if [email protected]_archived? && can?(:display, @essence)
- case @essence.mimetype
- when /^image\/(jpeg|png|gif|tiff|bmp)/
= image_tag display_collection_item_essence_path(@collection, @item, @essence)
Expand Down

0 comments on commit c21d291

Please sign in to comment.