curation_concerns 1.6.3 → 1.7.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/.travis.yml +2 -8
  4. data/README.md +27 -1
  5. data/app/actors/curation_concerns/actors/base_actor.rb +2 -3
  6. data/app/actors/curation_concerns/actors/file_set_actor.rb +1 -1
  7. data/app/actors/curation_concerns/actors/grant_edit_to_depositor_actor.rb +19 -0
  8. data/app/actors/curation_concerns/actors/initialize_workflow_actor.rb +19 -0
  9. data/app/assets/javascripts/curation_concerns/charts.js +47 -0
  10. data/app/assets/javascripts/curation_concerns/curation_concerns.js +2 -0
  11. data/app/assets/javascripts/curation_concerns/workflow_actions_affix.js +11 -0
  12. data/app/assets/stylesheets/curation_concerns/_admin.scss +18 -0
  13. data/app/assets/stylesheets/curation_concerns/_curation_concerns.scss +1 -0
  14. data/app/assets/stylesheets/curation_concerns/_positioning.scss +11 -0
  15. data/app/controllers/concerns/curation_concerns/act_as_admin_controller.rb +25 -0
  16. data/app/controllers/concerns/curation_concerns/admin_controller_behavior.rb +38 -0
  17. data/app/controllers/concerns/curation_concerns/admin_page.rb +18 -0
  18. data/app/controllers/concerns/curation_concerns/collections_controller_behavior.rb +3 -2
  19. data/app/controllers/concerns/curation_concerns/curation_concern_controller.rb +158 -159
  20. data/app/controllers/concerns/curation_concerns/embargoes_controller_behavior.rb +4 -6
  21. data/app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb +2 -1
  22. data/app/controllers/concerns/curation_concerns/leases_controller_behavior.rb +4 -6
  23. data/app/controllers/concerns/curation_concerns/single_use_links_viewer_controller_behavior.rb +2 -1
  24. data/app/controllers/curation_concerns/admin/workflow_roles_controller.rb +36 -0
  25. data/app/controllers/curation_concerns/workflow_actions_controller.rb +25 -0
  26. data/app/conversions/power_converters/polymorphic_type.rb +7 -0
  27. data/app/conversions/power_converters/sipity_action.rb +9 -0
  28. data/app/conversions/power_converters/sipity_action_name.rb +8 -0
  29. data/app/conversions/power_converters/sipity_agent.rb +6 -0
  30. data/app/conversions/power_converters/sipity_entity.rb +12 -0
  31. data/app/conversions/power_converters/sipity_role.rb +8 -0
  32. data/app/conversions/power_converters/sipity_workflow_id.rb +16 -0
  33. data/app/conversions/power_converters/sipity_workflow_state.rb +10 -0
  34. data/app/conversions/power_converters.rb +6 -0
  35. data/app/forms/curation_concerns/forms/workflow_action_form.rb +62 -0
  36. data/app/forms/curation_concerns/forms/workflow_responsibility_form.rb +42 -0
  37. data/app/helpers/curation_concerns/charts_helper.rb +23 -0
  38. data/app/helpers/curation_concerns/main_app_helpers.rb +1 -0
  39. data/app/helpers/curation_concerns/url_helper.rb +2 -5
  40. data/app/indexers/curation_concerns/indexes_workflow.rb +44 -0
  41. data/app/indexers/curation_concerns/work_indexer.rb +1 -2
  42. data/app/jobs/import_export_job.rb +46 -0
  43. data/app/models/concerns/curation_concerns/ability.rb +2 -0
  44. data/app/models/concerns/curation_concerns/permissions/writable.rb +7 -8
  45. data/app/models/concerns/curation_concerns/publishable.rb +6 -0
  46. data/app/models/concerns/curation_concerns/solr_document_behavior.rb +8 -0
  47. data/app/models/concerns/curation_concerns/user.rb +5 -0
  48. data/app/models/curation_concerns/group.rb +23 -0
  49. data/app/models/curation_concerns/workflow_action_info.rb +13 -0
  50. data/app/models/sipity/agent.rb +21 -0
  51. data/app/models/sipity/comment.rb +13 -0
  52. data/app/models/sipity/entity.rb +32 -0
  53. data/app/models/sipity/entity_specific_responsibility.rb +21 -0
  54. data/app/models/sipity/method.rb +5 -0
  55. data/app/models/sipity/notifiable_context.rb +26 -0
  56. data/app/models/sipity/notification.rb +28 -0
  57. data/app/models/sipity/notification_recipient.rb +17 -0
  58. data/app/models/sipity/role.rb +43 -0
  59. data/app/models/sipity/workflow.rb +19 -0
  60. data/app/models/sipity/workflow_action.rb +25 -0
  61. data/app/models/sipity/workflow_responsibility.rb +23 -0
  62. data/app/models/sipity/workflow_role.rb +13 -0
  63. data/app/models/sipity/workflow_state.rb +26 -0
  64. data/app/models/sipity/workflow_state_action.rb +9 -0
  65. data/app/models/sipity/workflow_state_action_permission.rb +8 -0
  66. data/app/models/vocab/fedora_resource_status.rb +4 -1
  67. data/app/presenters/curation_concerns/admin/workflow_role_presenter.rb +40 -0
  68. data/app/presenters/curation_concerns/work_show_presenter.rb +4 -0
  69. data/app/presenters/curation_concerns/workflow_presenter.rb +43 -0
  70. data/app/renderers/curation_concerns/renderers/rights_attribute_renderer.rb +1 -1
  71. data/app/search_builders/curation_concerns/search_filters.rb +0 -1
  72. data/app/services/curation_concerns/actors/actor_factory.rb +3 -1
  73. data/app/services/curation_concerns/admin_set_service.rb +13 -4
  74. data/app/services/curation_concerns/work_form_service.rb +11 -0
  75. data/app/services/curation_concerns/workflow/action_taken_service.rb +57 -0
  76. data/app/services/curation_concerns/workflow/activate_object.rb +9 -0
  77. data/app/services/curation_concerns/workflow/deactivate_object.rb +11 -0
  78. data/app/services/curation_concerns/workflow/default_workflow_strategy.rb +13 -0
  79. data/app/services/curation_concerns/workflow/method_generator.rb +55 -0
  80. data/app/services/curation_concerns/workflow/notification_configuration_parameter.rb +42 -0
  81. data/app/services/curation_concerns/workflow/notification_generator.rb +64 -0
  82. data/app/services/curation_concerns/workflow/notification_service.rb +66 -0
  83. data/app/services/curation_concerns/workflow/permission_generator.rb +95 -0
  84. data/app/services/curation_concerns/workflow/permission_query.rb +432 -0
  85. data/app/services/curation_concerns/workflow/remove_depositor_permissions.rb +11 -0
  86. data/app/services/curation_concerns/workflow/sipity_actions_generator.rb +49 -0
  87. data/app/services/curation_concerns/workflow/state_machine_generator.rb +102 -0
  88. data/app/services/curation_concerns/workflow/status_list_service.rb +52 -0
  89. data/app/services/curation_concerns/workflow/workflow_action_service.rb +56 -0
  90. data/app/services/curation_concerns/workflow/workflow_by_model_name_strategy.rb +14 -0
  91. data/app/services/curation_concerns/workflow/workflow_factory.rb +64 -0
  92. data/app/services/curation_concerns/workflow/workflow_importer.rb +103 -0
  93. data/app/services/curation_concerns/workflow/workflow_permissions_generator.rb +49 -0
  94. data/app/services/curation_concerns/workflow/workflow_schema.rb +56 -0
  95. data/app/services/rights_service.rb +1 -1
  96. data/app/services/sipity.rb +2 -0
  97. data/app/sources/curation_concerns/resource_statistics_source.rb +101 -0
  98. data/app/values/curation_concerns/chart_data.rb +61 -0
  99. data/app/views/curation_concerns/admin/_admin_menu.html.erb +5 -0
  100. data/app/views/curation_concerns/admin/_resource_stats.html.erb +43 -0
  101. data/app/views/curation_concerns/admin/_sidebar.html.erb +3 -0
  102. data/app/views/curation_concerns/admin/_total_embargo_visibility.html.erb +21 -0
  103. data/app/views/curation_concerns/admin/_total_objects.html.erb +1 -0
  104. data/app/views/curation_concerns/admin/_total_objects_charts.html.erb +12 -0
  105. data/app/views/curation_concerns/admin/index.html.erb +11 -0
  106. data/app/views/curation_concerns/admin/widgets/_pie.html.erb +1 -0
  107. data/app/views/curation_concerns/admin/workflow.html.erb +31 -0
  108. data/app/views/curation_concerns/admin/workflow_roles/index.html.erb +45 -0
  109. data/app/views/curation_concerns/base/_form_rights.html.erb +1 -1
  110. data/app/views/curation_concerns/base/_workflow_actions.html.erb +39 -0
  111. data/app/views/curation_concerns/base/show.html.erb +2 -0
  112. data/app/views/curation_concerns/file_sets/media_display/_office_document.html.erb +0 -1
  113. data/app/views/layouts/_head_tag_content.html.erb +13 -0
  114. data/app/views/layouts/admin.html.erb +10 -0
  115. data/app/views/shared/_my_actions.html.erb +4 -1
  116. data/config/initializers/precompile_assets.rb +1 -0
  117. data/config/locales/curation_concerns.en.yml +97 -56
  118. data/config/routes.rb +7 -0
  119. data/curation_concerns.gemspec +9 -3
  120. data/db/migrate/20160919151348_create_sipity.rb +163 -0
  121. data/db/migrate/20161012182404_create_sipity_workflow_methods.rb +10 -0
  122. data/lib/curation_concerns/configuration.rb +68 -0
  123. data/lib/curation_concerns/engine.rb +9 -1
  124. data/lib/curation_concerns/rails/routes.rb +1 -0
  125. data/lib/curation_concerns/version.rb +1 -1
  126. data/lib/curation_concerns.rb +1 -1
  127. data/lib/generators/curation_concerns/admin_dashboard_generator.rb +15 -0
  128. data/lib/generators/curation_concerns/install_generator.rb +7 -0
  129. data/lib/generators/curation_concerns/sample_data_generator.rb +12 -0
  130. data/lib/generators/curation_concerns/templates/app/controllers/curation_concerns/admin_controller.rb +61 -0
  131. data/lib/generators/curation_concerns/templates/catalog_controller.rb +1 -3
  132. data/lib/generators/curation_concerns/templates/config/curation_concerns.rb +39 -0
  133. data/lib/generators/curation_concerns/templates/db/seeds.rb +94 -0
  134. data/lib/generators/curation_concerns/templates/spec/models/collection_spec.rb +1 -1
  135. data/lib/generators/curation_concerns/templates/spec/models/file_set_spec.rb +1 -1
  136. data/lib/generators/curation_concerns/templates/workflow.json.erb +19 -0
  137. data/lib/generators/curation_concerns/work/USAGE +1 -0
  138. data/lib/generators/curation_concerns/work/templates/actor_spec.rb.erb +1 -1
  139. data/lib/generators/curation_concerns/work/templates/controller_spec.rb.erb +1 -1
  140. data/lib/generators/curation_concerns/work/templates/feature_spec.rb.erb +1 -1
  141. data/lib/generators/curation_concerns/work/templates/form_spec.rb.erb +1 -1
  142. data/lib/generators/curation_concerns/work/templates/model_spec.rb.erb +1 -1
  143. data/spec/abilities/admin_ability_spec.rb +15 -0
  144. data/spec/actors/curation_concerns/file_set_actor_spec.rb +24 -0
  145. data/spec/actors/curation_concerns/grant_edit_to_depositor_actor_spec.rb +32 -0
  146. data/spec/actors/curation_concerns/initialize_workflow_actor_spec.rb +33 -0
  147. data/spec/actors/curation_concerns/interpret_visibility_actor_spec.rb +1 -0
  148. data/spec/actors/curation_concerns/work_actor_spec.rb +10 -5
  149. data/spec/controllers/curation_concerns/acts_as_admin_controller_spec.rb +22 -0
  150. data/spec/controllers/curation_concerns/admin/workflow_roles_controller_spec.rb +26 -0
  151. data/spec/controllers/curation_concerns/admin_controller_spec.rb +64 -0
  152. data/spec/controllers/curation_concerns/generic_works_controller_json_spec.rb +11 -3
  153. data/spec/controllers/curation_concerns/generic_works_controller_spec.rb +4 -4
  154. data/spec/controllers/curation_concerns/workflow_actions_controller_spec.rb +36 -0
  155. data/spec/conversions/power_converters/polymorphic_type_spec.rb +22 -0
  156. data/spec/conversions/power_converters/sipity_action_name_spec.rb +32 -0
  157. data/spec/conversions/power_converters/sipity_action_spec.rb +43 -0
  158. data/spec/conversions/power_converters/sipity_agent_spec.rb +20 -0
  159. data/spec/conversions/power_converters/sipity_entity_spec.rb +46 -0
  160. data/spec/conversions/power_converters/sipity_role_spec.rb +33 -0
  161. data/spec/conversions/power_converters/sipity_workflow_id_spec.rb +28 -0
  162. data/spec/conversions/power_converters/sipity_workflow_state_spec.rb +22 -0
  163. data/spec/factories/generic_works.rb +19 -6
  164. data/spec/factories/sipity_entities.rb +7 -0
  165. data/spec/factories/workflow_actions.rb +6 -0
  166. data/spec/factories/workflow_states.rb +6 -0
  167. data/spec/factories/workflows.rb +5 -0
  168. data/spec/features/admin_spec.rb +14 -0
  169. data/spec/features/create_child_work_spec.rb +1 -1
  170. data/spec/features/create_work_spec.rb +1 -1
  171. data/spec/features/embargo_spec.rb +1 -1
  172. data/spec/features/lease_spec.rb +1 -1
  173. data/spec/features/work_generator_spec.rb +2 -2
  174. data/spec/features/workflow_roles_spec.rb +48 -0
  175. data/spec/forms/curation_concerns/forms/workflow_action_form_spec.rb +111 -0
  176. data/spec/forms/curation_concerns/forms/workflow_responsibility_form_spec.rb +33 -0
  177. data/spec/helpers/curation_concerns/charts_helper_spec.rb +62 -0
  178. data/spec/helpers/url_helper_spec.rb +11 -11
  179. data/spec/indexers/work_indexer_spec.rb +13 -1
  180. data/spec/javascripts/charts_spec.coffee +10 -0
  181. data/spec/javascripts/fixtures/chart_example.html +1 -0
  182. data/spec/jobs/import_export_job_spec.rb +28 -0
  183. data/spec/models/curation_concerns/group_spec.rb +15 -0
  184. data/spec/models/file_set_spec.rb +6 -2
  185. data/spec/models/generic_work_spec.rb +12 -0
  186. data/spec/models/sipity/agent_spec.rb +9 -0
  187. data/spec/models/sipity/comment_spec.rb +16 -0
  188. data/spec/models/sipity/entity_spec.rb +27 -0
  189. data/spec/models/sipity/entity_specific_responsibility_spec.rb +8 -0
  190. data/spec/models/sipity/notifiable_context_spec.rb +8 -0
  191. data/spec/models/sipity/notification_recipient_spec.rb +10 -0
  192. data/spec/models/sipity/notification_spec.rb +15 -0
  193. data/spec/models/sipity/role_spec.rb +30 -0
  194. data/spec/models/sipity/workflow_action_spec.rb +10 -0
  195. data/spec/models/sipity/workflow_responsibility_spec.rb +7 -0
  196. data/spec/models/sipity/workflow_role_spec.rb +7 -0
  197. data/spec/models/sipity/workflow_spec.rb +15 -0
  198. data/spec/models/sipity/workflow_state_action_permission_spec.rb +7 -0
  199. data/spec/models/sipity/workflow_state_action_spec.rb +7 -0
  200. data/spec/models/sipity/workflow_state_spec.rb +7 -0
  201. data/spec/models/user_spec.rb +12 -1
  202. data/spec/presenters/curation_concerns/work_show_presenter_spec.rb +12 -1
  203. data/spec/presenters/curation_concerns/workflow_presenter_spec.rb +39 -0
  204. data/spec/routing/route_spec.rb +13 -0
  205. data/spec/services/curation_concerns/admin_set_service_spec.rb +13 -0
  206. data/spec/services/curation_concerns/qa_select_service_spec.rb +75 -0
  207. data/spec/services/curation_concerns/workflow/action_taken_service_spec.rb +76 -0
  208. data/spec/services/curation_concerns/workflow/activate_object_spec.rb +20 -0
  209. data/spec/services/curation_concerns/workflow/deactivate_object_spec.rb +20 -0
  210. data/spec/services/curation_concerns/workflow/method_generator_spec.rb +43 -0
  211. data/spec/services/curation_concerns/workflow/notification_configuration_parameter_spec.rb +25 -0
  212. data/spec/services/curation_concerns/workflow/notification_generator_spec.rb +27 -0
  213. data/spec/services/curation_concerns/workflow/notification_service_spec.rb +81 -0
  214. data/spec/services/curation_concerns/workflow/permission_generator_spec.rb +52 -0
  215. data/spec/services/curation_concerns/workflow/permission_query_spec.rb +179 -0
  216. data/spec/services/curation_concerns/workflow/remove_depositor_permissions_spec.rb +21 -0
  217. data/spec/services/curation_concerns/workflow/sipity_actions_generator_spec.rb +30 -0
  218. data/spec/services/curation_concerns/workflow/state_machine_generator_spec.rb +46 -0
  219. data/spec/services/curation_concerns/workflow/status_list_service_spec.rb +46 -0
  220. data/spec/services/curation_concerns/workflow/workflow_importer_spec.rb +50 -0
  221. data/spec/services/curation_concerns/workflow/workflow_permissions_generator_spec.rb +37 -0
  222. data/spec/services/curation_concerns/workflow/workflow_schema_spec.rb +85 -0
  223. data/spec/sources/curation_concerns/resource_statistics_source_spec.rb +137 -0
  224. data/spec/spec_helper.rb +8 -1
  225. data/spec/test_app_templates/lib/generators/test_app_generator.rb +11 -0
  226. data/spec/views/curation_concerns/admin/_admin_menu.html.erb_spec.rb +23 -0
  227. data/spec/views/curation_concerns/admin/_resource_stats.html.erb_spec.rb +33 -0
  228. data/spec/views/curation_concerns/admin/_total_objects_charts.html.erb_spec.rb +28 -0
  229. data/spec/views/curation_concerns/admin/index.html.erb_spec.rb +26 -0
  230. data/spec/views/curation_concerns/admin/widgets/_pie.html.erb_spec.rb +17 -0
  231. data/spec/views/curation_concerns/base/file_manager.html.erb_spec.rb +1 -1
  232. data/spec/views/curation_concerns/base/show.html.erb_spec.rb +33 -0
  233. data/spec/views/curation_concerns/permissions/confirm.html.erb_spec.rb +1 -1
  234. data/spec/views/shared/_my_actions.html.erb_spec.rb +1 -0
  235. data/tasks/workflow.rake +8 -0
  236. metadata +335 -21
