sufia 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -3
  3. data/History.md +16 -0
  4. data/app/assets/javascripts/sufia.js +2 -0
  5. data/app/assets/javascripts/sufia/batch_select_all.js +57 -128
  6. data/app/controllers/batch_controller.rb +4 -5
  7. data/app/controllers/concerns/sufia/users_controller_behavior.rb +2 -2
  8. data/app/controllers/contact_form_controller.rb +2 -24
  9. data/app/controllers/dashboard_controller.rb +1 -66
  10. data/app/controllers/single_use_link_controller.rb +3 -2
  11. data/app/helpers/generic_file_helper.rb +1 -4
  12. data/app/models/checksum_audit_log.rb +1 -1
  13. data/app/views/_footer.html.erb +2 -4
  14. data/app/views/batch_edits/_check_all.html.erb +3 -8
  15. data/app/views/batch_edits/_delete_selected.html.erb +1 -1
  16. data/app/views/batch_edits/edit.html.erb +2 -3
  17. data/app/views/dashboard/_facet_pagination.html.erb +2 -2
  18. data/app/views/generic_files/_asset_permissions_denial_flash.html.erb +1 -1
  19. data/app/views/generic_files/_asset_saved_flash.html.erb +1 -1
  20. data/app/views/generic_files/_asset_updated_flash.html.erb +1 -1
  21. data/app/views/generic_files/_media_display.html.erb +1 -1
  22. data/app/views/generic_files/edit.html.erb +1 -1
  23. data/app/views/generic_files/show.html.erb +1 -1
  24. data/app/views/single_use_link/generate_download.html.erb +1 -1
  25. data/app/views/single_use_link/generate_show.html.erb +1 -1
  26. data/app/views/single_use_link/show.html.erb +1 -1
  27. data/app/views/users/_trophy_edit.html.erb +1 -1
  28. data/app/views/users/show.html.erb +1 -1
  29. data/features/browse_dashboard_files.feature +1 -4
  30. data/features/display_dashboard.feature +1 -4
  31. data/features/step_definitions/scholarsphere.rb +1 -1
  32. data/lib/sufia.rb +4 -1
  33. data/lib/sufia/batch_edits_controller_behavior.rb +3 -4
  34. data/lib/sufia/contact_form_controller_behavior.rb +45 -0
  35. data/lib/sufia/dashboard_controller_behavior.rb +92 -0
  36. data/lib/sufia/downloads_controller_behavior.rb +6 -39
  37. data/lib/sufia/files_controller_behavior.rb +7 -7
  38. data/lib/sufia/generic_file.rb +3 -5
  39. data/lib/sufia/generic_file/web_form.rb +15 -0
  40. data/lib/sufia/jobs/batch_update_job.rb +1 -2
  41. data/lib/sufia/jobs/transcode_audio_job.rb +2 -3
  42. data/lib/sufia/jobs/unzip_job.rb +22 -13
  43. data/lib/sufia/model_methods.rb +6 -0
  44. data/lib/sufia/version.rb +1 -1
  45. data/spec/controllers/batch_edits_controller_spec.rb +22 -2
  46. data/spec/controllers/downloads_controller_spec.rb +9 -15
  47. data/spec/controllers/generic_files_controller_spec.rb +32 -0
  48. data/spec/controllers/single_use_link_controller_spec.rb +2 -1
  49. data/spec/controllers/users_controller_spec.rb +13 -0
  50. data/spec/models/generic_file_spec.rb +41 -0
  51. data/spec/support/Gemfile +1 -0
  52. data/sufia.gemspec +1 -1
  53. metadata +7 -6
  54. data/app/views/static/versions.html.erb +0 -52
@@ -15,10 +15,7 @@
15
15
 
16
16
  module GenericFileHelper
17
17
  def display_title(gf)
18
- title = gf.title.join(' | ')
19
- title = gf.label if title.blank?
20
- title = 'No Title' if title.blank?
21
- title
18
+ gf.to_s
22
19
  end
23
20
 
24
21
  def add_field (key)
@@ -29,7 +29,7 @@ class ChecksumAuditLog < ActiveRecord::Base
29
29
  logs = GenericFile.load_instance_from_solr(version.pid).logs(version.dsid)
30
30
  list = logs.limit(2)
31
31
  if list.size > 1 && (list[0].pass == 1) && (list[1].pass == 1)
32
- list[0].delete
32
+ list[0].destroy
33
33
  end
34
34
  end
35
35
  end
