Skip to content
This repository was archived by the owner on Mar 24, 2020. It is now read-only.

Commit 70514a8

Browse files
hwengmcritchlow
authored andcommitted
Fixes #251- Implement the delete function and migrate to SHARE version 2 API.
1 parent 1eb1929 commit 70514a8

File tree

10 files changed

+67
-29
lines changed

10 files changed

+67
-29
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ gem 'active-fedora', '~> 6.7.8' # locked
77
gem 'solrizer', '~> 3.1.0' # locked
88
gem 'blacklight_advanced_search', '~> 2.2.0' # locked
99
gem 'kaminari', '~> 0.15.1' # locked (0.16.0+ breaks pagination)
10-
gem 'share_notify', '~> 0.2.0'
10+
gem 'share_notify', github: 'samvera-labs/share_notify', branch: 'master'
1111

1212
# private fork of solrizer-fedora with auto-commit disabled
1313
#gem 'solrizer-fedora', '3.0.0.pre1' # PRE-LOCK

Gemfile.lock

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
GIT
2+
remote: git://github.com/samvera-labs/share_notify.git
3+
revision: 96c16ab13c596f479f83cb55c70b27309f4d5f2d
4+
branch: master
5+
specs:
6+
share_notify (0.2.0)
7+
activesupport
8+
httparty
9+
110
GIT
211
remote: git://github.com/ucsdlib/solrizer-fedora.git
312
revision: 87c2d35e89df19bb4535e1f713a68b0dc469498a
@@ -152,8 +161,7 @@ GEM
152161
uber (~> 0.0.4)
153162
http-cookie (1.0.2)
154163
domain_name (~> 0.5)
155-
httparty (0.13.7)
156-
json (~> 1.8)
164+
httparty (0.16.1)
157165
multi_xml (>= 0.5.2)
158166
hydra-access-controls (6.5.2)
159167
active-fedora (~> 6.7)
@@ -212,7 +220,7 @@ GEM
212220
mini_portile2 (2.3.0)
213221
minitest (5.10.2)
214222
multi_json (1.12.1)
215-
multi_xml (0.5.5)
223+
multi_xml (0.6.0)
216224
multipart-post (2.0.0)
217225
net-scp (1.2.1)
218226
net-ssh (>= 2.6.5)
@@ -368,9 +376,6 @@ GEM
368376
childprocess (~> 0.5)
369377
rubyzip (~> 1.0)
370378
websocket (~> 1.0)
371-
share_notify (0.2.0)
372-
activesupport
373-
httparty
374379
simplecov (0.14.1)
375380
docile (~> 1.1.0)
376381
json (>= 1.8, < 3)
@@ -480,7 +485,7 @@ DEPENDENCIES
480485
rubyzip (= 1.2.1)
481486
sass-rails (~> 5.0.5)
482487
selenium-webdriver (= 3.4.0)
483-
share_notify (~> 0.2.0)
488+
share_notify!
484489
simplecov (~> 0.14.1)
485490
sitemap_generator (~> 5.3.1)
486491
solrizer (~> 3.1.0)
@@ -493,4 +498,4 @@ DEPENDENCIES
493498
unicorn (~> 5.3.0)
494499

495500
BUNDLED WITH
496-
1.14.3
501+
1.16.1

app/controllers/dams_resource_controller.rb

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,33 +209,44 @@ def osf_data
209209
render :json => @document
210210
end
211211

212+
def osf_delete
213+
@document = get_single_doc_via_search(1, {:q => "id:#{params[:id]}"} )
214+
authorize! :show, @document
215+
document = ShareNotify::PushDocument.new("http://library.ucsd.edu/dc/collection/#{params[:id]}", osf_date(@document))
216+
document.title = osf_title(@document)
217+
document.delete
218+
share_upload(document)
219+
redirect_to dams_collection_path(params[:id]), notice: "Your record has been deleted from OSF Share."
220+
end
221+
212222
def osf_push
213223
@document = get_single_doc_via_search(1, {:q => "id:#{params[:id]}"} )
214224
authorize! :show, @document
215225
document = ShareNotify::PushDocument.new("http://library.ucsd.edu/dc/collection/#{params[:id]}", osf_date(@document))
216226
document.title = osf_title(@document)
217-
document.description = osf_description(@document)
218-
document.publisher = osf_publisher
219-
document.languages = osf_languages(@document)
220-
document.tags = osf_mads_fields(@document)
221227
osf_contributors(@document).each do |contributor|
222228
document.add_contributor(contributor)
223229
end
224-
230+
225231
if document.valid?
226-
@headers = {'Authorization' => "Token #{share_config.fetch('token')}",
227-
'Content-Type' => 'application/json'
228-
}
229-
230-
@route = "#{share_config.fetch('host')}api/v1/share/data"
231-
@response = with_timeout { HTTParty.post(@route, body: document.to_share.to_json, headers: @headers)}
232+
share_upload(document)
232233
redirect_to dams_collection_path(params[:id]), notice: "Your record has been pushed to OSF Share."
233234
else
234235
redirect_to dams_collection_path(params[:id]), alert: "Your record is not valid."
235236
end
236237
end
237238

238239
private
240+
def share_upload(document)
241+
@headers = {
242+
'Authorization' => "Bearer #{share_config.fetch('token')}",
243+
'Content-Type' => 'application/vnd.api+json'
244+
}
245+
@route = "#{share_config.fetch('host')}api/v2/normalizeddata/"
246+
@body = ShareNotify::Graph.new(document).to_share_v2.to_json
247+
@response = with_timeout { HTTParty.post(@route, body: @body, headers: @headers)}
248+
end
249+
239250
def share_config
240251
env = Rails.env || 'test'
241252
@config ||= YAML.load(ERB.new(IO.read(File.join(Rails.root, 'config', 'share_notify.yml'))).result)[env].with_indifferent_access

