curation_concerns 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 832c5d5ac39f97b63124797e7ddd1b4f44b50314
4
- data.tar.gz: dc3f9767e7770d2df1cd944a1b7fa0ae8319c0bb
3
+ metadata.gz: b16c547a6265373a96bc6418d8c3128ffba5753f
4
+ data.tar.gz: 2ea1d0a6987df768e2c10f0599d230e462631145
5
5
  SHA512:
6
- metadata.gz: 4d4493a39a865be80e9a9b63b9b6aeea62a4d5080fc989916b798c731b03b2a8e60845f2ab84fdad3adfa12f51838aa3495731da5df8efebd516f331b705f3a1
7
- data.tar.gz: bc3ae415927e33076d79012f495676f92d08f6b42fa3add0795f7172d91e96cecc7fdd41e29d47c59a149e2618ac77ce27296941cad4a798c74d2390d4e9eec2
6
+ metadata.gz: e5521d24aee01187feab977e429dcd4db80f0149600c1a38ceddfdef1674d6e1552f27520a622fd5dd862d135a329496a77dc5b086ced5ae10c9116354e6e628
7
+ data.tar.gz: f3b6ecfb62270214f6b134ecd49d836d14308c8509ba94695a1ede4fdf60df91673c7ac9aae6c141eac5a46a2d70f11ac011f45346c9c10927a84d98a212c083
@@ -2,6 +2,8 @@ module CurationConcerns
2
2
  module SingleUseLinksControllerBehavior
3
3
  extend ActiveSupport::Concern
4
4
  included do
5
+ class_attribute :show_presenter
6
+ self.show_presenter = CurationConcerns::SingleUseLinkPresenter
5
7
  before_action :authenticate_user!
6
8
  before_action :authorize_user!
7
9
  # Catch permission errors
@@ -26,7 +28,7 @@ module CurationConcerns
26
28
  end
27
29
 
28
30
  def index
29
- links = SingleUseLink.where(itemId: params[:id])
31
+ links = SingleUseLink.where(itemId: params[:id]).map { |link| show_presenter.new(link) }
30
32
  render partial: 'curation_concerns/file_sets/single_use_link_rows', locals: { single_use_links: links }
31
33
  end
32
34
 
@@ -35,7 +35,13 @@ module CurationConcerns
35
35
  end
36
36
 
37
37
  def single_use_links
38
- @single_use_links ||= SingleUseLink.where(itemId: id)
38
+ @single_use_links ||= SingleUseLink.where(itemId: id).map { |link| link_presenter_class.new(link) }
39
39
  end
40
+
41
+ private
42
+
43
+ def link_presenter_class
44
+ CurationConcerns::SingleUseLinkPresenter
45
+ end
40
46
  end
41
47
  end
@@ -0,0 +1,52 @@
1
+ module CurationConcerns
2
+ class SingleUseLinkPresenter
3
+ include ActionView::Helpers::TranslationHelper
4
+
5
+ attr_reader :link
6
+
7
+ delegate :downloadKey, :expired?, :to_param, to: :link
8
+
9
+ # @param link [SingleUseLink]
10
+ def initialize(link)
11
+ @link = link
12
+ end
13
+
14
+ def human_readable_expiration
15
+ if hours < 1
16
+ t('curation_concerns.single_use_links.expiration.lesser_time')
17
+ else
18
+ t('curation_concerns.single_use_links.expiration.time', value: hours)
19
+ end
20
+ end
21
+
22
+ def short_key
23
+ link.downloadKey.first(6)
24
+ end
25
+
26
+ def link_type
27
+ if download?
28
+ t('curation_concerns.single_use_links.download.type')
29
+ else
30
+ t('curation_concerns.single_use_links.show.type')
31
+ end
32
+ end
33
+
34
+ def url_helper
35
+ if download?
36
+ "download_single_use_link_url"
37
+ else
38
+ "show_single_use_link_url"
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def download?
45
+ link.path =~ /downloads/
46
+ end
47
+
48
+ def hours
49
+ (link.expires - Time.zone.now).to_i / 3600
50
+ end
51
+ end
52
+ end
@@ -1,18 +1,18 @@
1
- <% single_use_links.each_with_index do |link, index| %>
2
- <% type = link.path =~ /downloads/ ? 'Download' : 'Show' %>
3
- <% url_helper = link.path =~ /downloads/ ? 'download_single_use_link_url' : 'show_single_use_link_url' %>
1
+ <% single_use_links.each do |presenter| %>
4
2
  <tr>