@@ -1,13 +1,11 @@
1
1
  <div id="footer-wrapper" class="row-fluid">
2
2
  <div id="footer">
3
3
  <div class="footer-logo">
4
- <p class="fright">
5
- <a href="/versions/"><%= Sufia::VERSION %></a></p>
6
- <a href="/"></a>
4
+ <p class="fright"><%= Sufia::VERSION %></p>
7
5
  <p>A service of Project Hydra.</p>
8
6
  </div>
9
7
  <div class="footer-text">
10
- <p><strong>Copyright &copy; 2012 Project Hydra</strong></p>
8
+ <p><strong>Copyright &copy; 2013 Project Hydra</strong> Licensed under the Apache License, Version 2.0</p>
11
9
  <ul>
12
10
  <li><a href="">One</a></li>
13
11
  <li><a href="">Two</a></li>
@@ -3,13 +3,8 @@
3
3
  <%= check_box_tag 'check_all', 'yes', @all_checked, :disabled => ((@batch_size_on_other_page + @document_list.count) > @max_batch_size) %>
4
4
  <a class="dropdown-toggle" data-toggle="dropdown" href="#"><span class="icon-cog" title="click for selection options"></span></a>
5
5
  <ul class="dropdown-menu">
6
- <li data-behavior="batch-edit-select-none" data-state="<%= @empty_batch ? 'on' : 'off' %>"><a href="#"><i class="<%= @empty_batch ? 'icon-ok' : '' %>"></i> Select None</a></li>
7
- <li data-behavior="batch-edit-select-page" data-state="<%= @all_checked && !@batch_part_on_other_page ? 'on' : 'off' %>"><a href="#"><i class="<%= @all_checked && !@batch_part_on_other_page ? 'icon-ok' : '' %>"></i> Select Only Current Page</a></li>
8
- <% if @result_set_size <= @max_batch_size %>
9
- <li data-behavior="batch-edit-select-all" data-state="<%= @entire_result_set_selected ? 'on' : 'off' %>"><a href="#"><i class="<%= @entire_result_set_selected ? 'icon-ok' : '' %>"></i> Select <em>All</em> Results</a></li>
10
- <% else %>
11
- <li data-behavior="batch-edit-select-all-disabled" data-state="'off' %>"><a href="#" onclick="return false;" disabled="true"> Result Set Too Big For Select All (><%=@max_batch_size%>)</a></li>
12
- <% end %>
6
+ <li data-behavior="batch-edit-select-none" data-state="on"><a href="#"><i class="icon-ok"></i> Select None</a></li>
7
+ <li data-behavior="batch-edit-select-page" data-state="off"><a href="#"><i class=""></i> Select Current Page</a></li>
13
8
  </ul>
14
9
  </div>
15
- <% end %>
10
+ <% end %>
@@ -1,5 +1,5 @@
1
1
  <%= form_tag(batch_edits_path, :method => :put, :class=> "batch-select-all hidden", "data-behavior" => 'batch-select-all') do -%>
2
2
  <%= hidden_field_tag('update_type', 'delete_all') %>
3
- <%= submit_tag("Delete Selected", :class=>'batch-all-button btn btn-primary', :data => { :confirm => "Deleting a file from #{t('sufia.product_name')} is permanent. Click OK to delete this file from #{t('sufia.product_name')}, or Cancel to cancel this operation"}) %>
3
+ <%= submit_tag("Delete Selected", :class=>'batch-all-button btn btn-primary submits-batches', :data => { :confirm => "Deleting a file from #{t('sufia.product_name')} is permanent. Click OK to delete this file from #{t('sufia.product_name')}, or Cancel to cancel this operation"}) %>
4
4
  <% end %>
5
5
 
@@ -207,7 +207,7 @@ $("a[rel=popover]").popover({ html: true });
207
207
  <%= hidden_field_tag('key', term.to_s) %>
208
208
  <%= render :partial => "generic_files/field_form", :locals => { :generic_file => @show_file, :f =>f, :render_req => false, :key => term } %>
209
209
  <div class="row">
210
- <%= f.submit "Save changes", :class=>'btn btn-primary field-save' , :id=>term.to_s+'_save'%>
210
+ <%= f.submit "Save changes", :class=>'btn btn-primary field-save updates-batches' , :id=>term.to_s+'_save'%>
211
211
  <a class="accordion-toggle btn" data-toggle="collapse" data-parent="#row_<%=term.to_s%>" href="#collapse_<%=term.to_s%>">Cancel </a>