app/views/dams_collections/_show_editor_tools.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</li>
99
<% } %>
1010
<% if can? :edit, @document['id'] %>
11-
<% links = { "ezid" => "Mint DOI", "osf_push" => "Push to OSF" }
11+
<% links = { "ezid" => "Mint DOI", "osf_push" => "Push to OSF", "osf_delete" => "Delete from OSF" }
1212
links.each { |key,label| %>
1313
<li><%= link_to "<i class='icon-plus-sign'></i> #{label}".html_safe,
1414
send("#{key}_dams_collection_path".to_sym, @document['id']),

app/views/dams_objects/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
</li>
5555
<% } %>
5656
<% if can_edit then %>
57-
<% links = { "ezid" => "Mint DOI", "osf_push" => "Push to OSF" }
57+
<% links = { "ezid" => "Mint DOI", "osf_push" => "Push to OSF", "osf_delete" => "Delete from OSF" }
5858
links.each { |key,label| %>
5959
<li><%= link_to "<i class='icon-plus-sign'></i> #{label}".html_safe,
6060
send("#{key}_dams_collection_path".to_sym, @document['id']),

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
get 'rdf_ttl'
2424
get 'osf_api'
2525
get 'osf_push'
26+
get 'osf_delete'
2627
get 'osf_data'
2728
end
2829
end

config/share_notify.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defaults: &defaults
2-
host: <%= ENV.fetch('APPS_DHH_STAGING_SHARE_NOTIFY_HOST'){'https://staging.osf.io/'}%>
2+
host: <%= ENV.fetch('APPS_DHH_STAGING_SHARE_NOTIFY_HOST'){'https://staging-share.osf.io/'}%>
33
token: <%= ENV.fetch('APPS_DHH_STAGING_NOTIFY_TOKEN'){'share_token'}%>
44

55
development:
@@ -21,10 +21,9 @@ demo:
2121
<<: *defaults
2222

2323
test:
24-
host: "https://staging.osf.io/"
24+
host: "https://staging-share.osf.io/"
2525
token: "share_token"
2626

2727
production:
28-
host: <%= ENV.fetch('APPS_DHH_PROD_SHARE_NOTIFY_HOST'){'https://share-registration.osf.io/'}%>
29-
token: <%= ENV.fetch('APPS_DHH_PROD_SHARE_NOTIFY_TOKEN'){'share_token'}%>
28+
<<: *defaults
3029

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
require 'spec_helper'
22

33
describe DamsCollectionsController do
4+
before(:all) do
5+
@unit = DamsUnit.create name: "Test Unit", description: "Test Description", code: "tu", uri: "http://example.com/"
6+
@provCollection = DamsProvenanceCollection.create titleValue: "Sample Provenance Collection", visibility: "public"
7+
@provCollection.save!
8+
solr_index (@provCollection.pid)
9+
end
10+
after(:all) do
11+
@provCollection.delete
12+
end
13+
14+
describe "osf_delete" do
15+
it "should delete a record from SHARE OSF" do
16+
sign_in User.create({:provider => 'developer'})
17+
get :osf_delete, { id: @provCollection.pid }
18+
expect(flash[:notice]).to include "Your record has been deleted from OSF Share."
19+
end
20+
end
21+
422
describe "share_config" do
523
it "should load config file" do
624
@controller = DamsCollectionsController.new
725
@controller.send(:share_config).fetch('token').should == "share_token"
8-
@controller.send(:share_config).fetch('host').should == "https://staging.osf.io/"
26+
@controller.send(:share_config).fetch('host').should == "https://staging-share.osf.io/"
927
end
1028
end
1129
end

spec/features/dams_collections_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,19 @@
204204
expect(page).to have_link('Data View', data_dams_collection_path(@provCollection.pid))
205205
expect(page).to have_link('DAMS 4.2 Preview', dams42_dams_collection_path(@provCollection.pid))
206206
end
207-
scenario "with dams_curator role should not see Mint DOI and Push to OSF" do
207+
scenario "with dams_curator role should not see Mint DOI and Push/Delete to/from OSF" do
208208
sign_in_curator
209209
visit dams_collection_path @provCollection
210210
expect(page).not_to have_content("Mint DOI");
211211
expect(page).not_to have_content("Push to OSF");
212+
expect(page).not_to have_content("Delete from OSF")
212213
end
213214
scenario "with dams_editor role should see Mint DOI and Push to OSF" do
214215
sign_in_developer
215216
visit dams_collection_path @provCollection
216217
expect(page).to have_content("Mint DOI");
217218
expect(page).to have_content("Push to OSF");
219+
expect(page).to have_content("Delete from OSF");
218220
end
219221
end
220222

spec/features/dams_object_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,19 @@
8484
expect(page).to have_link('Data View', data_dams_object_path(@o.pid))
8585
expect(page).to have_link('DAMS 4.2 Preview', dams42_dams_object_path(@o.pid))
8686
end
87-
it "with dams_curator role should not see Mint DOI and Push to OSF" do
87+
it "with dams_curator role should not see Mint DOI and Push/Delete to/from OSF" do
8888
sign_in_curator
8989
visit dams_object_path @o
9090
expect(page).not_to have_content("Mint DOI");
9191
expect(page).not_to have_content("Push to OSF");
92+
expect(page).not_to have_content("Delete from OSF")
9293
end
9394
it "with dams_editor role should see Mint DOI and Push to OSF" do
9495
sign_in_developer
9596
visit dams_object_path @o
9697
expect(page).to have_content("Mint DOI");
9798
expect(page).to have_content("Push to OSF");
99+
expect(page).to have_content("Delete from OSF");
98100
end
99101
end
100102

0 commit comments

Comments
 (0)