sufia 7.3.0.rc3 → 7.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +1 -0
  3. data/.eslintrc +6 -5
  4. data/.rubocop.yml +0 -1
  5. data/.rubocop_todo.yml +0 -8
  6. data/README.md +10 -5
  7. data/app/actors/sufia/actors/attach_members_actor.rb +70 -0
  8. data/app/actors/sufia/apply_permission_template_actor.rb +4 -4
  9. data/app/actors/sufia/default_admin_set_actor.rb +10 -7
  10. data/app/assets/javascripts/sufia.js +3 -1
  11. data/app/assets/javascripts/sufia/app.js +7 -18
  12. data/app/assets/javascripts/sufia/autocomplete.es6 +56 -57
  13. data/app/assets/javascripts/sufia/autocomplete/language.es6 +1 -2
  14. data/app/assets/javascripts/sufia/autocomplete/location.es6 +1 -1
  15. data/app/assets/javascripts/sufia/autocomplete/subject.es6 +1 -3
  16. data/app/assets/javascripts/sufia/autocomplete/work.es6 +31 -22
  17. data/app/assets/javascripts/sufia/{editor.js → content_blocks.js} +0 -0
  18. data/app/assets/javascripts/sufia/editor.es6 +47 -0
  19. data/app/assets/javascripts/sufia/editor/admin_set_widget.es6 +39 -0
  20. data/app/assets/javascripts/sufia/notifications.es6 +13 -13
  21. data/app/assets/javascripts/sufia/permissions/control.es6 +3 -3
  22. data/app/assets/javascripts/sufia/permissions/group_controls.es6 +2 -2
  23. data/app/assets/javascripts/sufia/permissions/user_controls.es6 +3 -3
  24. data/app/assets/javascripts/sufia/relationships.js +4 -2
  25. data/app/assets/javascripts/sufia/relationships/control.es6 +83 -0
  26. data/app/assets/javascripts/sufia/relationships/registry.es6 +60 -0
  27. data/app/assets/javascripts/sufia/relationships/registry_entry.es6 +38 -0
  28. data/app/assets/javascripts/sufia/relationships/work.es6 +7 -0
  29. data/app/assets/javascripts/sufia/save_work/required_fields.es6 +1 -1
  30. data/app/assets/javascripts/sufia/save_work/save_work_control.es6 +19 -11
  31. data/app/assets/javascripts/sufia/save_work/visibility_component.es6 +19 -10
  32. data/app/assets/javascripts/sufia/select_work_type.es6 +8 -6
  33. data/app/controllers/concerns/sufia/batch_uploads_controller_behavior.rb +1 -1
  34. data/app/controllers/concerns/sufia/works_controller_behavior.rb +7 -0
  35. data/app/controllers/sufia/admin/admin_sets_controller.rb +5 -2
  36. data/app/forms/sufia/forms/batch_edit_form.rb +2 -1
  37. data/app/forms/sufia/forms/work_form.rb +19 -17
  38. data/app/models/concerns/sufia/admin_set_behavior.rb +38 -0
  39. data/app/presenters/sufia/admin_set_options_presenter.rb +51 -0
  40. data/app/presenters/sufia/admin_set_presenter.rb +11 -0
  41. data/app/search_builders/sufia/find_works_search_builder.rb +1 -0
  42. data/app/services/sufia/actor_factory.rb +1 -0
  43. data/app/services/sufia/admin_set_create_service.rb +9 -9
  44. data/app/services/sufia/admin_set_service.rb +0 -28
  45. data/app/services/sufia/workflow/abstract_notification.rb +14 -1
  46. data/app/services/sufia/workflow/changes_required_notification.rb +2 -2
  47. data/app/services/sufia/workflow/deposited_notification.rb +1 -1
  48. data/app/services/sufia/workflow/pending_review_notification.rb +1 -1
  49. data/app/views/curation_concerns/base/_find_work_widget.html.erb +10 -16
  50. data/app/views/curation_concerns/base/_form.html.erb +5 -1
  51. data/app/views/curation_concerns/base/_form_child_work_relationships.html.erb +22 -32
  52. data/app/views/curation_concerns/base/_form_relationships.html.erb +4 -7
  53. data/app/views/curation_concerns/base/_guts4form.html.erb +7 -1
  54. data/app/views/sufia/admin/admin_sets/_form_participants.html.erb +3 -3
  55. data/app/views/sufia/admin/admin_sets/show.html.erb +10 -2
  56. data/config/initializers/monkey_patch_admin_set.rb +2 -0
  57. data/config/locales/sufia.en.yml +2 -0
  58. data/db/migrate/20170317141521_permission_template_change_column_workflow_name.rb +5 -0
  59. data/lib/generators/sufia/templates/workflow.json.erb +1 -0
  60. data/lib/sufia/version.rb +1 -1
  61. data/lib/tasks/migrate.rake +1 -1
  62. data/spec/actors/sufia/actors/attach_members_actor_spec.rb +68 -0
  63. data/spec/actors/sufia/apply_permission_template_actor_spec.rb +7 -3
  64. data/spec/actors/sufia/default_admin_set_actor_spec.rb +1 -1
  65. data/spec/controllers/sufia/admin/admin_sets_controller_spec.rb +21 -6
  66. data/spec/controllers/sufia/admin/permission_templates_controller_spec.rb +1 -1
  67. data/spec/controllers/sufia/batch_uploads_controller_spec.rb +24 -2
  68. data/spec/factories/permission_templates.rb +1 -0
  69. data/spec/factories/workflows.rb +1 -1
  70. data/spec/forms/curation_concerns/generic_work_form_spec.rb +5 -2
  71. data/spec/forms/sufia/forms/batch_edit_form_spec.rb +1 -1
  72. data/spec/forms/sufia/forms/work_form_spec.rb +32 -19
  73. data/spec/javascripts/autocomplete_spec.js.coffee +12 -33
  74. data/spec/javascripts/helpers/test_fixtures.js.coffee +10 -1
  75. data/spec/javascripts/relationships_control_spec.js.coffee +27 -0
  76. data/spec/javascripts/save_work_spec.js +9 -6
  77. data/spec/javascripts/visibility_component_spec.js +17 -8
  78. data/spec/models/admin_set_spec.rb +69 -0
  79. data/spec/presenters/sufia/admin_set_options_presenter_spec.rb +73 -0
  80. data/spec/presenters/sufia/admin_set_presenter_spec.rb +31 -2
  81. data/spec/services/sufia/actor_factory_spec.rb +2 -0
  82. data/spec/services/sufia/admin_set_create_service_spec.rb +4 -2
  83. data/spec/services/sufia/admin_set_service_spec.rb +0 -72
  84. data/spec/services/sufia/workflow/changes_required_notification_spec.rb +1 -1
  85. data/spec/services/sufia/workflow/deposited_notification_spec.rb +1 -1
  86. data/spec/services/sufia/workflow/pending_review_notification_spec.rb +1 -1
  87. data/spec/views/curation_concerns/base/_find_work_widget.html.erb_spec.rb +1 -2
  88. data/spec/views/curation_concerns/base/_form_child_work_relationships.html.erb_spec.rb +27 -62
  89. data/spec/views/curation_concerns/base/_form_relationships.html.erb_spec.rb +4 -2
  90. data/spec/views/sufia/admin/admin_sets/_form_participants.html.erb_spec.rb +1 -1
  91. data/spec/views/sufia/admin/admin_sets/_form_visibility.html.erb_spec.rb +3 -1
  92. data/spec/views/sufia/admin/admin_sets/show.html.erb_spec.rb +59 -0
  93. data/sufia.gemspec +3 -2
  94. data/template.rb +1 -1
  95. metadata +34 -19
  96. data/app/assets/javascripts/sufia/relationships/table.es6 +0 -206
  97. data/app/assets/javascripts/sufia/relationships/table_row.es6 +0 -79
  98. data/app/views/curation_concerns/base/_form_parent_work_relationships.html.erb +0 -43
  99. data/app/views/records/edit_fields/_in_works_ids.html.erb +0 -59
  100. data/spec/javascripts/helpers/test_responses.js +0 -13
  101. data/spec/javascripts/relationships_table_spec.js.coffee +0 -83
  102. data/spec/views/curation_concerns/base/_form_parent_work_relationships.html.erb_spec.rb +0 -114
  103. data/spec/views/records/edit_fields/_in_works_ids.html.erb_spec.rb +0 -113