5
- <td><%= type %></td>
6
- <td><%= link.downloadKey %></td>
7
- <td><%= link.expires %></td>
3
+ <td><%= presenter.link_type %></td>
4
+ <td><%= presenter.downloadKey %></td>
5
+ <td><%= presenter.human_readable_expiration %></td>
8
6
  <td>
9
7
  <button class="btn btn-xs btn-default copy-single-use-link"
10
- data-clipboard-text="<%= curation_concerns.send(url_helper, link.downloadKey) %>"
11
- data-toggle="tooltip" data-placement="bottom" title="Copied!">
12
- Copy to Clipboard
8
+ data-clipboard-text="<%= curation_concerns.send(presenter.url_helper, presenter.downloadKey) %>"
9
+ data-toggle="tooltip" data-placement="bottom"
10
+ title="<%= t('curation_concerns.single_use_links.copy.tooltip') %>">
11
+ <%= t('curation_concerns.single_use_links.copy.button') %>
13
12
  </button>
14
- <%= link_to "Delete", curation_concerns.delete_single_use_link_path(params[:id], link),
15
- class: 'btn btn-xs btn-danger delete-single-use-link' %>
13
+ <%= link_to t('curation_concerns.single_use_links.delete'),
14
+ curation_concerns.delete_single_use_link_path(params[:id], presenter),
15
+ class: 'btn btn-xs btn-danger delete-single-use-link' %>
16
16
  </td>
17
17
  </tr>
18
18
  <% end %>
@@ -1,11 +1,16 @@
1
1
  <table class="table table-striped <%= dom_class(presenter) %> single-use-links">
2
- <caption class="table-heading"><h2>Single-Use Links</h2></caption>
2
+ <caption class="table-heading"><h2><%= t('curation_concerns.single_use_links.title') %></h2></caption>
3
3
  <thead>
4
- <tr><th>Link</th><th>Key</th><th>Expires</th><th>Actions</th></tr>
4
+ <tr>
5
+ <th><%= t('curation_concerns.single_use_links.table.link') %></th>
6
+ <th><%= t('curation_concerns.single_use_links.table.key') %></th>
7
+ <th><%= t('curation_concerns.single_use_links.table.expires') %></th>
8
+ <th><%= t('curation_concerns.single_use_links.table.actions') %></th>
9
+ </tr>
5
10
  </thead>
6
11
  <tbody data-url="<%= curation_concerns.generated_single_use_links_path(presenter) %>">
7
12
  <% if presenter.single_use_links.empty? %>
8
- <tr><td>No links have been generated</td></tr>
13
+ <tr><td><%= t('curation_concerns.single_use_links.table.no_links') %></td></tr>
9
14
  <% else %>
10
15
  <%= render 'single_use_link_rows', single_use_links: presenter.single_use_links %>
11
16
  <% end %>
@@ -13,8 +18,10 @@
13
18
  </table>
14
19
 
15
20
  <div class="form_actions">
16
- <%= link_to "Generate Download Link", curation_concerns.generate_download_single_use_link_path(presenter),
17
- class: 'btn btn-default generate-single-use-link' %>
18
- <%= link_to "Generate Show Link", curation_concerns.generate_show_single_use_link_path(presenter),
19
- class: 'btn btn-default generate-single-use-link' %>
21
+ <%= link_to t('curation_concerns.single_use_links.download.generate'),
22
+ curation_concerns.generate_download_single_use_link_path(presenter),
23
+ class: 'btn btn-default generate-single-use-link' %>
24
+ <%= link_to t('curation_concerns.single_use_links.show.generate'),
25
+ curation_concerns.generate_show_single_use_link_path(presenter),
26
+ class: 'btn btn-default generate-single-use-link' %>
20
27
  </div>
