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

Removes defunct resource editing functionality #565

Merged
merged 1 commit into from
Feb 22, 2016
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
Binary file removed app/assets/images/add.png
Binary file not shown.
Binary file removed app/assets/images/unavailable.png
Binary file not shown.
Binary file removed app/assets/images/update.png
Binary file not shown.
36 changes: 1 addition & 35 deletions app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ class ItemsController < ApplicationController
]
before_action :forbid_modify, :only => [
:add_collection, :set_collection, :remove_collection,
:add_file, :delete_file,
:datastream_update,
:mods,
:open_version, :close_version,
:replace_file,
:resource, :update_resource,
:update_resource,
:set_content_type,
:source_id,
:tags, :tags_bulk,
Expand Down Expand Up @@ -347,26 +345,6 @@ def create_minimal_mods
end
end

def replace_file
@object.replace_file params[:uploaded_file], params[:file_name]
respond_to do |format|
msg = "File #{params[:file_name]} was replaced!"
format.any { redirect_to catalog_path(params[:id]), :notice => msg }
end
end

# add a file to a resource, not to be confused with add a resource to an object
def add_file
file = params[:uploaded_file]
file_name = file.original_filename
file_mtype = Rack::Mime.mime_type(File.extname(file_name))
@object.add_file file, params[:resource], file_name, file_mtype
respond_to do |format|
msg = "File #{file_name} was added!"
format.any { redirect_to catalog_path(params[:id]), :notice => msg }
end
end

def open_version
# puts params[:description]
vers_md_upd_info = {
Expand Down Expand Up @@ -515,18 +493,6 @@ def tags
end
end

def delete_file
@object.remove_file(params[:file_name])
respond_to do |format|
msg = params[:file_name] + ' has been deleted!'
format.any { redirect_to catalog_path(params[:id]), :notice => msg }
end
end

def resource
@content_ds = @object.datastreams['contentMetadata']
end

def purge_object
begin
create_obj
Expand Down
9 changes: 0 additions & 9 deletions app/views/catalog/_show_sections/_default_contents.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,10 @@

can_manage = current_user.is_admin || current_user.is_manager || (apo_pid && object.can_manage_content?(current_user.roles(apo_pid)))
can_view = current_user.is_admin || current_user.is_manager || (apo_pid && object.can_view_content?(current_user.roles(apo_pid)))
version_open = can_close_version? object.pid

content_ds.ng_xml.xpath('/contentMetadata/resource').each_with_index do |resource, index| %>
<li class="resource">
<span class="label">Resource (<%=index+1%>)</span> <%= resource['type']%>
<%if can_manage && version_open
edit_resource_link="/items/#{params[:id]}/resource/?edit=true&resource=#{resource['id']}"%>
<%= link_to "(edit)", edit_resource_link, :data => {ajax_modal: 'trigger'} %>
<%end%>
<% if resource.at('label') %>
<li><span class="label">Label</span> <%= resource.at('label').text %></li>
<% end %>
Expand All @@ -41,10 +36,6 @@
<li class="resource">
<span class="label">Resource (<%=inner_index%>)</span>
<%= child['type']%>
<%if can_manage && version_open
edit_resource_link = '/items/'+params[:id]+'/resource/?edit=true&resource='+child['id'] %>
<%= link_to "(edit)", edit_resource_link, :data => {ajax_modal: 'trigger'} %>
<%end%>
<ul>
<% if child.at('label') %>
<li> <span class="label">Label</span> <%= child.at('label').text %></li>
Expand Down
79 changes: 0 additions & 79 deletions app/views/items/resource.html.erb

This file was deleted.

4 changes: 0 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@
post 'datastream', :action => :datastream_update, :as => 'datastream_update'
get 'file', :action => :get_file, :as => 'get_file'
get 'file_list', :action => :file, :as => 'file'
post 'file', :action => :replace_file, :as => 'replace_file'
get 'resource', :action => :resource, :as => 'resource'
delete 'file', :action => :delete_file, :as => 'delete_file'
post 'add_file'
post 'file/attributes', :action => :update_attributes, :as => 'update_attributes'
match 'close_version_ui', :action => :close_version_ui, :as => 'close_version_ui', :via => [:get, :post]
match 'open_version_ui', :action => :open_version_ui, :as => 'open_version_ui', :via => [:get, :post]
Expand Down
46 changes: 0 additions & 46 deletions spec/controllers/items_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,44 +174,6 @@
get 'set_rights', :id => @pid, :rights => 'dark'
end
end

describe 'add_file' do
it 'should recieve an uploaded file and add it to the requested resource' do
# found the UploadedFile approach at: http://stackoverflow.com/questions/7280204/rails-post-command-in-rspec-controllers-files-arent-passing-through-is-the
file = Rack::Test::UploadedFile.new('spec/fixtures/cerenkov_radiation_160.jpg', 'image/jpg')
expect(@item).to receive(:add_file)
post 'add_file', :uploaded_file => file, :id => @pid, :resource => 'resourceID'
end
it 'should 403 if you are not an admin' do
allow(@current_user).to receive(:is_admin).and_return(false)
post 'add_file', :uploaded_file => nil, :id => @pid, :resource => 'resourceID'
expect(response.code).to eq('403')
end
end
describe 'delete_file' do
it 'should call dor services to remove the file' do
expect(@item).to receive(:remove_file)
get 'delete_file', :id => @pid, :file_name => 'old_file'
end
it 'should 403 if you are not an admin' do
allow(@current_user).to receive(:is_admin).and_return(false)
get 'delete_file', :id => @pid, :file_name => 'old_file'
expect(response.code).to eq('403')
end
end
describe 'replace_file' do
it 'should recieve an uploaded file and call dor-services' do
# found the UploadedFile approach at: http://stackoverflow.com/questions/7280204/rails-post-command-in-rspec-controllers-files-arent-passing-through-is-the
file = Rack::Test::UploadedFile.new('spec/fixtures/cerenkov_radiation_160.jpg', 'image/jpg')
expect(@item).to receive(:replace_file)
post 'replace_file', :uploaded_file => file, :id => @pid, :resource => 'resourceID', :file_name => 'somefile.txt'
end
it 'should 403 if you are not an admin' do
allow(@current_user).to receive(:is_admin).and_return(false)
post 'replace_file', :uploaded_file => nil, :id => @pid, :resource => 'resourceID', :file_name => 'somefile.txt'
expect(response.code).to eq('403')
end
end
describe 'update_parameters' do
before :each do
@content_md = double(Dor::ContentMetadataDS)
Expand Down Expand Up @@ -338,14 +300,6 @@
post 'update_resource', :resource => '0001', :type => 'book', :id => @pid
end
end
describe 'resource' do
it 'should set the object and datastream, then call the view' do
expect(Dor::Item).to receive(:find)
allow(@item).to receive(:datastreams).and_return({'contentMetadata' => double(Dor::ContentMetadataDS)})
get 'resource', :id => @pid, :resource => '0001'
# XXX : isn't actually testing what it says!
end
end
describe 'add_collection' do
it 'should add a collection' do
expect(@item).to receive(:add_collection).with('druid:1234')
Expand Down