@@ -1,6 +1,8 @@
1
1
  module Sufia
2
2
  module Workflow
3
3
  class AbstractNotification
4
+ include ActionView::Helpers::UrlHelper
5
+
4
6
  def self.send_notification(entity:, comment:, user:, recipients:)
5
7
  new(entity, comment, user, recipients).call
6
8
  end
@@ -13,6 +15,7 @@ module Sufia
13
15
  @comment = comment.respond_to?(:comment) ? comment.comment.to_s : ''
14
16
  @recipients = recipients
15
17
  @user = user
18
+ @entity = entity
16
19
  end
17
20
 
18
21
  def call
@@ -26,7 +29,17 @@ module Sufia
26
29
  end
27
30
 
28
31
  def message
29
- "#{title} (#{work_id}) was advanced in the workflow by #{user.user_key} and is awaiting approval #{comment}"
32
+ "#{title} (#{link_to work_id, document_path}) was advanced in the workflow by #{user.user_key} and is awaiting approval #{comment}"
33
+ end
34
+
35
+ # @return [ActiveFedora::Base] the document (work) the the Abstract WorkFlow is creating a notification for
36
+ def document
37
+ @entity.proxy_for
38
+ end
39
+
40
+ def document_path
41
+ key = document.model_name.singular_route_key
42
+ Rails.application.routes.url_helpers.send(key + "_path", document.id)
30
43
  end