212
212
  <div id="status_<%=term.to_s%>" class="status fleft"></div>
213
213
  </div>
@@ -220,12 +220,11 @@ $("a[rel=popover]").popover({ html: true });
220
220
  </div><!-- /well -->
221
221
  <div id="permissions_display" class="tab-pane">
222
222
  <%= form_for @generic_file, :url=>batch_edits_path, :method=>:put, :remote => true, :html => { :id=>"form_permissions", :class=>"ajax-form"} do |f| %>
223
- <%= hidden_field_tag('generic_file[terms_of_service]', '1') %>
224
223
  <%= hidden_field_tag('update_type', 'update') %>
225
224
  <%= hidden_field_tag('key', 'permissions') %>
226
225
  <%= render :partial => "generic_files/permission_form", :locals => { :gf => @show_file } %>
227
226
  <div class="row">
228
- <%= f.submit "Save changes", :class=>'btn btn-primary', :id=>'permissions_save' %>
227
+ <%= f.submit "Save changes", :class=>'btn btn-primary updates-batches', :id=>'permissions_save' %>
229
228
  <a class="accordion-toggle btn" data-toggle="collapse" data-parent="#row_permissions" href="#collapse_permissions">Cancel </a>
230
229
  <div id="status_permissions" class="status fleft"></div>
231
230
  </div>
@@ -2,10 +2,10 @@
2
2
  It implements the facets in the same manner as blacklight does for the main catalog for the individual's dashbord
3
3
  -->
4
4
  <div class="prev_next_links btn-group pull-left">
5
- <%= link_to_previous_page @pagination, raw(t('views.pagination.previous')), :params => params, :param_name => Blacklight::Solr::FacetPaginator.request_keys[:page], :class => 'btn' do %>
5
+ <%= link_to_previous_page @pagination, raw(t('views.pagination.previous')), :route_set=>sufia, :params => params, :param_name => Blacklight::Solr::FacetPaginator.request_keys[:page], :class => 'btn' do %>
6
6
  <span class="disabled btn"><%= raw(t('views.pagination.previous')) %></span>
7
7
  <% end %>
8
- <%= link_to_next_page @pagination, raw(t('views.pagination.next')), :params => params, :param_name => Blacklight::Solr::FacetPaginator.request_keys[:page], :class => 'btn' do %>
8
+ <%= link_to_next_page @pagination, raw(t('views.pagination.next')), :route_set=>sufia, :params => params, :param_name => Blacklight::Solr::FacetPaginator.request_keys[:page], :class => 'btn' do %>
9
9
 
10
10
  <span class="disabled btn"><%= raw(t('views.pagination.next')) %></span>
11
11
  <% end %>
@@ -16,7 +16,7 @@ limitations under the License.
16
16
 
17
17
  The file(s)
18
18
  <% generic_files.first(20).each do |gf|%>
19
- <%= link_to(display_title(gf), generic_file_url(gf.noid)) %><%= ',' unless gf == generic_files.last %>
19
+ <%= link_to(gf, generic_file_url(gf.noid)) %><%= ',' unless gf == generic_files.last %>
20
20
  <% end %>
21
21
  <%= '...' if generic_files.length > 20 %>
22
22
  could not be updated. You do not have sufficient privileges to edit it.
@@ -16,7 +16,7 @@ limitations under the License.
16
16
 
17
17
  The file(s)
18
18
  <% generic_files.first(20).each do |gf|%>
19
- <%= link_to(display_title(gf), generic_file_url(gf.noid)) %><%= ',' unless gf == generic_files.last %>
19
+ <%= link_to(gf, generic_file_url(gf.noid)) %><%= ',' unless gf == generic_files.last %>
20
20
  <% end %>
21
21
  <%= '...' if generic_files.length > 20 %>
22
22
  have been saved.
@@ -14,4 +14,4 @@ See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  %>
16
16
 
17
- The file <%= link_to(display_title(generic_file), sufia.generic_file_url(generic_file.noid)) %> has been updated.
17
+ The file <%= link_to(generic_file, sufia.generic_file_url(generic_file.noid)) %> has been updated.
@@ -25,7 +25,7 @@ limitations under the License.
25
25
  <% elsif @generic_file.audio? %>
26
26
  <audio controls="controls" class="video-js vjs-default-skin" data-setup="{}" preload="auto">
27
27
  <source src="<%= sufia.download_path(@generic_file, datastream_id: 'ogg') %>" type="audio/ogg" />