@@ -0,0 +1,42 @@
1
+ module CurationConcerns
2
+ module Forms
3
+ class WorkflowResponsibilityForm
4
+ def initialize(params = {})
5
+ model_instance.workflow_role_id = params[:workflow_role_id]
6
+ if params[:user_id]
7
+ user = ::User.find(params[:user_id])
8
+ model_instance.agent = user.to_sipity_agent
9
+ end
10
+ end
11
+
12
+ def model_instance
13
+ @model ||= Sipity::WorkflowResponsibility.new
14
+ end
15
+
16
+ def to_model
17
+ model_instance
18
+ end
19
+
20
+ delegate :model_name, :to_key, :workflow_role_id, :persisted?, :save!, to: :model_instance
21
+
22
+ def user_id
23
+ nil
24
+ end
25
+
26
+ def user_options
27
+ ::User.all
28
+ end
29
+
30
+ # The select options for choosing a responsibility
31
+ def workflow_role_options
32
+ Sipity::WorkflowRole.all.map { |wf_role| [label(wf_role), wf_role.id] }
33
+ end
34
+
35
+ private
36
+
37
+ def label(wf_role)
38
+ "#{wf_role.workflow.name} - #{wf_role.role.name}"
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,23 @@
1
+ module CurationConcerns
2
+ module ChartsHelper
3
+ # @example A chart with a drilldown
4
+ # {
5
+ # "First" => {
6
+ # "Second" => 3,
7
+ # "Third" => 3
8
+ # }
9
+ # }
10
+ # @example A chart without a drilldown
11
+ # {
12
+ # "First" => 3,
13
+ # "Second" => 4
14
+ # }
15
+ def hash_to_chart(data)
16
+ data = ::CurationConcerns::ChartData.new(data)
17
+ {
18
+ drilldown: { series: data.drilldown },
19
+ series: data.series
20
+ }
21
+ end
22
+ end
23
+ end
@@ -8,5 +8,6 @@ module CurationConcerns::MainAppHelpers
8
8
  include CurationConcerns::EmbargoHelper
