sufia 6.0.0.rc3 → 6.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -3
  3. data/README.md +2 -18
  4. data/SUFIA_VERSION +1 -1
  5. data/app/assets/javascripts/sufia.js +1 -0
  6. data/app/assets/javascripts/sufia/featured_researcher.js +14 -0
  7. data/app/assets/javascripts/sufia/user_search.js +5 -2
  8. data/app/assets/stylesheets/sufia/_buttons.scss +68 -8
  9. data/app/assets/stylesheets/sufia/_dashboard.scss +20 -2
  10. data/app/assets/stylesheets/sufia/_featured.scss +4 -0
  11. data/app/assets/stylesheets/sufia/_file-listing.scss +4 -0
  12. data/app/assets/stylesheets/sufia/_header.scss +31 -35
  13. data/app/assets/stylesheets/sufia/_settings.scss +40 -3
  14. data/app/assets/stylesheets/sufia/_styles.scss +2 -14
  15. data/app/controllers/batch_controller.rb +1 -44
  16. data/app/controllers/concerns/sufia/batch_controller_behavior.rb +55 -0
  17. data/app/controllers/concerns/sufia/files_controller_behavior.rb +7 -3
  18. data/app/controllers/concerns/sufia/single_use_links_controller_behavior.rb +51 -0
  19. data/app/controllers/concerns/sufia/single_use_links_viewer_controller_behavior.rb +58 -0
  20. data/app/controllers/content_blocks_controller.rb +10 -1
  21. data/app/controllers/single_use_links_controller.rb +2 -41
  22. data/app/controllers/single_use_links_viewer_controller.rb +1 -50
  23. data/app/helpers/content_block_helper.rb +5 -1
  24. data/app/views/batch/edit.html.erb +1 -1
  25. data/app/views/batch_edits/_delete_selected.html.erb +2 -2
  26. data/app/views/collections/_sort_and_per_page.html.erb +1 -1
  27. data/app/views/content_blocks/_featured_researcher.html.erb +3 -0
  28. data/app/views/content_blocks/index.html.erb +7 -0
  29. data/app/views/dashboard/_index_partials/_user_info.html.erb +2 -2
  30. data/app/views/generic_files/_permission.html.erb +1 -1
  31. data/app/views/generic_files/show.html.erb +1 -1
  32. data/app/views/generic_files/upload/_form_fields.html.erb +3 -3
  33. data/app/views/homepage/_featured_researcher.html.erb +1 -0
  34. data/app/views/my/_sort_and_per_page.html.erb +1 -1
  35. data/config/routes.rb +1 -0
  36. data/lib/generators/sufia/install_generator.rb +16 -0
  37. data/lib/sufia/version.rb +1 -1
  38. data/spec/controllers/content_blocks_controller_spec.rb +14 -0
  39. data/spec/jobs/sufia_resque_queue_spec.rb +49 -0
  40. data/spec/models/ability_spec.rb +3 -0
  41. data/spec/test_app_templates/lib/generators/test_app_generator.rb +0 -10
  42. data/spec/views/dashboard/index_spec.rb +2 -2
  43. data/spec/views/generic_file/show.html.erb_spec.rb +14 -2
  44. data/sufia-models/app/models/concerns/sufia/ability.rb +1 -0
  45. data/sufia-models/lib/generators/sufia/models/install_generator.rb +5 -10
  46. data/sufia-models/lib/sufia/models/resque.rb +8 -0
  47. data/sufia-models/lib/sufia/models/version.rb +1 -1
  48. metadata +13 -5