28
- <source src="<%= sufia.download_path(@generic_file, datastream_id: 'mp3') %>" type="audio/mp3" />
28
+ <source src="<%= sufia.download_path(@generic_file, datastream_id: 'mp3') %>" type="audio/mpeg" />
29
29
  Your browser does not support the audio tag.
30
30
  </audio>
31
31
  <% elsif @generic_file.pdf?%>
@@ -43,7 +43,7 @@ $("a[rel=popover]").popover({ html: true });
43
43
 
44
44
  <%= render :partial => 'breadcrumbs' %>
45
45
 
46
- <h1 class="lower">Edit <%= display_title(@generic_file) %></h1>
46
+ <h1 class="lower">Edit <%= @generic_file %></h1>
47
47
 
48
48
  <div class="row">
49
49
  <div class="span40">
@@ -28,7 +28,7 @@ limitations under the License.
28
28
 
29
29
  <%= render :partial => 'generic_files/breadcrumbs' %>
30
30
 
31
- <h1 class="lower"><%= display_title(@generic_file) %></h1>
31
+ <h1 class="lower"><%= @generic_file %></h1>
32
32
 
33
33
  <div class="row">
34
34
  <div class="span40">
@@ -1,3 +1,3 @@
1
1
  <h1>Single Use Link</h1>
2
2
  <p>Anyone can use the following link once to download the file</p>
3
- <%= link_to display_title(@generic_file), @link %> <%= link_to raw('<i class="icon-link icon-large"></i>'), '#', :class => 'copypaste itemicon itemcode', :title => 'Copy File URL', :id => "copy_link_#{@generic_file.pid}" %>
3
+ <%= link_to @generic_file, @link %> <%= link_to raw('<i class="icon-link icon-large"></i>'), '#', :class => 'copypaste itemicon itemcode', :title => 'Copy File URL', :id => "copy_link_#{@generic_file.pid}" %>
@@ -1,3 +1,3 @@
1
1
  <h1>Single Use Link</h1>
2
2
  <p>Anyone can use the following link once to view the file metadata</p>
3
- <%= link_to display_title(@generic_file), @link %>
3
+ <%= link_to @generic_file, @link %>
@@ -1,5 +1,5 @@
1
1
  <div >
2
- <h1 class="lower"><%= display_title(@generic_file) %></h1>
2
+ <h1 class="lower"><%= @generic_file %></h1>
3
3
  <h2 class="non lower">Actions</h2>
4
4
  <p>
5
5
  <%= link_to "Download (can only be used once)", @download_link %>
@@ -7,7 +7,7 @@
7
7
  <% trophies.each do |t| %>
8
8
  <dd>
9
9
  <div class="controls">
10
- <%= link_to display_title(t), sufia.generic_file_path(t) %>
10
+ <%= link_to t, sufia.generic_file_path(t) %>
11
11
  <label class="checkbox fleft">
12
12
  <%= check_box_tag "remove_trophy_#{t.id}" %> Yes &nbsp;
13
13
  </label>
@@ -40,7 +40,7 @@ limitations under the License.
40
40
  <dd><%= link_to_field('depositor', @user.to_s, GenericFile.where(:depositor => @user.to_s).count) %></dd>
41
41
  <dt><i class="icon-trophy trophy-on" ></i> Highlighted Files</dt>
42
42
  <% @trophies.each do |t| %>
43
- <dd> <%= link_to display_title(t), sufia.generic_file_path(t) %></dd>
43
+ <dd> <%= link_to t, sufia.generic_file_path(t) %></dd>
44
44
  <% end %>
45
45
  </dl>
46
46
 
@@ -11,9 +11,6 @@ Feature: Browse Dashboard files
11
11
  Scenario: Edit Dashboard File
12
12
  Given I am logged in as "archivist2@example.com"
13
13
  And I follow "dashboard"
14
- When I follow the link within
15
- """
16
- a[href="/files/test5/edit"]
17
- """
14
+ When I follow the link within "a[href='/files/test5/edit']"
18
15
  Then I should see "Edit Test mp3"
19
16
 
@@ -37,9 +37,6 @@ Feature: As an authenticate and authorized
37
37
  And I am logged in as "archivist1@example.com"
38
38
  And I follow "dashboard"
39
39
  Then I should see "Test Document Text"
40
- When I follow the link within
41
- """
42
- a[href="/files/test3"].itemtrash
43
- """
40
+ When I follow the link within "a[href='/files/test3'].itemtrash"
44
41
  Then I should see "The file has been deleted"
45
42
 