9
9
  include CurationConcerns::LeaseHelper
10
10
  include CurationConcerns::CollectionsHelper
11
+ include CurationConcerns::ChartsHelper
11
12
  include CurationConcerns::RightsHelper
12
13
  end
@@ -3,11 +3,8 @@ module CurationConcerns
3
3
  # override Blacklight so we can use our 'curation_concern' namespace
4
4
  # We may also pass in a ActiveFedora document instead of a SolrDocument
5
5
  def url_for_document(doc, _options = {})
6
- if doc.collection?
7
- doc
8
- else
9
- polymorphic_path([main_app, doc])
10
- end
6
+ return doc if doc.collection?
7
+ [main_app, doc]
11
8
  end
12
9
 
13
10
  # generated models get registered as curation concerns and need a
@@ -0,0 +1,44 @@
1
+ module CurationConcerns
2
+ module IndexesWorkflow
3
+ STORED_BOOL = Solrizer::Descriptor.new(:boolean, :stored, :indexed)
4
+ # Adds thumbnail indexing to the solr document
5
+ def generate_solr_document
6
+ super.tap do |solr_doc|
7
+ index_suppressed(solr_doc)
8
+ index_workflow_fields(solr_doc)
9
+ end
10
+ end
11
+
12
+ # Write the suppressed status into the solr_document
13
+ # @params [Hash] solr_document the solr document to add the field to
14
+ def index_suppressed(solr_document)
15
+ solr_document[suppressed_field] = object.suppressed?
16
+ end
17
+
18
+ # Write the workflow roles and state so one can see where the document moves to next
19
+ # @params [Hash] solr_document the solr document to add the field to
20
+ def index_workflow_fields(solr_document)
21
+ return unless object.persisted?
22
+ entity = PowerConverter.convert_to_sipity_entity(object)
23
+ return if entity.nil?
24
+ solr_document[workflow_role_field] = workflow_roles(entity).map { |role| "#{entity.workflow.name}-#{role}" }
25
+ solr_document[workflow_state_name_field] = entity.workflow_state.name if entity.workflow_state
26
+ end
27
+
28
+ def workflow_state_name_field
29
+ @workflow_state_name_field ||= Solrizer.solr_name('workflow_state_name', :symbol)
30
+ end
31
+
32
+ def workflow_role_field
33
+ @workflow_role_field ||= Solrizer.solr_name('actionable_workflow_roles', :symbol)
34
+ end
35
+
36
+ def workflow_roles(entity)
37
+ CurationConcerns::Workflow::PermissionQuery.scope_roles_associated_with_the_given_entity(entity: entity)
38
+ end
39
+
40
+ def suppressed_field
41
+ @suppressed_field ||= Solrizer.solr_name('suppressed', STORED_BOOL)
42
+ end
43
+ end
44
+ end
@@ -1,13 +1,12 @@
1
1
  module CurationConcerns