31
44
 
32
45
  private
@@ -8,13 +8,13 @@ module Sufia
8
8
  end
9
9
 
10
10
  def message
11
- "#{title} (#{work_id}) requires additional changes before approval.\n\n '#{comment}'"
11
+ "#{title} (#{link_to work_id, document_path}) requires additional changes before approval.\n\n '#{comment}'"
12
12
  end
13
13
 
14
14
  private
15
15
 
16
16
  def users_to_notify
17
- user_key = ActiveFedora::Base.find(work_id).depositor
17
+ user_key = document.depositor
18
18
  super << ::User.find_by(email: user_key)
19
19
  end
20
20
  end
@@ -8,7 +8,7 @@ module Sufia
8
8
  end
9
9
 
10
10
  def message
11
- "#{title} (#{work_id}) was approved by #{user.user_key}. #{comment}"
11
+ "#{title} (#{link_to work_id, document_path}) was approved by #{user.user_key}. #{comment}"
12
12
  end
13
13
 
14
14
  private
@@ -8,7 +8,7 @@ module Sufia
8
8
  end
9
9
 
10
10
  def message
11
- "#{title} (#{work_id}) was deposited by #{user.user_key} and is awaiting approval #{comment}"
11
+ "#{title} (#{link_to work_id, document_path}) was deposited by #{user.user_key} and is awaiting approval #{comment}"
12
12
  end
13
13
 
14
14
  private
@@ -1,16 +1,10 @@
1
- <%= f.input id_type,
2
- label: false,
3
- type: :text,
4
- input_html:{
5
- id: id_name,
6
- name: f.object.model_name.param_key + '[' + id_type + '][]',
7
- :'data-autocomplete-url' => Rails.application.routes.url_helpers.qa_path + '/search/find_works',
8
- :'data-autocomplete' => 'work',
9
- :'data-user' => current_user.email,
10
- :'data-id' => id,
11
- autocomplete: 'off',
12
- :'aria-labelledby' => id_name + '_label',
13
- :class => 'new-form-control string multi_value optional related_works_ids form-control multi-text-field ui-autocomplete-input',
14
- value: ''
15
- }
16
- %>
1
+ <%= text_field_tag "find_#{name}",
2
+ '',
3
+ placeholder: t('.placeholder', default: 'Search for a work'),
4
+ autocomplete: 'off',
5
+ style: "width: 100%",
6
+ data: {
7
+ autocomplete: 'work',
8
+ 'autocomplete-url' => Rails.application.routes.url_helpers.qa_path + '/search/find_works',
9
+ 'exclude-work': id # exclude this item from the result set.
10
+ } %>
@@ -1,4 +1,8 @@
1
- <%= simple_form_for [main_app, @form], html: { multipart: true } do |f| %>
1
+ <%= simple_form_for [main_app, @form],
2
+ html: {
3
+ data: { behavior: 'work-form' },
4
+ multipart: true
5
+ } do |f| %>
2
6
  <% if f.object.errors.include?(:base) %>