@@ -5,4 +5,4 @@
5
5
  <%= media_display @presenter %>
6
6
  <%= render "attributes", presenter: @presenter %>
7
7
  <%= render "show_actions", presenter: @presenter, parent: parent %>
8
- <%= render "single_use_links", presenter: @presenter %>
8
+ <%= render "single_use_links", presenter: @presenter if can? :edit, @presenter.id %>
@@ -112,6 +112,27 @@ en:
112
112
  restricted:
113
113
  text: "Private"
114
114
  class: "label-danger"
115
+ single_use_links:
116
+ title: Single-Use Links
117
+ table:
118
+ link: Link
119
+ key: Key
120
+ expires: Expires
121
+ actions: Actions
122
+ no_links: No links have been generated
123
+ download:
124
+ type: Download
125
+ generate: Generate Download Link
126
+ show:
127
+ type: Show
128
+ generate: Generate Show Link
129
+ copy:
130
+ tooltip: Copied!
131
+ button: Copy to Clipboard
132
+ delete: Delete
133
+ expiration:
134
+ time: "in %{value} hours"
135
+ lesser_time: in less than one hour
115
136
  blacklight:
116
137
  search:
117
138
  fields:
@@ -1,3 +1,3 @@
1
1
  module CurationConcerns
2
- VERSION = "1.2.0".freeze
2
+ VERSION = "1.3.0".freeze
3
3
  end
@@ -6,6 +6,11 @@ describe CurationConcerns::SingleUseLinksController, type: :controller do
6
6
  let(:user) { create(:user) }
7
7
  let(:file) { create(:file_set, user: user) }
8
8
 
9
+ describe "::show_presenter" do
10
+ subject { described_class }
11
+ its(:show_presenter) { is_expected.to eq(CurationConcerns::SingleUseLinkPresenter) }
12
+ end
13
+
9
14
  describe "logged in user with edit permission" do
10
15
  let(:hash) { "some-dummy-sha2-hash" }
11
16
 
@@ -78,10 +78,10 @@ describe CurationConcerns::FileSetPresenter do
78
78
  end
79
79
  end
80
80
 
81
- describe "single_use_links" do
82
- it "returns ActiveRecord::Relation of all single use links for the file set" do
83
- expect(SingleUseLink).to receive(:where).with(itemId: presenter.id)
84
- presenter.single_use_links
85
- end
81
+ describe "#single_use_links" do
82
+ let!(:show_link) { create(:show_link, itemId: presenter.id) }
83
+ let!(:download_link) { create(:download_link, itemId: presenter.id) }
84
+ subject { presenter.single_use_links }
85
+ it { is_expected.to include(CurationConcerns::SingleUseLinkPresenter) }
86
86
  end
87
87
  end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe CurationConcerns::SingleUseLinkPresenter do
4
+ subject { described_class.new(link) }
5
+
6
+ context "with any kind of link" do
7
+ let(:link) { create(:download_link) }
8
+
9
+ describe "#human_readable_expiration" do
10
+ context "in more than one hour" do
11
+ its(:human_readable_expiration) { is_expected.to eq("in 23 hours") }
12
+ end
13
+ context "in less than an hour" do
14
+ before { allow(link).to receive(:expires).and_return(Time.zone.now) }
15
+ its(:human_readable_expiration) { is_expected.to eq("in less than one hour") }
16
+ end
17
+ end
18
+
19
+ describe "#short_key" do
20
+ its(:short_key) { is_expected.to eq(link.downloadKey.first(6)) }
21
+ end
22
+
23
+ describe "delegated methods" do
24
+ its(:downloadKey) { is_expected.to eq(link.downloadKey) }
25
+ its(:expired?) { is_expected.to eq(link.expired?) }
26
+ its(:to_param) { is_expected.to eq(link.to_param) }
27
+ end
28
+ end
29
+
30
+ context "with a download link" do
31
+ let(:link) { create(:download_link) }
32
+ its(:link_type) { is_expected.to eq("Download") }
33
+ its(:url_helper) { is_expected.to eq("download_single_use_link_url") }
34
+ end
35
+
36
+ context "with a show link" do
37
+ let(:link) { create(:show_link) }
38
+ its(:link_type) { is_expected.to eq("Show") }
39
+ its(:url_helper) { is_expected.to eq("show_single_use_link_url") }
40
+ end
41
+ end
@@ -36,130 +36,142 @@ describe 'curation_concerns/file_sets/show.html.erb', type: :view do
36
36
 