@@ -0,0 +1,55 @@
1
+ module Sufia
2
+ module BatchControllerBehavior
3
+ extend ActiveSupport::Concern
4
+ include Hydra::Controller::ControllerBehavior
5
+
6
+ included do
7
+ layout "sufia-one-column"
8
+
9
+ before_filter :has_access?
10
+ ActiveSupport::Deprecation.deprecate_methods(BatchController, :initialize_fields)
11
+ class_attribute :edit_form_class
12
+ self.edit_form_class = Sufia::Forms::BatchEditForm
13
+ end
14
+
15
+ def edit
16
+ @batch = Batch.find_or_create(params[:id])
17
+ @form = edit_form
18
+ end
19
+
20
+ def update
21
+ authenticate_user!
22
+ @batch = Batch.find_or_create(params[:id])
23
+ @batch.status = ["processing"]
24
+ @batch.save
25
+ file_attributes = edit_form_class.model_attributes(params[:generic_file])
26
+ Sufia.queue.push(BatchUpdateJob.new(current_user.user_key, params[:id], params[:title], file_attributes, params[:visibility]))
27
+ flash[:notice] = 'Your files are being processed by ' + t('sufia.product_name') + ' in the background. The metadata and access controls you specified are being applied. Files will be marked <span class="label label-danger" title="Private">Private</span> until this process is complete (shouldn\'t take too long, hang in there!). You may need to refresh your dashboard to see these updates.'
28
+ if uploading_on_behalf_of? @batch
29
+ redirect_to sufia.dashboard_shares_path
30
+ else
31
+ redirect_to sufia.dashboard_files_path
32
+ end
33
+ end
34
+
35
+ protected
36
+
37
+ def edit_form
38
+ generic_file = ::GenericFile.new(creator: [current_user.name], title: @batch.generic_files.map(&:label))
39
+ edit_form_class.new(generic_file)
40
+ end
41
+
42
+ # override this method if you need to initialize more complex RDF assertions (b-nodes)
43
+ def initialize_fields(file)
44
+ file.initialize_fields
45
+ end
46
+
47
+ def uploading_on_behalf_of? batch
48
+ file = batch.generic_files.first
49
+ return false if file.nil? || file.on_behalf_of.blank?
50
+ current_user.user_key != file.on_behalf_of
51
+ end
52
+
53
+ end
54
+ end
55
+
@@ -40,6 +40,10 @@ module Sufia
40
40
  before_filter :build_breadcrumbs, only: [:show, :edit, :stats]
41
41
  load_resource only: [:audit]
42
42
  load_and_authorize_resource except: [:index, :audit]
43
+
44
+ class_attribute :edit_form_class, :presenter_class
45
+ self.edit_form_class = Sufia::Forms::GenericFileEditForm
46
+ self.presenter_class = Sufia::GenericFilePresenter
43
47
  end
44
48
 
45
49
  # routed to /files/new
@@ -143,7 +147,7 @@ module Sufia
143
147
  end
144
148
 
145
149
  def presenter
146
- Sufia::GenericFilePresenter.new(@generic_file)
150
+ presenter_class.new(@generic_file)
147
151
  end
148
152
 
149
153
  def version_list
@@ -151,7 +155,7 @@ module Sufia
151
155
  end
152
156
 
153
157
  def edit_form
154
- Sufia::Forms::GenericFileEditForm.new(@generic_file)
158
+ edit_form_class.new(@generic_file)
155
159
  end
156
160
 
157
161
  def audit_service
@@ -188,7 +192,7 @@ module Sufia
188
192
 
189
193
  # this is provided so that implementing application can override this behavior and map params to different attributes
190
194
  def update_metadata
191
- file_attributes = Sufia::Forms::GenericFileEditForm.model_attributes(params[:generic_file])
195
+ file_attributes = edit_form_class.model_attributes(params[:generic_file])
192
196
  actor.update_metadata(file_attributes, params[:visibility])
193
197
  end
194
198
 