3
7
  <div class="alert alert-danger alert-dismissable" role="alert">
4
8
  <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
@@ -2,21 +2,18 @@
2
2
  Code:
3
3
  app/assets/javascripts/sufia/relationships
4
4
  CSS:
5
- table.relationships-ajax-enabled : Used by sufia JS app as selector to wire up the UI functionality
6
- tr.new-row : The basic template row for cloning when user clicks "Add"
7
- .btn-remove-row : Button to remove its parent TR from the table
8
- .btn-add-row : Button to clone its parent TR and inject a new row into the table
9
- input.new-form-control : Input field for client client side validation and additional features
5
+ [data-behavior="remove-relationship"] : Button to remove its parent TR from the table
6
+ [data-behavior="add-relationship"] : Button to clone its parent TR and inject a new row into the table
10
7
  .message.has-warning : Used to display UI errors related to input values and server errors
11
8
  HTML Properties:
12
9
  table:
13
- data-query-url : URL base to append newly added work ID to for querying details (title, href)
10
+ [data-behavior="child-relationships"] : allows the javascript to be initialized
11
+ data-param-key : the parameter key value for this model type
14
12
  %>
15
13
  <div class="form-group multi_value optional managed">
16
- <%= link_to "Attach New Work", polymorphic_path([main_app, :new, :curation_concerns, :parent, curation_concern.model_name.singular], parent_id: params[:id]), target: "_blank", class: 'btn btn-primary' %>
14
+ <%= link_to "Attach New Work", polymorphic_path([main_app, :new, :curation_concerns, :parent, curation_concern.model_name.singular], parent_id: curation_concern.id), target: "_blank", class: 'btn btn-primary' %>
17
15
 
18
- <table class="table table-striped related-files relationships-ajax-enabled"
19
- data-query-url="<%= polymorphic_path([main_app, :curation_concerns, curation_concern.model_name.singular], id: '$id') %>">
16
+ <table class="table table-striped related-files" data-behavior="child-relationships" data-param-key="<%= f.object.model_name.param_key %>">
20
17
  <thead>
21
18
  <tr>
22
19
  <th>Child Work</th>
@@ -24,42 +21,35 @@ HTML Properties:
24
21
  </tr>
25
22
  </thead>
26
23
  <tbody>
27
- <tr class="hidden">
28
- <td>
29
- <% f.object.ordered_fileset_members.each do |fileset| %>
30
- <input class="related_works_ids work_filesets_ids" name="<%= f.object.model_name.param_key %>[ordered_member_ids][]" type="hidden" value="<%= fileset.id %>">
31
- <% end %>
32
- </td>
33
- <td></td>
34
- </tr>
35
- <% f.object.ordered_work_members.each do |member| %>
24
+
25
+ <%= f.fields_for :work_members do |row| %>
36
26
  <tr>
37
27
  <td>
38
- <%= link_to member.title.first, [main_app, member] %>
39
- <input class="string multi_value optional form-control related_works_ids work_child_members_ids form-control multi-text-field hidden" value="<%= member.id %>" id="work_child_members_ids" aria-labelledby="work_child_members_ids_label" name="<%= f.object.model_name.param_key %>[ordered_member_ids][]" type="text">
28
+ <%= link_to row.object.title.first, [main_app, row.object] %>
40
29
  </td>
41
30
  <td>
42
- <div class="child-actions">
43
- <%= link_to "Edit", [main_app, :edit, member], target: "_blank", class: 'btn btn-default' %>
44
- <a class="btn btn-danger btn-remove-row">Remove</a>
45
- </div>
31
+ <a class="btn btn-danger" data-behavior="remove-relationship" data-index="<%= row.index %>">Remove</a>
46
32
  </td>