37
37
  before do
38
38
  view.lookup_context.prefixes.push 'curation_concerns/base'
39
- allow(view).to receive(:can?).with(:edit, String).and_return(true)
40
39
  assign(:presenter, presenter)
41
40
  end
42
41
 
43
- describe 'title heading' do
44
- before do
45
- stub_template 'shared/_brand_bar.html.erb' => 'Brand Bar'
46
- stub_template 'shared/_title_bar.html.erb' => 'Title Bar'
47
- render template: 'curation_concerns/file_sets/show.html.erb', layout: 'layouts/curation_concerns'
48
- end
49
- it 'shows the title' do
50
- expect(rendered).to have_selector 'h1 > small', text: 'My Title'
42
+ context "when user does not have edit acces" do
43
+ before { allow(view).to receive(:can?).with(:edit, String).and_return(false) }
44
+
45
+ it "does not show buttons to create links" do
46
+ expect(rendered).not_to have_link("Generate Download Link")
47
+ expect(rendered).not_to have_link("Generate Show Link")
51
48
  end
52
49
  end
53
50
 
54
- describe 'media display' do
55
- context 'when config is true' do
51
+ context "when the user has edit access" do
52
+ before { allow(view).to receive(:can?).with(:edit, String).and_return(true) }
53
+
54
+ describe 'title heading' do
56
55
  before do
57
- allow(CurationConcerns.config).to receive(:display_media_download_link) { true }
58
- render
56
+ stub_template 'shared/_brand_bar.html.erb' => 'Brand Bar'
57
+ stub_template 'shared/_title_bar.html.erb' => 'Title Bar'
58
+ render template: 'curation_concerns/file_sets/show.html.erb', layout: 'layouts/curation_concerns'
59
59
  end
60
+ it 'shows the title' do
61
+ expect(rendered).to have_selector 'h1 > small', text: 'My Title'
62
+ end
63
+ end
60
64
 
61
- context 'with an image' do
62
- let(:mime_type) { 'image/tiff' }
63
- it 'renders the download link' do
64
- expect(rendered).to have_link('Download the full-sized image')
65
+ describe 'media display' do
66
+ context 'when config is true' do
67
+ before do
68
+ allow(CurationConcerns.config).to receive(:display_media_download_link) { true }
69
+ render
65
70
  end
66
- end
67
71
 
68
- context 'with a PDF' do
69
- let(:mime_type) { 'application/pdf' }
70
- it 'renders the download link' do
71
- expect(rendered).to have_link('Download the full-sized PDF')
72
+ context 'with an image' do
73
+ let(:mime_type) { 'image/tiff' }
74
+ it 'renders the download link' do
75
+ expect(rendered).to have_link('Download the full-sized image')
76
+ end
72
77
  end
73
- end
74
78
 