2
2
  class WorkIndexer < ActiveFedora::IndexingService
3
3
  include IndexesThumbnails
4
- STORED_BOOL = Solrizer::Descriptor.new(:boolean, :stored, :indexed)
4
+ include IndexesWorkflow
5
5
 
6
6
  def generate_solr_document
7
7
  super.tap do |solr_doc|
8
8
  solr_doc[Solrizer.solr_name('member_ids', :symbol)] = object.member_ids
9
9
  Solrizer.set_field(solr_doc, 'generic_type', 'Work', :facetable)
10
- solr_doc[Solrizer.solr_name('suppressed', STORED_BOOL)] = object.suppressed?
11
10
  end
12
11
  end
13
12
  end
@@ -0,0 +1,46 @@
1
+ require 'open3'
2
+
3
+ class ImportExportJob < ActiveJob::Base
4
+ attr_reader :mode
5
+ include Open3
6
+
7
+ # @param [String] uri of the resource
8
+ # @option opts [String] desc_dir location of descriptions
9
+ # @option opts [String] bin_dir location of binaries
10
+ # @option opts [String] profile BagIt profile
11
+ # @option opts [String] mode import or export mode
12
+ # Notes:
13
+ # * the Fedora import-export tool is not release yet
14
+ # * current parameters are undergoing changes
15
+ # * import features are not yet available
16
+ # * exporting bags is not yet supported
17
+ def perform(uri, options = {})
18
+ @mode = options.fetch(:mode, "export")
19
+ call(uri,
20
+ options.fetch(:desc_dir, CurationConcerns.config.descriptions_directory),
21
+ options.fetch(:bin_dir, CurationConcerns.config.binaries_directory),
22
+ options.fetch(:profile, nil))
23
+ end
24
+
25
+ private
26
+
27
+ def call(uri, desc_dir, bin_dir, _profile = nil)
28
+ command = "java -jar #{CurationConcerns.config.import_export_jar_file_path} --mode #{mode} --resource #{uri} --descDir #{desc_dir} --binDir #{bin_dir}"
29
+ internal_call(command)
30
+ end
31
+
32
+ def internal_call(command)
33
+ stdin, stdout, stderr, wait_thr = popen3(command)
34
+ begin
35
+ out = stdout.read
36
+ err = stderr.read
37
+ exit_status = wait_thr.value
38
+ raise "Fedora command failed: \"#{command}\"\n#{err}" unless exit_status.success?
39
+ out
40
+ ensure
41
+ stdin.close
42
+ stdout.close
43
+ stderr.close
44
+ end
45
+ end
46
+ end
@@ -28,11 +28,13 @@ module CurationConcerns
28
28
  end