47
33
  </tr>
48
34
  <% end %>
49
- <tr class="new-row">
35
+ <tr>
50
36
  <td>
51
- <a href="" class="title hidden"></a>
52
- <%= render "find_work_widget", f: f, id_name: 'work_child_members_ids', id_type: 'ordered_member_ids', user_email: current_user.email, id: f.object.model.id %>
37
+ <%= render "find_work_widget", f: f,
38
+ name: 'child_work',
39
+ id: f.object.model.id %>
53
40
  <div class="message has-warning hidden"></div>
54
41
  </td>
55
42
  <td>
56
- <div class="child-actions">
57
- <a href="" class="edit hidden btn btn-default" target="_blank">Edit</a>
58
- <a class="btn btn-danger btn-remove-row hidden">Remove</a>
59
- <a class="btn btn-primary btn-add-row">Add</a>
60
- </div>
43
+ <a class="btn btn-primary" data-behavior="add-relationship">Add</a>
61
44
  </td>
62
45
  </tr>
63
46
  </tbody>
64
47
  </table>
65
48
  </div>
49
+
50
+ <script type="text/x-tmpl" id="tmpl-child-work">
51
+ <tr>
52
+ <td>{%= o.title %}</td>
53
+ <td><button class="btn btn-danger" data-behavior="remove-relationship">Remove</button></td>
54
+ </tr>
55
+ </script>
@@ -1,7 +1,7 @@
1
1
  <% if Flipflop.assign_admin_set? %>
2
2
  <%= f.input :admin_set_id, as: :select,
3
- collection: Sufia::AdminSetService.new(controller).select_options(:deposit),
4
- include_blank: true,
3
+ include_blank: false,
4
+ collection: Sufia::AdminSetOptionsPresenter.new(Sufia::AdminSetService.new(controller)).select_options,
5
5
  input_html: { class: 'form-control' } %>
6
6
  <% end %>
7
7
 
@@ -14,10 +14,7 @@
14
14
  input_html: { class: 'form-control', multiple: true } %>
15
15
  </div>
16
16
 
17
- <% if params[:id] %>
17
+ <% if f.object.persisted? %>
18
18
  <h3><%= t("sufia.works.form.in_this_work") %></h3>
19
- <%= render 'form_child_work_relationships', f: f, id_name: 'work_child_members_ids', id_type: 'ordered_member_ids' %>
20
-
21
- <h3><%= t("sufia.works.form.in_other_works") %></h3>
22
- <%= render 'form_parent_work_relationships', f: f, id_name: 'work_parent_members_ids', id_type: 'in_works_ids' %>
19
+ <%= render 'form_child_work_relationships', f: f %>
23
20
  <% end %>
@@ -1,5 +1,5 @@
1
1
  <% # we will yield to content_for for each tab, e.g. :files_tab %>
2
- <% tabs ||= %w[metadata files relationships share] # default tab order %>
2
+ <% tabs ||= %w[metadata files relationships] # default tab order %>
3
3
  <div class="row">
4
4
  <div class="col-xs-12 col-sm-8" role="main">
5
5
 
@@ -16,6 +16,12 @@
16
16
  </a>
17
17
  </li>
18
18
  <% end %>
19
+
20
+ <li role="presentation" id="tab-share" class="hidden">
21
+ <a href="#share" aria-controls="share" role="tab" data-toggle="tab">
22
+ <i class="fa icon-share"></i> <%= t("sufia.works.form.tab.share") %>
23
+ </a>
24
+ </li>
19
25
  </ul>
20
26
 
21
27
  <!-- Tab panes -->
@@ -2,7 +2,7 @@
2
2
  <div class="panel panel-default labels">
3
3
  <div class="panel-body">
4
4
  <h2><%= t('.add_participants') %></h2>
5
- <% access_options = options_for_select([['Manager', 'manage'], ['Depositor', 'deposit'], ['Viewer', 'view']]) %>
5
+ <% access_options = options_for_select([['Depositor', 'deposit']]) %>
6
6
  <%= simple_form_for @form.permission_template,