@@ -0,0 +1,51 @@
1
+ module Sufia
2
+ module SingleUseLinksControllerBehavior
3
+ extend ActiveSupport::Concern
4
+ included do
5
+
6
+ before_filter :authenticate_user!
7
+ before_filter :authorize_user!
8
+ # Catch permission errors
9
+ rescue_from Hydra::AccessDenied, CanCan::AccessDenied do |exception|
10
+ if current_user and current_user.persisted?
11
+ redirect_to root_url, alert: "You do not have sufficient privileges to create links to this document"
12
+ else
13
+ session["user_return_to"] = request.url
14
+ redirect_to new_user_session_url, alert: exception.message
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ def new_download
21
+ @su = SingleUseLink.create itemId: params[:id], path: sufia.download_path(id: asset)
22
+ @link = sufia.download_single_use_link_path(@su.downloadKey)
23
+
24
+ respond_to do |format|
25
+ format.html
26
+ format.js { render js: @link }
27
+ end
28
+ end
29
+
30
+ def new_show
31
+ @su = SingleUseLink.create itemId: params[:id], path: sufia.polymorphic_path(asset)
32
+ @link = sufia.show_single_use_link_path(@su.downloadKey)
33
+
34
+ respond_to do |format|
35
+ format.html
36
+ format.js { render js: @link }
37
+ end
38
+ end
39
+
40
+
41
+ protected
42
+ def authorize_user!
43
+ authorize! :edit, asset
44
+ end
45
+
46
+ def asset
47
+ @asset ||= ActiveFedora::Base.load_instance_from_solr(params[:id])
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,58 @@
1
+ require 'sufia/single_use_error'
2
+
3
+ module Sufia
4
+ module SingleUseLinksViewerControllerBehavior
5
+ extend ActiveSupport::Concern
6
+ include Sufia::DownloadsControllerBehavior
7
+ included do
8
+ skip_before_filter :load_file, except: :download
9
+ rescue_from Sufia::SingleUseError, with: :render_single_use_error
10
+ rescue_from CanCan::AccessDenied, with: :render_single_use_error
11
+ rescue_from ActiveRecord::RecordNotFound, with: :render_single_use_error
12
+ class_attribute :presenter_class
13
+ self.presenter_class = Sufia::GenericFilePresenter
14
+ end
15
+
16
+ def download
17
+ raise not_found_exception unless single_use_link.path == sufia.download_path(id: @asset)
18
+ send_content
19
+ end
20
+
21
+ def show
22
+ raise not_found_exception unless single_use_link.path == sufia.polymorphic_path(@asset)
23
+
24
+ #show the file
25
+ @presenter = presenter
26
+
27
+ # create a dowload link that is single use for the user since we do not just want to show metadata we want to access it too
28
+ @su = single_use_link.create_for_path sufia.download_path(id: @asset)
29
+ @download_link = sufia.download_single_use_link_path(@su.downloadKey)
30
+ end
31
+
32
+ protected
33
+
34
+ def presenter
35
+ presenter_class.new(@asset)
36
+ end
37
+
38
+ def authorize_download!
39
+ authorize! :read, asset
40
+ end
41
+
42
+ def single_use_link
43
+ @single_use_link ||= SingleUseLink.find_by_downloadKey!(params[:id])
44
+ end
45
+
46
+ def not_found_exception
47
+ Sufia::SingleUseError.new('Single-Use Link Not Found')
48
+ end
49
+
50
+ def asset
51
+ @asset ||= ActiveFedora::Base.find(single_use_link.itemId)
52
+ end
53
+
54
+ def current_ability
55
+ @current_ability ||= SingleUseLinksViewerController::Ability.new current_user, single_use_link
56
+ end
57
+ end
58
+ end
@@ -1,5 +1,10 @@
1
1
  class ContentBlocksController < ApplicationController
2
- load_and_authorize_resource
2
+ load_and_authorize_resource except: :index
3
+ before_filter :load_featured_researchers, only: :index
4
+ authorize_resource only: :index
5
+
6
+ def index
7
+ end
3
8
 
4
9
  def create
5
10
  @content_block.save
@@ -21,4 +26,8 @@ protected
21
26
  params.require(:content_block).permit([:value, :external_key])
22
27
  end
23
28
 
29
+ def load_featured_researchers
30
+ @content_blocks = ContentBlock.recent_researchers.page(params[:page])
31
+ end
32
+
24
33
  end
@@ -1,43 +1,4 @@
1
1
  class SingleUseLinksController < ApplicationController
2
- before_filter :authenticate_user!
3
- before_filter :authorize_user!
4
-
5
- def new_download
6
- @su = SingleUseLink.create itemId: params[:id], path: sufia.download_path(id: asset)
7
- @link = sufia.download_single_use_link_path(@su.downloadKey)
8
-
9
- respond_to do |format|
10
- format.html
11
- format.js { render js: @link }
12
- end
13
- end
14
-
15
- def new_show
16
- @su = SingleUseLink.create itemId: params[:id], path: sufia.polymorphic_path(asset)
17
- @link = sufia.show_single_use_link_path(@su.downloadKey)
18
-
19
- respond_to do |format|
20
- format.html
21
- format.js { render js: @link }
22
- end
23
- end
24
-
25
- # Catch permission errors
26
- rescue_from Hydra::AccessDenied, CanCan::AccessDenied do |exception|
27
- if current_user and current_user.persisted?
28
- redirect_to root_url, alert: "You do not have sufficient privileges to create links to this document"
29
- else
30
- session["user_return_to"] = request.url
31
- redirect_to new_user_session_url, alert: exception.message
32
- end
33
- end
34
-
35
- protected
36
- def authorize_user!
37
- authorize! :edit, asset
38
- end
39
-
40
- def asset
41
- @asset ||= ActiveFedora::Base.load_instance_from_solr(params[:id])
42
- end
2
+ include Sufia::SingleUseLinksControllerBehavior
43
3
  end
4
+
@@ -1,9 +1,5 @@
1
- require 'sufia/single_use_error'
2
-
3
1
  class SingleUseLinksViewerController < ApplicationController