29
29
 
30
30
  def admin_permissions
31
+ can :read, :admin_dashboard
31
32
  alias_action :edit, to: :update
32
33
  alias_action :show, to: :read
33
34
  alias_action :discover, to: :read
34
35
 
35
36
  can :manage, curation_concerns_models
37
+ can :manage, Sipity::WorkflowResponsibility
36
38
  end
37
39
 
38
40
  # Override this method in your ability model if you use a different group
@@ -9,6 +9,13 @@ module CurationConcerns
9
9
 
10
10
  included do
11
11
  validate :paranoid_permissions
12
+
13
+ class_attribute :paranoid_edit_permissions
14
+ self.paranoid_edit_permissions =
15
+ [
16
+ { key: :edit_groups, message: 'Public cannot have edit access', condition: ->(obj) { obj.edit_groups.include?('public') } },
17
+ { key: :edit_groups, message: 'Registered cannot have edit access', condition: ->(obj) { obj.edit_groups.include?('registered') } }
18
+ ]
12
19
  end
13
20
 
14
21
  def paranoid_permissions
@@ -21,14 +28,6 @@ module CurationConcerns
21
28
  end
22
29
  valid
23
30
  end
24
-
25
- def paranoid_edit_permissions
26
- [
27
- { key: :edit_users, message: 'Depositor must have edit access', condition: ->(obj) { !obj.edit_users.include?(obj.depositor) } },
28
- { key: :edit_groups, message: 'Public cannot have edit access', condition: ->(obj) { obj.edit_groups.include?('public') } },
29
- { key: :edit_groups, message: 'Registered cannot have edit access', condition: ->(obj) { obj.edit_groups.include?('registered') } }
30
- ]
31
- end
32
31
  end