7
7
  url: [sufia, :admin, @form, :permission_template],
8
8
  html: { id: 'group-participants-form' } do |f| %>
@@ -59,9 +59,9 @@
59
59
 
60
60
  <fieldset>
61
61
  <legend><%= t(".current_participants") %></legend>
62
- <%= render 'form_participant_table', access: 'managers', filter: :manage? %>
62
+ <%# render 'form_participant_table', access: 'managers', filter: :manage? %>
63
63
  <%= render 'form_participant_table', access: 'depositors', filter: :deposit? %>
64
- <%= render 'form_participant_table', access: 'viewers', filter: :view? %>
64
+ <%# render 'form_participant_table', access: 'viewers', filter: :view? %>
65
65
  </fieldset>
66
66
  </div>
67
67
  </div>
@@ -11,8 +11,16 @@
11
11
  <%= link_to sufia.edit_admin_admin_set_path(@presenter), class: 'btn btn-primary' do %>
12
12
  <span class="fa fa-edit"></span> <%= t(:'helpers.action.edit') %>
13
13
  <% end %>
14
- <%= link_to sufia.admin_admin_set_path(@presenter), class: 'btn btn-danger', data: { confirm: t('.confirm_delete'), method: :delete } do %>
15
- <span class="fa fa-remove"></span> <%= t(:'helpers.action.delete') %>
14
+ <% if @presenter.disable_delete? %>
15
+ <span title="<%= @presenter.disabled_message %>">
16
+ <%= link_to sufia.admin_admin_set_path(@presenter), class: 'btn btn-danger disabled' do %>
17
+ <span class="fa fa-remove"></span> <%= t(:'helpers.action.delete') %>
18
+ <% end %>
19
+ </span>
20
+ <% else %>
21
+ <%= link_to sufia.admin_admin_set_path(@presenter), class: 'btn btn-danger', data: { confirm: t('.confirm_delete'), method: :delete } do %>
22
+ <span class="fa fa-remove"></span> <%= t(:'helpers.action.delete') %>
23
+ <% end %>
16
24
  <% end %>
17
25
  </div>
18
26
  </div>
@@ -0,0 +1,2 @@
1
+ # Override CC's AdminSet to load Sufia's updated AdminSetBehavior
2
+ AdminSet.include(Sufia::AdminSetBehavior)
@@ -321,6 +321,8 @@ en:
321
321
  new:
322
322
  header: "Create New Administrative Set"
323
323
  delete:
324
+ error_default_set: "Administrative set cannot be deleted as it is the default set"
325
+ error_not_empty: "Administrative set cannot be deleted as it is not empty"
324
326
  notification: "Administrative set successfully deleted"
325
327
  form:
326
328
  tabs:
@@ -0,0 +1,5 @@
1
+ class PermissionTemplateChangeColumnWorkflowName < ActiveRecord::Migration
2
+ def change
3
+ change_column_null :permission_templates, :workflow_name, false
4
+ end
5
+ end
@@ -4,6 +4,7 @@
4
4
  "name": "one_step_mediated_deposit",
5
5
  "label": "One-step mediated deposit workflow",
6
6
  "description": "A single-step workflow for mediated deposit in which all deposits must be approved by a reviewer. Reviewer may also send deposits back to the depositor.",