4
- include Sufia::DownloadsControllerBehavior
5
-
6
- skip_before_filter :load_file, except: :download
2
+ include Sufia::SingleUseLinksViewerControllerBehavior
7
3
 
8
4
  class Ability
9
5
  include CanCan::Ability
@@ -21,49 +17,4 @@ class SingleUseLinksViewerController < ApplicationController
21
17
  end
22
18
  end
23
19
 
24
- rescue_from Sufia::SingleUseError, with: :render_single_use_error
25
- rescue_from CanCan::AccessDenied, with: :render_single_use_error
26
- rescue_from ActiveRecord::RecordNotFound, with: :render_single_use_error
27
-
28
- def download
29
- raise not_found_exception unless single_use_link.path == sufia.download_path(id: @asset)
30
- send_content
31
- end
32
-
33
- def show
34
- raise not_found_exception unless single_use_link.path == sufia.polymorphic_path(@asset)
35
-
36
- #show the file
37
- @presenter = presenter
38
-
39
- # create a dowload link that is single use for the user since we do not just want to show metadata we want to access it too
40
- @su = single_use_link.create_for_path sufia.download_path(id: @asset)
41
- @download_link = sufia.download_single_use_link_path(@su.downloadKey)
42
- end
43
-
44
- protected
45
-
46
- def presenter
47
- Sufia::GenericFilePresenter.new(@asset)
48
- end
49
-
50
- def authorize_download!
51
- authorize! :read, asset
52
- end
53
-
54
- def single_use_link
55
- @single_use_link ||= SingleUseLink.find_by_downloadKey!(params[:id])
56
- end
57
-
58
- def not_found_exception
59
- Sufia::SingleUseError.new('Single-Use Link Not Found')
60
- end
61
-
62
- def asset
63
- @asset ||= ActiveFedora::Base.find(single_use_link.itemId)
64
- end
65
-
66
- def current_ability
67
- @current_ability ||= SingleUseLinksViewerController::Ability.new current_user, single_use_link
68
- end
69
20
  end
@@ -27,11 +27,15 @@ module ContentBlockHelper
27
27
  concat hidden_field_tag 'content_block[name]', content_block.name
28
28
  concat f.text_area :value, id: editing_field_id, class: "tinymce", rows: 20, cols: 120
29
29
  concat f.label :external_key, content_block.external_key_name
30
- concat f.text_field :external_key
30
+ concat f.text_field :external_key, class: key_field_class(content_block.name)
31
31
  concat content_tag(:div) { f.submit 'Save', class: "btn btn-primary" }
32
32
  }
33
33
  end
34
34
 
35
+ def key_field_class(content_block_type)
36
+ content_block_type == ContentBlock::RESEARCHER ? 'select2-user' : ''
37
+ end
38
+
35
39
  def new_form(name)
36
40
  content_block = ContentBlock.new(name: name)
37
41
  edit_form(content_block, "new_#{name}_text_area")
@@ -16,7 +16,7 @@
16
16
 
17
17
  <%= render 'generic_files/permission_form', f: f, batch: @batch %>
18
18
 
19
- <div class="row" id="permissions_submit">
19
+ <div id="permissions_submit">
20
20
  <%= button_tag type: 'submit', class: 'btn btn-primary btn-lg',
21
21
  onclick: "confirmation_needed = false;", id: "upload_submit", name: "update_permission" do %>
22
22
  <i class="glyphicon glyphicon-floppy-disk"></i> Save
@@ -1,5 +1,5 @@
1
- <%= form_tag(batch_edits_path, method: :delete, class: "batch-select-all hidden", "data-behavior" => 'batch-select-all') do -%>
1
+ <%= form_tag(batch_edits_path, method: :delete, class: "batch-select-all hidden button_to-inline", "data-behavior" => 'batch-select-all') do -%>
2
2
  <%= hidden_field_tag('update_type', 'delete_all') %>
3
3
  <%= hidden_field_tag('return_controller', params[:controller]) %>