75
- context 'with a word document' do
76
- let(:mime_type) { 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' }
77
- it 'renders the download link' do
78
- expect(rendered).to have_link('Download the document')
79
+ context 'with a PDF' do
80
+ let(:mime_type) { 'application/pdf' }
81
+ it 'renders the download link' do
82
+ expect(rendered).to have_link('Download the full-sized PDF')
83
+ end
79
84
  end
80
- end
81
85
 
82
- context 'with anything else' do
83
- let(:mime_type) { 'application/binary' }
84
- it 'renders the download link' do
85
- expect(rendered).to have_link('Download the document')
86
+ context 'with a word document' do
87
+ let(:mime_type) { 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' }
88
+ it 'renders the download link' do
89
+ expect(rendered).to have_link('Download the document')
90
+ end
86
91
  end
87
- end
88
- end
89
92
 
90
- context 'when config is false' do
91
- before do
92
- allow(CurationConcerns.config).to receive(:display_media_download_link) { false }
93
- render
93
+ context 'with anything else' do
94
+ let(:mime_type) { 'application/binary' }
95
+ it 'renders the download link' do
96
+ expect(rendered).to have_link('Download the document')
97
+ end
98
+ end
94
99
  end
95
100
 
96
- context 'with an image' do
97
- let(:mime_type) { 'image/tiff' }
98
- it 'does not render the download link' do
99
- expect(rendered).not_to have_link('Download the full-sized image')
101
+ context 'when config is false' do
102
+ before do
103
+ allow(CurationConcerns.config).to receive(:display_media_download_link) { false }
104
+ render
100
105
  end
101
- end
102
106
 
103
- context 'with a PDF' do
104
- let(:mime_type) { 'application/pdf' }
105
- it 'does not render the download link' do
106
- expect(rendered).not_to have_link('Download the full-sized PDF')
107
+ context 'with an image' do
108
+ let(:mime_type) { 'image/tiff' }
109
+ it 'does not render the download link' do
110
+ expect(rendered).not_to have_link('Download the full-sized image')
111
+ end
107
112
  end
108
- end
109
113
 
110
- context 'with a word document' do
111
- let(:mime_type) { 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' }
112
- it 'does not render the download link' do
113
- expect(rendered).not_to have_link('Download the document')
114
+ context 'with a PDF' do
115
+ let(:mime_type) { 'application/pdf' }
116
+ it 'does not render the download link' do
117
+ expect(rendered).not_to have_link('Download the full-sized PDF')
118
+ end
119
+ end
120
+
121
+ context 'with a word document' do
122
+ let(:mime_type) { 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' }
123
+ it 'does not render the download link' do
124
+ expect(rendered).not_to have_link('Download the document')
125
+ end
114
126
  end
115
- end
116
127
 
117
- context 'with anything else' do
118
- let(:mime_type) { 'application/binary' }
119
- it 'does not render the download link' do
120
- expect(rendered).not_to have_link('Download the document')
128
+ context 'with anything else' do
129
+ let(:mime_type) { 'application/binary' }
130
+ it 'does not render the download link' do
131
+ expect(rendered).not_to have_link('Download the document')
132
+ end
121
133
  end
122
134
  end
123
135
  end
124
- end
125
136
 
126
- describe 'attributes' do
127
- before { render }
137
+ describe 'attributes' do
138
+ before { render }
128
139
 
129
- it 'shows the description' do
130
- expect(rendered).to have_selector '.attribute.description', text: 'Lorem ipsum'
140
+ it 'shows the description' do
141
+ expect(rendered).to have_selector '.attribute.description', text: 'Lorem ipsum'
142
+ end
131
143
  end
132
- end
133
144
 
134
- describe 'single use links' do
135
- before do
136
- allow(presenter).to receive(:single_use_links).and_return(links)
137
- controller.params = { id: presenter.id }
138
- render
139
- end
145
+ describe 'single use links' do
146
+ before do
147
+ allow(presenter).to receive(:single_use_links).and_return(links)
148
+ controller.params = { id: presenter.id }
149
+ render
150
+ end
140
151
 
141
- context "when links are present" do
142
- let(:show_link) { create(:show_link) }
143
- let(:download_link) { create(:download_link) }
144
- let(:links) { [show_link, download_link] }
145
-
146
- it "renders single use links for the file set" do
147
- expect(rendered).to have_selector('td', text: 'Show')
148
- expect(rendered).to have_selector('td', text: 'Download')
149
- expect(rendered).to have_selector('td', text: show_link.downloadKey)
150
- expect(rendered).to have_selector('td', text: show_link.expires)
151
- expect(rendered).to have_link("Generate Download Link")
152
- expect(rendered).to have_link("Generate Show Link")
152
+ context "when links are present" do
153
+ let(:show_link) { CurationConcerns::SingleUseLinkPresenter.new(create(:show_link)) }
154
+ let(:download_link) { CurationConcerns::SingleUseLinkPresenter.new(create(:download_link)) }
155
+ let(:links) { [show_link, download_link] }
156
+
157
+ it "renders single use links for the file set" do
158
+ expect(rendered).to have_selector('td', text: 'Show')
159
+ expect(rendered).to have_selector('td', text: 'Download')
160
+ expect(rendered).to have_selector('td', text: show_link.downloadKey)
161
+ expect(rendered).to have_selector('td', text: "23 hours")
162
+ expect(rendered).to have_link("Generate Download Link")
163
+ expect(rendered).to have_link("Generate Show Link")
164
+ end
153
165
  end
154
- end
155
166
 
156
- context "when no links are present" do
157
- let(:links) { [] }
167
+ context "when no links are present" do
168
+ let(:links) { [] }
158
169
 
159
- it "renders a table without links" do
160
- expect(rendered).to have_selector('td', text: 'No links have been generated')
161
- expect(rendered).to have_link("Generate Download Link")
162
- expect(rendered).to have_link("Generate Show Link")
170
+ it "renders a table without links" do
171
+ expect(rendered).to have_selector('td', text: 'No links have been generated')
172
+ expect(rendered).to have_link("Generate Download Link")
173
+ expect(rendered).to have_link("Generate Show Link")
174
+ end
163
175
  end
164
176
  end
165
177
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curation_concerns
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-07-29 00:00:00.000000000 Z
13
+ date: 2016-08-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hydra-head
@@ -797,6 +797,7 @@ files:
797
797
  - app/presenters/curation_concerns/permission_badge.rb
798
798
  - app/presenters/curation_concerns/presenter_factory.rb
799
799
  - app/presenters/curation_concerns/presents_attributes.rb
800
+ - app/presenters/curation_concerns/single_use_link_presenter.rb
800
801
  - app/presenters/curation_concerns/version_list_presenter.rb
801
802
  - app/presenters/curation_concerns/version_presenter.rb
802
803
  - app/presenters/curation_concerns/work_show_presenter.rb
@@ -1183,6 +1184,7 @@ files:
1183
1184
  - spec/presenters/curation_concerns/file_set_presenter_spec.rb
1184
1185
  - spec/presenters/curation_concerns/permission_badge_spec.rb
1185
1186
  - spec/presenters/curation_concerns/presenter_factory_spec.rb
1187
+ - spec/presenters/curation_concerns/single_use_link_presenter_spec.rb
1186
1188
  - spec/presenters/curation_concerns/version_list_presenter_spec.rb
1187
1189
  - spec/presenters/curation_concerns/version_presenter_spec.rb
1188
1190
  - spec/presenters/curation_concerns/work_show_presenter_spec.rb
@@ -1392,6 +1394,7 @@ test_files:
1392
1394
  - spec/presenters/curation_concerns/file_set_presenter_spec.rb
1393
1395
  - spec/presenters/curation_concerns/permission_badge_spec.rb
1394
1396
  - spec/presenters/curation_concerns/presenter_factory_spec.rb
1397
+ - spec/presenters/curation_concerns/single_use_link_presenter_spec.rb
1395
1398
  - spec/presenters/curation_concerns/version_list_presenter_spec.rb
1396
1399
  - spec/presenters/curation_concerns/version_presenter_spec.rb
1397
1400
  - spec/presenters/curation_concerns/work_show_presenter_spec.rb