33
32
  end
34
33
  end
@@ -1,4 +1,5 @@
1
1
  module CurationConcerns
2
+ # Workflow considerations
2
3
  module Publishable
3
4
  extend ActiveSupport::Concern
4
5
 
@@ -15,5 +16,10 @@ module CurationConcerns
15
16
  def suppressed?
16
17
  state_workflow.new(state).pending?
17
18
  end
19
+
20
+ def to_sipity_entity
21
+ raise "Can't create an entity until the model has been persisted" unless persisted?
22
+ @sipity_entity ||= Sipity::Entity.find_by(proxy_for_global_id: to_global_id.to_s)
23
+ end
18
24
  end
19
25
  end
@@ -38,6 +38,10 @@ module CurationConcerns
38
38
  def to_partial_path
39
39
  @model._to_partial_path
40
40
  end
41
+
42
+ def to_global_id
43
+ URI::GID.build app: GlobalID.app, model_name: model_name.name, model_id: @id
44
+ end
41
45
  end
42
46
  ##
43
47
  # Offer the source (ActiveFedora-based) model to Rails for some of the
@@ -162,6 +166,10 @@ module CurationConcerns
162
166
  end
163
167
  end
164
168
 
169
+ def workflow_state
170
+ first(Solrizer.solr_name('workflow_state_name', :symbol))
171
+ end
172
+
165
173
  private
166
174
 
167
175
  def date_field(field_name)
@@ -2,6 +2,7 @@ module CurationConcerns::User
2
2
  extend ActiveSupport::Concern
3
3
  included do
4
4
  delegate :can?, :cannot?, to: :ability
5
+ has_one :sipity_agent, as: :proxy_for, dependent: :destroy, class_name: 'Sipity::Agent'
5
6
  end
6
7
 
7
8
  # Redefine this for more intuitive keys in Redis
@@ -10,6 +11,10 @@ module CurationConcerns::User
10
11
  user_key.gsub(/\./, '-dot-')
11
12
  end
12
13
 
14
+ def to_sipity_agent
15
+ sipity_agent || create_sipity_agent!
16
+ end
17
+
13
18
  private
14
19
 
15
20
  def ability