@@ -34,7 +34,7 @@ Then /^I reset the mail server$/ do
34
34
  ContactForm.any_instance.unstub(:deliver)
35
35
  end
36
36
 
37
- When /^I follow the link within$/ do |selector|
37
+ When /^I follow the link within "(.*?)"$/ do |selector|
38
38
  find(selector).click
39
39
  end
40
40
 
data/lib/sufia.rb CHANGED
@@ -12,6 +12,8 @@ require 'nest'
12
12
  require 'RMagick'
13
13
  require 'activerecord-import'
14
14
  require 'rails_autolink'
15
+ require 'sufia/dashboard_controller_behavior'
16
+ require "sufia/contact_form_controller_behavior"
15
17
 
16
18
  autoload :Zip, 'zipruby'
17
19
  module Sufia
@@ -32,7 +34,8 @@ module Sufia
32
34
  config.temp_file_base = nil
33
35
  config.id_namespace = "sufia"
34
36
  config.fits_path = "fits.sh"
35
-
37
+ config.enable_contact_form_delivery = false
38
+
36
39
  config.autoload_paths += %W(
37
40
  #{config.root}/lib/sufia/jobs
38
41
  #{config.root}/app/controllers/concerns
@@ -22,7 +22,7 @@ module Sufia
22
22
  h[key] ||= []
23
23
  h[key] = (h[key] + gf.send(key)).uniq
24
24
  end
25
- @names << display_title(gf)
25
+ @names << gf.to_s
26
26
  permissions = (permissions + gf.permissions).uniq
27
27
  end
28
28
 
@@ -54,10 +54,9 @@ module Sufia
54
54
  super
55
55
  elsif type == "delete_all"
56
56
  batch.each do |doc_id|
57
- gf = ::GenericFile.load_instance_from_solr(doc_id)
58
- gf.delete
57
+ gf = ::GenericFile.find(doc_id)
58
+ gf.destroy
59
59
  end
60
- clear_batch!
61
60
  after_update
62
61
  end
63
62
 
@@ -0,0 +1,45 @@
1
+ # Copyright © 2012 The Pennsylvania State University
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Sufia
16
+ module ContactFormControllerBehavior
17
+
18
+ def new
19
+ @contact_form = ContactForm.new
20
+ end
21
+
22
+ def create
23
+ @contact_form = ContactForm.new(params[:contact_form])
24
+ @contact_form.request = request
25
+ # not spam and a valid form
26
+ logger.warn "*** MARK ***"
27
+ if @contact_form.deliver
28
+ flash.now[:notice] = 'Thank you for your message!'
29
+ after_deliver
30
+ render :new
31
+ else
32
+ flash[:error] = 'Sorry, this message was not sent successfully. '
33
+ flash[:error] << @contact_form.errors.full_messages.map { |s| s.to_s }.join(",")
34
+ render :new
35
+ end
36
+ rescue
37
+ flash[:error] = 'Sorry, this message was not delivered.'
38
+ render :new
39
+ end
40
+
41
+ def after_deliver
42
+ return unless Sufia::Engine.config.enable_contact_form_delivery
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,92 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright © 2012 The Pennsylvania State University
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ require 'blacklight/catalog'
16
+
17
+ module Sufia
18
+ module DashboardControllerBehavior
19
+ extend ActiveSupport::Concern
20
+ include Hydra::BatchEditBehavior
21
+ include Blacklight::Catalog
22
+
23
+ included do
24
+ include Hydra::BatchEditBehavior
25
+ include Blacklight::Catalog
26
+ include Blacklight::Configurable # comply with BL 3.7
27
+ include ActionView::Helpers::DateHelper
28
+ include BlacklightAdvancedSearch::ParseBasicQ
29
+ include BlacklightAdvancedSearch::Controller
30
+
31
+ # This is needed as of BL 3.7
32
+ self.copy_blacklight_config_from(CatalogController)
33
+
34
+ before_filter :authenticate_user!
35
+ before_filter :enforce_show_permissions, :only=>:show
36
+ before_filter :enforce_viewing_context_for_show_requests, :only=>:show
37
+
38
+ # This applies appropriate access controls to all solr queries (the internal method of this is overidden bellow to only include edit files)
39
+ self.solr_search_params_logic += [:add_access_controls_to_solr_params]
40
+ # This filters out objects that you want to exclude from search results, like FileAssets
41
+ self.solr_search_params_logic += [:exclude_unwanted_models]
42
+
43
+ end
44
+
45
+ def index
46
+ extra_head_content << view_context.auto_discovery_link_tag(:rss, sufia.url_for(params.merge(:format => 'rss')), :title => "RSS for results")
47
+ extra_head_content << view_context.auto_discovery_link_tag(:atom, sufia.url_for(params.merge(:format => 'atom')), :title => "Atom for results")
48
+ (@response, @document_list) = get_search_results
49
+ @user = current_user
50
+ @events = @user.events(100)
51
+ @last_event_timestamp = @user.events.first[:timestamp].to_i || 0 rescue 0
52
+ @filters = params[:f] || []
53
+
54
+ # adding a key to the session so that the history will be saved so that batch_edits select all will work
55
+ search_session[:dashboard] = true
56
+ respond_to do |format|
57
+ format.html { save_current_search_params }
58
+ format.rss { render :layout => false }
59
+ format.atom { render :layout => false }
60
+ end
61
+
62
+ # set up some parameters for allowing the batch controls to show appropiately
63
+ @max_batch_size = 80
64
+ count_on_page = @document_list.count {|doc| batch.index(doc.id)}
65
+ @disable_select_all = @document_list.count > @max_batch_size
66
+ batch_size = batch.uniq.size
67
+ @result_set_size = @response.response["numFound"]
68
+ @empty_batch = batch.empty?
69
+ @all_checked = (count_on_page == @document_list.count)
70
+ @entire_result_set_selected = @response.response["numFound"] == batch_size
71
+ @batch_size_on_other_page = batch_size - count_on_page
72
+ @batch_part_on_other_page = (@batch_size_on_other_page) > 0
73
+ end
74
+
75
+ def activity
76
+ # reverse events since we're prepending rows. without reverse, old events wind up first
77
+ events = current_user.events.reverse
78
+ # filter events to include only those that have occurred since params[:since]
79
+ events.select! { |event| event[:timestamp].to_i > params[:since].to_i } if params[:since]
80
+ # return the event, a formatted date string, and a numerical timestamp
81
+ render :json => events.map { |event| [event[:action], "#{time_ago_in_words(Time.at(event[:timestamp].to_i))} ago", event[:timestamp].to_i] }
82
+ rescue
83
+ render :json => []
84
+ end
85
+
86
+ protected
87
+ # show only files with edit permissions in lib/hydra/access_controls_enforcement.rb apply_gated_discovery
88
+ def discovery_permissions
89
+ ["edit"]
90
+ end
91
+ end
92
+ end
@@ -15,6 +15,7 @@
15
15
  module Sufia
16
16
  module DownloadsControllerBehavior
17
17
  extend ActiveSupport::Concern
18
+ include Hydra::Controller::DownloadBehavior
18
19
 
19
20
  included do
20
21
  # module mixes in normalize_identifier method
@@ -24,47 +25,13 @@ module Sufia
24
25
  prepend_before_filter :normalize_identifier
25
26
  end
26
27
 
27
- def show
28
- if can? :read, params[:id]
29
- asset = ActiveFedora::Base.load_instance_from_solr(params[:id])
30
- # we can now examine @asset and determine if we should send_content, or some other action.
31
- send_content (asset)
32
- else
33
- logger.info "Can not read #{params[:id]}"
34
- raise Hydra::AccessDenied.new("You do not have sufficient access privileges to read this document, which has been marked private.", :read, params[:id])
35
- end
36
- end
37
-
38
- protected
39
-
40
28
  def datastream_name
41
- @datastream_name ||= params[:datastream_id] || DownloadsController.default_content_dsid
42
- end
43
-
44
- def send_content(asset)
45
- opts = {disposition: 'inline'}
46
- if default_datastream?
47
- opts[:filename] = params["filename"] || asset.label
48
- else
49
- opts[:filename] = params[:datastream_id]
50
- end
51
- ds = asset.datastreams[datastream_name]
52
- raise ActionController::RoutingError.new('Not Found') if ds.nil?
53
- data = ds.content
54
- opts[:type] = ds.mimeType
55
- send_data data, opts
56
- end
57
-
58
- def default_datastream?
59
- datastream_name == self.class.default_content_dsid
60
- end
61
-
62
- private
63
-
64
- module ClassMethods
65
- def default_content_dsid
66
- "content"
29
+ if datastream.dsid == self.class.default_content_dsid
30
+ params[:filename] || asset.label
31
+ else
32
+ params[:datastream_id]
67
33
  end
68
34
  end
35
+
69
36
  end
70
37
  end