4
- <%= 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
+ <%= submit_tag("Delete Selected", class: 'batch-all-button btn btn-danger 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" }) %>
5
5
  <% end %>
@@ -21,7 +21,7 @@
21
21
  <% end %>
22
22
  <%= render_hash_as_hidden_fields(params_for_search.except(:per_page, :sort)) %>
23
23
  &nbsp;&nbsp;&nbsp;
24
- <button class="btn btn-primary"><i class="glyphicon glyphicon-refresh"></i> Refresh</button>
24
+ <button class="btn btn-info"><i class="glyphicon glyphicon-refresh"></i> Refresh</button>
25
25
  <%= render 'view_type_group' %>
26
26
  <% end %>
27
27
  <% end unless sort_fields.empty? %>
@@ -0,0 +1,3 @@
1
+ <div class='featured-researcher'>
2
+ <%= raw(featured_researcher_block.value) %>
3
+ </div>
@@ -0,0 +1,7 @@
1
+ <h1> Featured Researchers </h1>
2
+
3
+ <div class="col-xs-12 col-sm-6">
4
+ <%= render partial: 'featured_researcher', collection: @content_blocks, as: :featured_researcher_block %>
5
+
6
+ <%= paginate @content_blocks, outer_window: 2, theme: 'blacklight', route_set: sufia %>
7
+ </div>
@@ -9,10 +9,10 @@
9
9
  </div>
10
10
 
11
11
  <div class="col-xs-6 col-sm-12 col-md-6 user-info">
12
- <%= link_to t("sufia.view_profile"), sufia.profile_path(@user), class: "btn btn-default btn-raised" %>
12
+ <%= link_to t("sufia.view_profile"), sufia.profile_path(@user), class: "btn btn-default" %>
13
13
  </div>
14
14
  <div class="col-xs-6 col-sm-12 col-md-6 user-info">
15
- <%= link_to t("sufia.edit_profile"), sufia.edit_profile_path(@user), class: "btn btn-default btn-raised" %>
15
+ <%= link_to t("sufia.edit_profile"), sufia.edit_profile_path(@user), class: "btn btn-default" %>
16
16
  </div>
17
17
  </div>
18
18
  </div>
@@ -2,7 +2,7 @@
2
2
  <%= form_for generic_file, url: sufia.generic_file_path(generic_file), html: {multipart: true, class: 'form-horizontal', id: 'permission'} do |f| %>
3
3
  <%= hidden_field_tag('redirect_tab', 'permissions') %>
4
4
  <%= render "generic_files/permission_form", f: f %>
5
- <div class="row" id="permissions_submit">
5
+ <div id="permissions_submit">
6
6
  <%= button_tag type: 'submit', class: 'btn btn-primary btn-lg', onclick: "confirmation_needed = false;", id: "upload_submit", name: "update_permission" do %>
7
7
  <i class="glyphicon glyphicon-floppy-disk"></i> Save
8
8
  <% end %>
@@ -47,7 +47,7 @@
47
47
  <%= render 'show_collections' %>
48
48
  </div>
49
49
  <div itemscope itemtype="<%= @presenter.itemtype %>" class="col-xs-12 col-sm-8">
50
- <h1 class="visibility"><%= @presenter %> <%= render_visibility_badge %></h1>
50
+ <h1 class="visibility"><%= @presenter.title.first %> <%= render_visibility_badge %></h1>
51
51
  <%= render 'show_descriptions' %>
52
52
  <%= render 'show_details' %>
53
53
  <%= render 'users/activity_log', events: @events %>
@@ -8,21 +8,21 @@
8
8
  <div class="row fileupload-buttonbar">
9
9
  <div class="col-md-7">
10
10
  <!-- The fileinput-button span is used to style the file input field as button -->
11
- <span class="btn btn-success fileinput-button">
11
+ <span class="btn btn-primary fileinput-button">
12
12
  <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
13
13
  <span aria-hidden="true">Select files...</span>
14
14
  <input type="file" name="files[]" multiple />
15
15
  </span>
16
16
  <% ua = request.env['HTTP_USER_AGENT'] %>
17
17
  <% if !!(ua =~ /Chrome/) %>
18
- <span class="btn btn-success fileinput-button">
18
+ <span class="btn btn-primary fileinput-button">
19
19
  <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
20
20
  <span aria-hidden="true">Select folder...</span>
21
21
  <input type="file" name="files[]" directory webkitdirectory mozdirectory />
22
22
  </span>
23
23
  <% end %>
24
24
  <div id="main_upload_start_span" class="activate-container visible-all-inline-block" data-toggle="tooltip" data-title="<%= t('sufia.upload_tooltip') %>">
25
- <button type="submit" class="activate-submit btn btn-primary start" id="main_upload_start">
25
+ <button type="submit" class="activate-submit btn btn-info start" id="main_upload_start">
26
26
  <i class="glyphicon glyphicon-upload"></i>
27
27
  <span>Start upload</span>
28
28
  </button>