@@ -0,0 +1,23 @@
1
+ module CurationConcerns
2
+ class Group
3
+ def initialize(name)
4
+ @name = name
5
+ end
6
+
7
+ attr_reader :name
8
+
9
+ def to_sipity_agent
10
+ sipity_agent || create_sipity_agent!
11
+ end
12
+
13
+ private
14
+
15
+ def sipity_agent
16
+ Sipity::Agent.find_by(proxy_for_id: name, proxy_for_type: self.class.name)
17
+ end
18
+
19
+ def create_sipity_agent!
20
+ Sipity::Agent.create!(proxy_for_id: name, proxy_for_type: self.class.name)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ module CurationConcerns
2
+ # A simple data object for holding a user, work and their workflow proxies
3
+ class WorkflowActionInfo
4
+ def initialize(work, user)
5
+ @work = work
6
+ @user = user
7
+ @entity = PowerConverter.convert(work, to: :sipity_entity)
8
+ @agent = PowerConverter.convert(user, to: :sipity_agent)
9
+ end
10
+
11
+ attr_reader :entity, :agent, :user, :work
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ module Sipity
2
+ # A proxy for something that can take an action.
3
+ #
4
+ # * A User can be an agent
5
+ # * A Group can be an agent (though Group is outside the scope of this system)
6
+ class Agent < ActiveRecord::Base
7
+ self.table_name = 'sipity_agents'
8
+
9
+ ENTITY_LEVEL_AGENT_RELATIONSHIP = 'entity_level'.freeze
10
+ WORKFLOW_LEVEL_AGENT_RELATIONSHIP = 'workflow_level'.freeze
11
+
12
+ belongs_to :proxy_for, polymorphic: true
13
+ has_many :workflow_responsibilities, dependent: :destroy, class_name: 'Sipity::WorkflowResponsibility'
14
+ has_many :entity_specific_responsibilities, dependent: :destroy, class_name: 'Sipity::EntitySpecificResponsibility'
15
+
16
+ has_many :comments,
17
+ foreign_key: :agent_id,
18
+ dependent: :destroy,
19
+ class_name: 'Sipity::Comment'
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module Sipity
2
+ # Represents a "comment" placed by the given :agent in regards to the give :entity
3
+ class Comment < ActiveRecord::Base
4
+ self.table_name = 'sipity_comments'
5
+
6
+ belongs_to :agent, class_name: 'Sipity::Agent'
7
+ belongs_to :entity, class_name: 'Sipity::Entity'
8
+
9
+ def name_of_commentor
10
+ agent.proxy_for.to_s
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ module Sipity
2
+ # A proxy for the entity that is being processed.
3
+ # By using a proxy, we need not worry about polluting the proxy's concerns
4
+ # with things related to processing.
5
+ #
6
+ # The goal is to keep this behavior separate, so that we can possibly
7
+ # extract the information.
8
+ class Entity < ActiveRecord::Base
9
+ self.table_name = 'sipity_entities'
10
+
11
+ belongs_to :workflow, class_name: 'Sipity::Workflow'
12
+ belongs_to :workflow_state, class_name: 'Sipity::WorkflowState'
13
+
14
+ has_many :entity_specific_responsibilities, dependent: :destroy, class_name: 'Sipity::EntitySpecificResponsibility'
15
+
16
+ has_many :comments,
17
+ foreign_key: :entity_id,
18
+ dependent: :destroy,
19
+ class_name: 'Sipity::Comment'
20
+
21
+ def workflow_state_name
22
+ workflow_state.name if workflow_state
23
+ end
24
+
25
+ # Defines the method #workflow_name
26
+ delegate :name, to: :workflow, prefix: :workflow
27
+
28
+ def proxy_for
29
+ @proxy_for ||= GlobalID::Locator.locate(proxy_for_global_id)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ module Sipity
2
+ # In what capacity can an agent act upon the given entity?
3
+ #
4
+ # This is an analogue to the Sipity::WorkflowResponsibility, but
5
+ # the responsibility only applies to the given entity.
6
+ #
7
+ # @example
8
+ # An Advisor for a given Student would have an
9
+ # EntitySpecificResponsibility to review an ETD submitted by the
10
+ # given Student.
11
+ # The Graduate School Reviewer would have a WorkflowResponsibility
12
+ # to review all ETDs submitted.
13
+ #
14
+ # @see Sipity::WorkflowResponsibility
15
+ class EntitySpecificResponsibility < ActiveRecord::Base
16
+ self.table_name = 'sipity_entity_specific_responsibilities'
17
+ belongs_to :entity, class_name: 'Sipity::Entity'
18
+ belongs_to :workflow_role, class_name: 'Sipity::WorkflowRole'
19
+ belongs_to :agent, class_name: 'Sipity::Agent'
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module Sipity
2
+ class Method < ActiveRecord::Base
3
+ self.table_name = 'sipity_workflow_methods'
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ module Sipity
2
+ # A bridge for defining the "contexts" in which emails are sent.
3
+ #
4
+ # When an object enters a new state, we want to be able to define what are
5
+ # the emails that should be sent.
6
+ #
7
+ # In Sipity this could be modeled by defining a NotifiableContext for a
8
+ # WorkflowState and Email.
9
+ #
10
+ # @example
11
+ # workflow_state = Sipity::WorkflowState.new
12
+ # notification = Sipity::Notification.new
13
+ #
14
+ # Sipity::NotifiableContext.new(
15
+ # scope_for_notification: workflow_state,
16
+ # reason_for_notification: 'on_enter',
17
+ # notification: notification
18
+ # )
19
+ class NotifiableContext < ActiveRecord::Base
20
+ self.table_name = 'sipity_notifiable_contexts'
21
+ belongs_to :scope_for_notification, polymorphic: true
22
+ belongs_to :notification, class_name: 'Sipity::Notification'
23
+
24
+ REASON_ACTION_IS_TAKEN = 'action_is_taken'.freeze
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ module Sipity
2
+ # Responsible for defining a notification that is associated with a given
3
+ # context; I believe the context is something that will be triggered via
4
+ # an action however, I don't believe this needs to be a "hard"
5
+ # relationship. It is instead a polymorphic relationship.
6
+ class Notification < ActiveRecord::Base
7
+ self.table_name = 'sipity_notifications'
8
+
9
+ has_many :notifiable_contexts,
10
+ dependent: :destroy,
11
+ foreign_key: :notification_id,
12
+ class_name: 'Sipity::NotifiableContext'
13
+
14
+ has_many :recipients,
15
+ dependent: :destroy,
16
+ foreign_key: :notification_id,
17
+ class_name: 'Sipity::NotificationRecipient'
18
+
19
+ NOTIFICATION_TYPE_EMAIL = 'email'.freeze
20
+
21
+ # TODO: There are other types, but for now, we are assuming just emails to send.
22
+ enum(notification_type: { NOTIFICATION_TYPE_EMAIL => NOTIFICATION_TYPE_EMAIL })
23
+
24
+ def self.valid_notification_types
25
+ notification_types.keys
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ module Sipity
2
+ # Responsible for defining who receives what email and in what capacity
3
+ # (eg to:, cc:, bcc:)
4
+ class NotificationRecipient < ActiveRecord::Base
5
+ self.table_name = 'sipity_notification_recipients'
6
+ belongs_to :notification, class_name: 'Sipity::Notification'
7
+ belongs_to :role, class_name: 'Sipity::Role'
8
+
9
+ enum(
10
+ recipient_strategy: {
11
+ 'to' => 'to',
12
+ 'cc' => 'cc',
13
+ 'bcc' => 'bcc'
14
+ }
15
+ )
16
+ end
17
+ end
@@ -0,0 +1,43 @@
1
+ module Sipity
2
+ # A role is a responsibility to do things. That is to take actions. It is
3
+ # easy to conflate a person's role with the groups to which they belong.
4
+ # A group is a set of people. The association of group with role
5
+ # indicates that the set of people have the same responsibilities.
6
+ #
7
+ # By separating Group and Role, we expose a more rich system in which we
8
+ # can talk about group membership separate from the group's
9
+ # responsibility.
10
+ #
11
+ # Another way to think of it is that a Group is a marco that expands to
12
+ # represent people. A Role is a macro that expands to represent
13
+ # responsibilities. In keeping them separate we can model more rich
14
+ # relationships.
15
+ #
16
+ # @note Roles should be verbs. They are what you do.
17
+ #
18
+ # @note This model representes the "roles" that users of the system can
19
+ # have. It is not the "role" that they had in relation to the scholarly
20
+ # work that is being deposited (i.e. co-author on a paper).
21
+ #
22
+ # @see Sipity::Agent
23
+ class Role < ActiveRecord::Base
24
+ self.table_name = 'sipity_roles'
25
+
26
+ has_many :workflow_roles,
27
+ dependent: :destroy,
28
+ class_name: 'Sipity::WorkflowRole'
29
+
30
+ has_many :email_recipients,
31
+ dependent: :destroy,
32
+ foreign_key: :role_id,
33
+ class_name: 'Sipity::NotificationRecipient'
34
+
35
+ def self.[](name)
36
+ find_or_create_by!(name: name.to_s)
37
+ end
38
+
39
+ def to_s
40
+ name
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,19 @@
1
+ module Sipity
2
+ # A named workflow for processing an entity. Originally I had thought of
3
+ # calling this a Type, but once I extracted the Processing submodule,
4
+ # type felt to much of a noun, not conveying potentiality. Workflow
5
+ # conveys "things will happen" because of this.
6
+ class Workflow < ActiveRecord::Base
7
+ self.table_name = 'sipity_workflows'
8
+
9
+ has_many :entities, dependent: :destroy, class_name: 'Sipity::Entity'
10
+ has_many :workflow_states, dependent: :destroy, class_name: 'Sipity::WorkflowState'
11
+ has_many :workflow_actions, dependent: :destroy, class_name: 'Sipity::WorkflowAction'
12
+ has_many :workflow_roles, dependent: :destroy, class_name: 'Sipity::WorkflowRole'
13
+
14
+ DEFAULT_INITIAL_WORKFLOW_STATE = 'new'.freeze
15
+ def initial_workflow_state
16
+ workflow_states.find_or_create_by!(name: DEFAULT_INITIAL_WORKFLOW_STATE)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ module Sipity
2
+ # A named thing that happens within the bounds of a :workflow.
3
+ #
4
+ # When a Sipity::WorkflowAction is taken, it may:
5
+ # * Advance the state to a new Sipity::WorkflowState (as defined by
6
+ # the :resulting_workflow_state relation)
7
+ # * Deliver one or more notifications (as defined by the
8
+ # :notifiable_contexts relation)
9
+ #
10
+ # @see CurationConcerns::Forms::WorkflowActionForm
11
+ class WorkflowAction < ActiveRecord::Base
12
+ self.table_name = 'sipity_workflow_actions'
13
+
14
+ belongs_to :workflow, class_name: 'Sipity::Workflow'
15
+ belongs_to :resulting_workflow_state, class_name: 'Sipity::WorkflowState'
16
+
17
+ has_many :workflow_state_actions, dependent: :destroy, class_name: 'Sipity::WorkflowStateAction'
18
+ has_many :triggered_methods, dependent: :destroy, class_name: 'Sipity::Method'
19
+
20
+ has_many :notifiable_contexts,
21
+ dependent: :destroy,
22
+ as: :scope_for_notification,
23
+ class_name: 'Sipity::NotifiableContext'
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ module Sipity
2
+ # In what capacity can an agent act upon all entities for the given
3
+ # Workflow
4
+ #
5
+ # This is an analogue to the Sipity::EntitySpecificResponsibility, but
6
+ # the responsibility only applies to all entities for the given
7
+ # Workflow
8
+ #
9
+ # @example
10
+ # An Advisor for a given Student would have an
11
+ # EntitySpecificResponsibility to review an ETD submitted by the
12
+ # given Student.
13
+ # The Graduate School Reviewer would have a WorkflowResponsibility
14
+ # to review all ETDs submitted.
15
+ #
16
+ # @see Sipity::Role for discussion of roles
17
+ # @see Sipity::EntitySpecificResponsibility
18
+ class WorkflowResponsibility < ActiveRecord::Base
19
+ self.table_name = 'sipity_workflow_responsibilities'
20
+ belongs_to :agent, class_name: 'Sipity::Agent'
21
+ belongs_to :workflow_role, class_name: 'Sipity::WorkflowRole'
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ module Sipity
2
+ # For a given processing workflow, what roles have a part to play in
3
+ # the processing?
4
+ class WorkflowRole < ActiveRecord::Base
5
+ self.table_name = 'sipity_workflow_roles'
6
+
7
+ belongs_to :role, class_name: 'Sipity::Role'
8
+ belongs_to :workflow, class_name: 'Sipity::Workflow'
9
+ has_many :workflow_responsibilities, dependent: :destroy, class_name: 'Sipity::WorkflowResponsibility'
10
+ has_many :workflow_state_action_permissions, dependent: :destroy, class_name: 'Sipity::WorkflowStateActionPermission'
11
+ has_many :entity_specific_responsibilities, dependent: :destroy, class_name: 'Sipity::EntitySpecificResponsibility'
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ module Sipity
2
+ # Throughout the workflow process, a processed entity may have numerous
3
+ # states.
4
+ class WorkflowState < ActiveRecord::Base
5
+ self.table_name = 'sipity_workflow_states'
6
+
7
+ belongs_to :workflow, class_name: 'Sipity::Workflow'
8
+ has_many :originating_workflow_state_actions,
9
+ dependent: :destroy,
10
+ class_name: 'Sipity::WorkflowStateAction',
11
+ foreign_key: :originating_workflow_state_id
12
+
13
+ has_many :resulting_workflow_actions,
14
+ dependent: :destroy,
15
+ class_name: 'Sipity::WorkflowAction',
16
+ foreign_key: :resulting_workflow_state_id
17
+
18
+ # TODO: What should be done with entities in the given state if the WorkflowState is destroyed?
19
+ has_many :entities, class_name: 'Sipity::Workflow'
20
+
21
+ has_many :notifiable_contexts,
22
+ dependent: :destroy,
23
+ as: :scope_for_notification,
24
+ class_name: 'Sipity::NotifiableContext'
25
+ end
26
+ end