7
+ "allows_access_grant": false,
7
8
  "actions": [
8
9
  {
9
10
  "name": "deposit",
@@ -1,3 +1,3 @@
1
1
  module Sufia
2
- VERSION = '7.3.0.rc3'.freeze
2
+ VERSION = '7.3.0'.freeze
3
3
  end
@@ -2,7 +2,7 @@ namespace :sufia do
2
2
  namespace :migrate do
3
3
  task move_all_works_to_admin_set: :environment do
4
4
  require 'sufia/move_all_works_to_admin_set'
5
- MoveAllWorksToAdminSet.run(AdminSet.find(Sufia::DefaultAdminSetActor::DEFAULT_ID))
5
+ MoveAllWorksToAdminSet.run(AdminSet.find(AdminSet::DEFAULT_ID))
6
6
  end
7
7
 
8
8
  desc "Migrate workflow data from 7.3.0.rc1"
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Sufia::Actors::AttachMembersActor do
4
+ let(:create_actor) do
5
+ double('create actor', create: true,
6
+ curation_concern: work,
7
+ update: true,
8
+ user: depositor)
9
+ end
10
+ let(:actor) do
11
+ CurationConcerns::Actors::ActorStack.new(work, depositor, [described_class])
12
+ end
13
+ let(:depositor) { create(:user) }
14
+ let(:work) { create(:work) }
15
+ let(:attributes) { { work_members_attributes: { '0' => { id: id } } } }
16
+
17
+ describe "#update" do
18
+ subject { actor.update(attributes) }
19
+ before do
20
+ work.ordered_members << existing_child_work
21
+ end
22
+ let(:existing_child_work) { create(:work) }
23
+ let(:id) { existing_child_work.id }
24
+
25
+ context "without useful attributes" do
26
+ let(:attributes) { {} }
27
+ it { is_expected.to be true }
28
+ end
29
+
30
+ context "when the id already exists in the members" do
31
+ it "does nothing" do
32
+ expect { subject }.not_to change { work.ordered_members.to_a }
33
+ end
34
+
35
+ context "and the _destroy flag is set" do
36
+ let(:attributes) { { work_members_attributes: { '0' => { id: id, _destroy: 'true' } } } }
37
+
38
+ it "removes from the member and the ordered members" do
39
+ expect { subject }.to change { work.ordered_members.to_a }
40
+ expect(work.ordered_member_ids).not_to include(existing_child_work.id)
41
+ expect(work.member_ids).not_to include(existing_child_work.id)
42
+ end
43
+ end
44
+ end
45
+
46
+ context "when the id does not exist in the members" do
47
+ let(:another_work) { create(:work) }
48
+ let(:id) { another_work.id }
49
+ context "and I can edit that object" do
50
+ let(:ability) { instance_double(Ability) }
51
+ before do
52
+ allow(Ability).to receive(:new).and_return(ability)
53
+ allow(ability).to receive(:can?).with(:edit, GenericWork).and_return(true)
54
+ end
55
+ it "is added to the ordered members" do
56
+ expect { subject }.to change { work.ordered_members.to_a }
57
+ expect(work.ordered_member_ids).to include(existing_child_work.id, another_work.id)
58
+ end
59
+ end
60
+
61
+ context "and I can not edit that object" do
62
+ it "does nothing" do
63
+ expect { subject }.not_to change { work.ordered_members.to_a }
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -11,7 +11,11 @@ RSpec.describe Sufia::ApplyPermissionTemplateActor do
11
11
  CurationConcerns::Actors::ActorStack.new(work, depositor, [described_class])
12
12
  end
13
13
  let(:depositor) { create(:user) }
14
- let(:work) { build(:generic_work) }
14
+ let(:work) do
15
+ build(:generic_work,
16
+ edit_users: ['Kevin'],
17
+ read_users: ['Taraji'])
18
+ end
15
19
  let(:attributes) { { admin_set_id: admin_set.id } }
16
20
  let(:admin_set) { create(:admin_set) }
17
21
  let(:permission_template) { create(:permission_template, admin_set_id: admin_set.id) }
@@ -54,9 +58,9 @@ RSpec.describe Sufia::ApplyPermissionTemplateActor do
54
58
 
55
59
  it "adds the template users to the work" do
56
60
  expect(actor.create(attributes)).to be true
57
- expect(work.edit_users).to include 'hannah'
61
+ expect(work.edit_users).to include('hannah', 'Kevin')
58
62
  expect(work.edit_groups).to include 'librarians'
59
- expect(work.read_users).to include 'gary'
63
+ expect(work.read_users).to include('gary', 'Taraji')
60
64
  expect(work.read_groups).to include 'readers'
61
65
  end
62
66
  end
@@ -22,7 +22,7 @@ RSpec.describe Sufia::DefaultAdminSetActor do
22
22
 
23
23
  context "when admin_set_id is blank" do
24
24
  let(:attributes) { { admin_set_id: '' } }
25
- let(:default_id) { described_class::DEFAULT_ID }
25
+ let(:default_id) { AdminSet::DEFAULT_ID }
26
26
 
27
27
  it "creates the default AdminSet with a PermissionTemplate and calls the next actor with the default admin set id" do
28
28
  expect(next_actor).to receive(:create).with(admin_set_id: default_id).and_return(true)
@@ -109,27 +109,30 @@ describe Sufia::Admin::AdminSetsController do
109
109
 
110
110
  describe "#update" do
111
111
  let(:admin_set) { create(:admin_set, edit_users: [user]) }
112
- let(:permission_template) { Sufia::PermissionTemplate.find_or_create_by(admin_set_id: admin_set.id) }
112
+ let(:permission_template) { create(:permission_template, admin_set_id: admin_set.id, workflow_name: workflow_name) }
113
+ let(:workflow_name) { 'one_step_mediated_deposit' }
113
114
  it 'updates a record' do
114
115
  # Prevent a save which causes Fedora to complain it doesn't know the referenced node.
115
116
  expect_any_instance_of(AdminSet).to receive(:save).and_return(true)
116
117
  patch :update, params: { id: admin_set,
117
- admin_set: { title: "Improved title", thumbnail_id: "mw22v559x", workflow_name: "one_step_mediated_deposit" } }
118
+ admin_set: { title: "Improved title", thumbnail_id: "mw22v559x", workflow_name: workflow_name } }
118
119
  expect(response).to be_redirect
119
120
  expect(assigns[:admin_set].title).to eq ['Improved title']
120
121
  expect(assigns[:admin_set].thumbnail_id).to eq 'mw22v559x'
121
- expect(permission_template.workflow_name).to eq 'one_step_mediated_deposit'
122
+ expect(permission_template.workflow_name).to eq workflow_name
122
123
  end
123
124
  end
124
125
 
125
126
  describe "#destroy" do
126
127
  let(:admin_set) { create(:admin_set, edit_users: [user]) }
128
+
127
129
  context "with empty admin set" do
128
130
  it "deletes the admin set" do
129
131
  delete :destroy, params: { id: admin_set }
130
132
  expect(response).to have_http_status(:found)
131
133
  expect(response).to redirect_to(Sufia::Engine.routes.url_helpers.admin_admin_sets_path)
132
134
  expect(flash[:notice]).to eq "Administrative set successfully deleted"
135
+ expect(AdminSet.exists?(admin_set.id)).to be false
133
136
  end
134
137
  end
135
138
  context "with a non-empty admin set" do
@@ -138,14 +141,26 @@ describe Sufia::Admin::AdminSetsController do
138
141
  admin_set.members << work
139
142
  admin_set.reload
140
143
  end
141
- it "detaches the works and deletes the admin set" do
144
+ it "doesn't delete the admin set (or work)" do
142
145
  delete :destroy, params: { id: admin_set }
143
146
  expect(response).to have_http_status(:found)
144
- expect(response).to redirect_to(Sufia::Engine.routes.url_helpers.admin_admin_sets_path)
145
- expect(flash[:notice]).to eq "Administrative set successfully deleted"
147
+ expect(response).to redirect_to(Sufia::Engine.routes.url_helpers.admin_admin_set_path(admin_set))
148
+ expect(flash[:alert]).to eq "Administrative set cannot be deleted as it is not empty"
149
+ expect(AdminSet.exists?(admin_set.id)).to be true
146
150
  expect(GenericWork.exists?(work.id)).to be true
147
151
  end
148
152
  end
153
+
154
+ context "with the default admin set" do
155
+ let(:admin_set) { create(:admin_set, edit_users: [user], id: AdminSet::DEFAULT_ID) }
156
+ it "doesn't delete the admin set" do
157
+ delete :destroy, params: { id: admin_set }
158
+ expect(response).to have_http_status(:found)
159
+ expect(response).to redirect_to(Sufia::Engine.routes.url_helpers.admin_admin_set_path(admin_set))
160
+ expect(flash[:alert]).to eq "Administrative set cannot be deleted as it is the default set"
161
+ expect(AdminSet.exists?(admin_set.id)).to be true
162
+ end
163
+ end
149
164
  end
150
165
  end
151
166
  end