diff --git a/.env.template b/.env.template index b979f9e77e30bc7f62082ccab3c6c965ce64435e..dee61c4a81bb4cc1b621a9adbeb3e8c8b08c5c46 100644 --- a/.env.template +++ b/.env.template @@ -117,6 +117,8 @@ S3_BUCKET_PREFIX= CRC_1280_COLLECTION=CRC 1280 # File uploads +RUBY_THREAD_MACHINE_STACK_SIZE=8388608 +RUBY_THREAD_VM_STACK_SIZE=8388608 MAX_FILES=1000 MAX_FILE_SIZE=2.gigabytes @@ -167,3 +169,9 @@ ARK_NAAN= DOWNLOAD_SIZE_LIMIT=100000000 DOWNLOAD_PATH=tmp/downloads +# Admin set titles for the workflows +RUB_ADMIN_SET_TITLE="RUB publication workflow" +CRC_ADMIN_SET_TITLE="CRC 1280 publication Workflow" + +# System user with role publication manager +SYSTEM_PUBLICATION_MANAGER=publication_manager@hyrax diff --git a/.env.template.development b/.env.template.development index 3994688a8e8f7bdf3a11b5fa6f375630162a61f6..840bd3713661d92ccdc68b7f54ebcb2888068999 100644 --- a/.env.template.development +++ b/.env.template.development @@ -150,6 +150,13 @@ ORCID_SANDBOX=true # If Authorization is restricted, only existing users with an Orcid are allowed access ORCID_RESTRICT_AUTHORIZATION=true +# DOI +REGISTER_DOI=false +DOI_URL= +DOI_USERNAME= +DOI_PASSWORD= +DOI_PREFIX= + # ARK REGISTER_ARK=false ARK_ENDPOINT= @@ -159,14 +166,13 @@ ARK_NAMESPACE= # ARK name assigning authority number ARK_NAAN= -# DOI -REGISTER_DOI=false -DOI_URL= -DOI_USERNAME= -DOI_PASSWORD= -DOI_PREFIX= - # Download DOWNLOAD_SIZE_LIMIT=100000000 DOWNLOAD_PATH=tmp/downloads +# Admin set titles for the workflows +RUB_ADMIN_SET_TITLE="RUB publication workflow" +CRC_ADMIN_SET_TITLE="CRC 1280 publication Workflow" + +# System user with role publication manager +SYSTEM_PUBLICATION_MANAGER=publication_manager@hyrax diff --git a/docker-compose.yml b/docker-compose.yml index fcb918ec21fde42e20d0ccf01e7fef01b8b6e6d8..d797b2f58032d64427fee56f3f197ee9fc9076d5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -55,6 +55,11 @@ services: - .env expose: - 5432 + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -h localhost"] + interval: 30s + timeout: 5s + retries: 3 fcrepodb: <<: *db environment: diff --git a/hyrax/Dockerfile b/hyrax/Dockerfile index f2ffdd0fc02809e98557e2251e3033f97a0907af..c1c6f43535b8d7a57c517748055b9bcf41311454 100644 --- a/hyrax/Dockerfile +++ b/hyrax/Dockerfile @@ -1,4 +1,4 @@ -FROM ruby:2.7.7-alpine +FROM ruby:2.7.8-alpine # Setup build variables ARG RAILS_ENV diff --git a/hyrax/Gemfile b/hyrax/Gemfile index f5e05309bf4c894a79aff31a4809d922b267fd8e..485c88d81583a013f5dbcbf4722ac876bf92bdc6 100644 --- a/hyrax/Gemfile +++ b/hyrax/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '2.7.7' +ruby '2.7.8' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.2.6' diff --git a/hyrax/Gemfile.lock b/hyrax/Gemfile.lock index f3dd0909e13511ba04e87a2d24f234cae06953a2..f8d8e744835a7f1a4017a294fb8377740e5e425c 100644 --- a/hyrax/Gemfile.lock +++ b/hyrax/Gemfile.lock @@ -1064,7 +1064,7 @@ DEPENDENCIES web-console (>= 3.3.0) RUBY VERSION - ruby 2.7.7p221 + ruby 2.7.8p225 BUNDLED WITH 2.1.4 diff --git a/hyrax/app/actors/hyrax/actors/file_actor.rb b/hyrax/app/actors/hyrax/actors/file_actor.rb index 2121b223fb8e4fb0b08977096aaef2df2d0937af..ff724fb18dbf11598176012384336751a58e7cf7 100644 --- a/hyrax/app/actors/hyrax/actors/file_actor.rb +++ b/hyrax/app/actors/hyrax/actors/file_actor.rb @@ -84,7 +84,7 @@ module Hyrax file_set.characterization_proxy.original_checksum = uploaded_file.characterization_data['original_checksum'] file_set.characterization_proxy.format_label = [] - if file_set.image? + if file_set.mime_type_image? file_set.characterization_proxy.height = uploaded_file.characterization_data['height'] file_set.characterization_proxy.width = uploaded_file.characterization_data['width'] @@ -151,43 +151,10 @@ module Hyrax target_bucket = Aws::S3::Bucket.new(target_bucket_name) s3.create_bucket(target_bucket_name) unless s3.bucket_exists?(target_bucket_name) - target_object_key = generate_target_object_key(file_set) - s3.move_object(source_object_key, target_bucket_name, target_object_key, { uploaded_file_path: source_object_key }) - target_object = target_bucket.object(target_object_key) + s3.move_object(source_object_key, target_bucket_name, file_set.object_key_on_s3, { uploaded_file_path: source_object_key }) - download_bucket = Aws::S3::Resource.new(region: ENV['S3_REGION']).bucket(target_bucket_name) - - url_options = { - response_content_disposition: "attachment; filename=\"#{target_object_key}\"" - } - object = download_bucket.object(target_object_key) - - return object.exists? ? object.presigned_url(:get, url_options).to_s : nil - end - - def change_repository_file_content(uploaded_file, repository_file, target_object) - uploaded_file.file.file.file = target_object - - repository_file.content = uploaded_file.file_url - end - - def generate_target_object_key(file_set) - prefix = case file_set.for_complex_type - when 'ComplexSubject' - complex_subject = ComplexSubject.find_by(source_identifier: file_set.for_complex_identifier) - "#{complex_subject.subject_title}/files" - when 'ComplexSession' - complex_session = ComplexSession.find_by(source_identifier: file_set.for_complex_identifier) - "#{complex_session.complex_subject.subject_title}/#{complex_session.session_title}/files" - when 'ComplexModality' - complex_modality = ComplexModality.find_by(source_identifier: file_set.for_complex_identifier) - "#{complex_modality.complex_subject.subject_title}/#{complex_modality.complex_session.session_title}/#{complex_modality.modality_title}/files" - else - 'files' - end - - "/#{prefix}/#{file_set.title.first}" + s3.presigned_url_for_downlad(target_bucket_name, file_set.object_key_on_s3) end def clear_metadata(file_set) diff --git a/hyrax/app/assets/javascripts/dataset_form.js b/hyrax/app/assets/javascripts/dataset_form.js new file mode 100644 index 0000000000000000000000000000000000000000..eac7ed7b9f846cf1beadd5d2bc024e8f751943fe --- /dev/null +++ b/hyrax/app/assets/javascripts/dataset_form.js @@ -0,0 +1,14 @@ +$(document).on('change', '.complex_relation_section input:visible, .complex_relation_section select:visible', function() { + var is_required = false; + + var $field_wrapper = $(this).closest('.complex_relation_section'); + var $child_elements = $field_wrapper.find('input:visible, select:visible'); + + $child_elements.each(function(index, child){ + if ($(child).val().length > 0){ + is_required = true + } + }); + + is_required ? $child_elements.prop('required', true) : $child_elements.prop('required', false) +}); \ No newline at end of file diff --git a/hyrax/app/controllers/callbacks_controller.rb b/hyrax/app/controllers/callbacks_controller.rb index e55fc6147d56bc32b74a0d6a36fff328f795cd59..c8ed6e59dd0f842d15f790cf529ea83c9c194bd2 100644 --- a/hyrax/app/controllers/callbacks_controller.rb +++ b/hyrax/app/controllers/callbacks_controller.rb @@ -20,6 +20,10 @@ class CallbacksController < Devise::OmniauthCallbacksController def authenticate_and_authorize(provider) if current_user + if current_user.orcid.nil? && provider.to_s == 'orcid' + current_user.update(orcid: request.env["omniauth.auth"].uid) + flash[:notice] = "You are now connected with ORCID" + end redirect_to Hyrax::Engine.routes.url_helpers.dashboard_path else case provider.to_s diff --git a/hyrax/app/helpers/hyrax_helper.rb b/hyrax/app/helpers/hyrax_helper.rb index ecc7c15819fb5ea76fcb8e94208fbb9109d0a616..72e238c0fef42888477595249d705820b767763c 100644 --- a/hyrax/app/helpers/hyrax_helper.rb +++ b/hyrax/app/helpers/hyrax_helper.rb @@ -23,24 +23,8 @@ module HyraxHelper file_set = FileSet.find(file_set_id) bucket_name = s3.sanitise_name(file_set.parent_works.first.id) - bucket = Aws::S3::Resource.new(region: ENV['S3_REGION']).bucket(bucket_name) - - begin - file_key = generate_target_object_key(file_set) - rescue StandardError - begin - file_key = generate_target_object_key(file_set) - rescue StandardError - return nil - end - end - url_options = { - expires_in: 60.minutes.seconds.to_i, - response_content_disposition: "attachment; filename=\"#{file_key}\"" - } - - object = bucket.object(file_key) - object.exists? ? object.presigned_url(:get, url_options).to_s : nil + + s3.presigned_url_for_downlad(bucket_name, file_set.object_key_on_s3) end def can_create_work_in_group?(group_id) @@ -77,28 +61,16 @@ module HyraxHelper total_size > 0 && total_size < ENV.fetch('DOWNLOAD_SIZE_LIMIT', '100000000').to_i end - def generate_target_object_key(file_set) - prefix = case file_set.for_complex_type - when 'ComplexSubject' - complex_subject = ComplexSubject.find_by(source_identifier: file_set.for_complex_identifier) - "#{complex_subject.subject_title}/files" - when 'ComplexSession' - complex_session = ComplexSession.find_by(source_identifier: file_set.for_complex_identifier) - "#{complex_session.complex_subject.subject_title}/#{complex_session.session_title}/files" - when 'ComplexModality' - complex_modality = ComplexModality.find_by(source_identifier: file_set.for_complex_identifier) - "#{complex_modality.complex_subject.subject_title}/#{complex_modality.complex_session.session_title}/#{complex_modality.modality_title}/files" - else - 'files' - end - - "/#{prefix}/#{file_set.title.first}" - end - - %w(published archived deposited).each do |work_state| - define_method :"is_#{work_state}?" do |presenter| - presenter.workflow.state == work_state - end + def is_tombstonable?(presenter) + presenter.tombstone_status != ['initiated'] && (is_published?(presenter) || is_archived?(presenter)) + end + + def is_published?(presenter) + ['deposited', 'published'].include?(presenter.workflow.state) + end + + def is_archived?(presenter) + presenter.workflow.state == 'archived' end def tombstone_out_of_date?(presenter) diff --git a/hyrax/app/inputs/nested_relation_input.rb b/hyrax/app/inputs/nested_relation_input.rb index 352ff8a953a2b14df3b7a9695153f447ac6c8f2d..8b84fa11629e0e664ca49b2836cc636c2c7033c3 100644 --- a/hyrax/app/inputs/nested_relation_input.rb +++ b/hyrax/app/inputs/nested_relation_input.rb @@ -16,7 +16,7 @@ protected field_name = name_for(attribute_name, index, field, parent) field_id = id_for(attribute_name, index, field, parent) field_value = value.send(field).first - + out << "<div class='complex_relation_section'>" out << "<div class='row'>" out << " <div class='col-md-3'>" out << template.label_tag(field_name, 'Title', required: required) @@ -89,7 +89,8 @@ protected out << destroy_widget(attribute_name, index, field_label, parent) out << ' </div>' - out << '</div>' # last row + out << '</div>' + out << '</div>' out end end diff --git a/hyrax/app/models/concerns/external_services.rb b/hyrax/app/models/concerns/external_services.rb index d5a1168e35c90657d53537e3b83a9489413a73d9..70b290d5b410c9127d6e888a0de1a5fdb480c9a6 100644 --- a/hyrax/app/models/concerns/external_services.rb +++ b/hyrax/app/models/concerns/external_services.rb @@ -41,7 +41,7 @@ module ExternalServices s3.init_client bucket_name = s3.sanitise_name(id) s3.create_bucket(bucket_name) unless s3.bucket_exists?(bucket_name) - s3.add_content(bucket_name, 'metadata.json', to_json) + s3.add_content(bucket_name, 'metadata.json', self.class.find(self.id).to_json) end end diff --git a/hyrax/app/models/crc_dataset.rb b/hyrax/app/models/crc_dataset.rb old mode 100644 new mode 100755 index 63748473a72e493225e0d3f93faafea6a73f4f31..f71fdabc6e375e2f5558e94ad2ec752595f66ee1 --- a/hyrax/app/models/crc_dataset.rb +++ b/hyrax/app/models/crc_dataset.rb @@ -148,6 +148,10 @@ class CrcDataset < ActiveFedora::Base FileSetFastLoadMetadata.where(work_source_identifier: source.first) end + def default_admin_set + AdminSet.where(title: ENV.fetch('CRC_ADMIN_SET_TITLE', 'CRC 1280 Publishing Workflow')).first + end + private def set_default_source_and_tombstone_status diff --git a/hyrax/app/models/dataset.rb b/hyrax/app/models/dataset.rb old mode 100644 new mode 100755 index af76216ec52e8506e48de274312b03e8e0fb0e37..a666e748b129f6fb12cad7167fe3585259a56963 --- a/hyrax/app/models/dataset.rb +++ b/hyrax/app/models/dataset.rb @@ -116,6 +116,10 @@ class Dataset < ActiveFedora::Base accepts_nested_attributes_for :complex_relation, reject_if: :relation_blank, allow_destroy: true accepts_nested_attributes_for :updated_subresources, allow_destroy: true + def default_admin_set + AdminSet.where(title: ENV.fetch('RUB_ADMIN_SET_TITLE', 'RUB publication workflow')).first + end + private def set_default_tombstone_status diff --git a/hyrax/app/models/doi.rb b/hyrax/app/models/doi.rb index 7d78764eff08151572872b029e9b970c631251b6..91099d4f3cedc91a71fd8f8febceda8a168fefdb 100644 --- a/hyrax/app/models/doi.rb +++ b/hyrax/app/models/doi.rb @@ -30,7 +30,7 @@ class DOI end def label - "doi:#{@identifier}" + @identifier end def self.match_doi_prefix(value) diff --git a/hyrax/app/models/file_set.rb b/hyrax/app/models/file_set.rb index 7cf0932652b9d009d27c25e0d402e17b1d1c1ed4..075e8fd4796868366515b8ca59ef94dcb770a8c5 100644 --- a/hyrax/app/models/file_set.rb +++ b/hyrax/app/models/file_set.rb @@ -20,6 +20,30 @@ class FileSet < ActiveFedora::Base FileSetFastLoadMetadata.find_by(fedora_file_set_id: id) end + def mime_type_image? + file_extention = ".#{self.title.first&.split('.')&.last}" + mime_type = Rack::Mime.mime_type(file_extention) + mime_type.include?('image') + end + + def object_key_on_s3 + prefix = case for_complex_type + when 'ComplexSubject' + complex_subject = ComplexSubject.find_by(source_identifier: for_complex_identifier) + "#{complex_subject.subject_title}/files" + when 'ComplexSession' + complex_session = ComplexSession.find_by(source_identifier: for_complex_identifier) + "#{complex_session.complex_subject.subject_title}/#{complex_session.session_title}/files" + when 'ComplexModality' + complex_modality = ComplexModality.find_by(source_identifier: for_complex_identifier) + "#{complex_modality.complex_subject.subject_title}/#{complex_modality.complex_session.session_title}/#{complex_modality.modality_title}/files" + else + 'files' + end + + "/#{prefix}/#{title.first}" + end + private def create_file_set_with_fast_load_meta_data diff --git a/hyrax/app/models/user.rb b/hyrax/app/models/user.rb index e1f60dbb109da947e458ada4f66f548297e0ba6e..d2313845736ccf7b601538f7d25652674384ce54 100644 --- a/hyrax/app/models/user.rb +++ b/hyrax/app/models/user.rb @@ -61,6 +61,14 @@ class User < ApplicationRecord roles.where(name: "publication_manager").any? end + def can_tombstone?(presenter) + self.admin? + end + + def is_depositor_for?(presenter) + presenter.depositor == self.user_key + end + def self.from_omniauth_orcid(auth) if ENV.fetch('ORCID_RESTRICT_AUTHORIZATION', 'true') == 'true' full_orcid = auth.uid @@ -116,12 +124,83 @@ class User < ApplicationRecord # user.skip_confirmation! end - def can_tombstone?(presenter) - self.admin? + def self.assign_user_to_role(user, user_hash) + user_hash = ActiveSupport::HashWithIndifferentAccess.new(user_hash) + role_name = user_hash.fetch('role', nil) + group_id = user_hash.fetch('group_id', nil) + return true, '' if role_name.blank? + + role = if %w(admin publication_manager crc_1280_manager crc_1280_member).include?(role_name) + Role.find_or_create_by(name: role_name) + elsif role_name == "crc_1280_group_manager" and group_id.present? + Role.find_or_create_by(name: "crc_1280_#{group_id}_manager") + elsif role_name == "crc_1280_group_member" and group_id.present? + Role.find_or_create_by(name: "crc_1280_#{group_id}_member") + end + + unless role.present? + if %w(crc_1280_group_manager crc_1280_group_member).include?(role_name) and group_id.blank? + return false, "Error: #{role_name} needs a group id" + else + return false, "Error: #{role_name} is not a valid role" + end + end + + role.users << user if role.users.where(id: user.id).blank? + role.save + return true, "Assigned user #{user.email} role #{role.name}" end - def is_depositor_for?(presenter) - presenter.depositor == self.user_key + def self.find_by_hash(user_hash) + user_hash = ActiveSupport::HashWithIndifferentAccess.new(user_hash) + user = nil + if user_hash.fetch('email', nil).present? + user = User.find_by(email: user_hash['email']) + elsif user_hash.fetch('saml_id', nil).present? + user = User.find_by(provider: "saml", uid: user_hash['saml_id']) + elsif user_hash.fetch('orcid', nil).present? + orcid = user_hash['orcid'] + orcid = "https://orcid.org/#{user_hash['orcid']}" unless orcid.start_with?("https://orcid.org/") + user = User.find_by(orcid: orcid) + end + user + end + + def self.find_or_create_user_email(user_hash) + user_hash = ActiveSupport::HashWithIndifferentAccess.new(user_hash) + email = nil + if user_hash.fetch('email', nil).present? + email = user_hash['email'] + elsif user_hash.fetch('saml_id', nil).present? + email = user_hash['saml_id'] + email = "#{user_hash['saml_id']}@saml" unless user_hash['saml_id'].include?('@') + elsif user_hash.fetch('orcid', nil).present? + email = "#{user_hash['orcid']}@orcid" + end + email + end + + def self.find_or_create_publication_manager + user_hash = { + "email": ENV.fetch('SYSTEM_PUBLICATION_MANAGER', 'publication_manager@hyrax'), + "name": "Publication Manager", + "role": "publication_manager" + } + user = User.find_by_hash(user_hash) + if user.blank? + user = User.new + user.email = user_hash['email'] + user.password = SecureRandom.random_bytes(32) + user.display_name = user_hash["name"] + if user.save + _success, message = self.assign_user_to_role(user, user_hash) + return true, "Created user #{user_hash['email']}. #{message}", user + else + return false, "Error: #{user.errors.full_messages}", nil + end + else + return true, "Found user #{user_hash['email']}", user + end end end diff --git a/hyrax/app/services/hyrax/workflow/draft_notification.rb b/hyrax/app/services/hyrax/workflow/draft_notification.rb new file mode 100644 index 0000000000000000000000000000000000000000..756ed30e7a417316876b718dfad7cc003f4fb6df --- /dev/null +++ b/hyrax/app/services/hyrax/workflow/draft_notification.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Hyrax + module Workflow + class DraftNotification < AbstractNotification + private + + def subject + I18n.t('hyrax.notifications.workflow.draft.subject') + end + + def message + I18n.t('hyrax.notifications.workflow.draft.message', title: title, + link: (link_to work_id, document_path), + user: user.user_key, comment: comment) + end + + def users_to_notify + [::User.find_by(email: document.depositor)] + end + end + end +end diff --git a/hyrax/app/services/hyrax/workflow/make_visibility_public.rb b/hyrax/app/services/hyrax/workflow/make_visibility_public.rb new file mode 100644 index 0000000000000000000000000000000000000000..898793e8c5636f68a75e0b99409a7598c79e7401 --- /dev/null +++ b/hyrax/app/services/hyrax/workflow/make_visibility_public.rb @@ -0,0 +1,13 @@ +module Hyrax + module Workflow + ## + # This is a built in function for workflow, so that a workflow action can be created that + # Transfer Ownership for dataset + module MakeVisibilityPublic + def self.call(target:, **) + target.update(visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC) + VisibilityCopyJob.perform_later(target) + end + end + end +end diff --git a/hyrax/app/services/hyrax/workflow/transfer_ownership.rb b/hyrax/app/services/hyrax/workflow/transfer_ownership.rb new file mode 100644 index 0000000000000000000000000000000000000000..3da6b297baba85ad6473ca66c1ace15e631f6ced --- /dev/null +++ b/hyrax/app/services/hyrax/workflow/transfer_ownership.rb @@ -0,0 +1,13 @@ +module Hyrax + module Workflow + ## + # This is a built in function for workflow, so that a workflow action can be created that + # Transfer Ownership for dataset + module TransferOwnership + def self.call(target:, **) + status, _message, user = ::User.find_or_create_publication_manager + Hyrax::ChangeDepositorService.call(target, user, false) if status and user.present? + end + end + end +end diff --git a/hyrax/app/services/s3_storage_service.rb b/hyrax/app/services/s3_storage_service.rb index a1b300f2f0426ac15b74cff0d7e224ad5e6fff49..1527620bc473948b83fc5ec58ec6b4030965511f 100644 --- a/hyrax/app/services/s3_storage_service.rb +++ b/hyrax/app/services/s3_storage_service.rb @@ -178,7 +178,11 @@ class S3StorageService path = File.join(base_dir, object[:key]) dirname = File.dirname(path) FileUtils.mkdir_p(dirname) unless File.directory?(dirname) - get_content(s3_bucket, object[:key], path) + if object[:key] == "metadata.json" + filter_matadata_json_file(s3_bucket, object[:key], path) + else + get_content(s3_bucket, object[:key], path) + end end base_dir end @@ -198,4 +202,29 @@ class S3StorageService delete_bucket(b) end end + + def presigned_url_for_downlad(bucket_name, file_key) + bucket = Aws::S3::Resource.new(region: ENV['S3_REGION']).bucket(bucket_name) + url_options = { + response_content_disposition: "attachment; filename=\"#{file_key}\"" + } + + object = bucket.object(file_key) + object.exists? ? object.presigned_url(:get, url_options).to_s : nil + end + + private + + def filter_matadata_json_file(s3_bucket, key, path) + metadata_object = @s3_client.get_object(bucket: s3_bucket, key: key) + parsed_data = JSON.load(metadata_object.body) + filtered_data = parsed_data.slice('id', 'depositor', 'title', 'alternative_title', 'description', 'abstract', 'keyword', 'license', 'publisher', 'subject', 'language') + filtered_data['Creators and Contributors'] = parsed_data['complex_person'].map { |person| person.slice('first_name', 'last_name', 'name', 'email', 'role', 'orcid', 'affiliation')} if parsed_data['complex_person'].present? + filtered_data['Related items'] = parsed_data['complex_relation'].map { |relation| relation.slice('title', 'url', 'relationship')} if parsed_data['complex_relation'].present? + filtered_data['Date'] = parsed_data['complex_date'].map { |date| date.slice('date', 'description')} if parsed_data['complex_date'].present? + filtered_data['Funding reference'] = parsed_data['complex_funding_reference'].map { |funding| funding.slice('funder_identifier', 'funder_name', 'award_number', 'award_uri', 'award_title')} if parsed_data['complex_funding_reference'].present? + File.open(path, 'w') do |f| + f.write(filtered_data.to_json) + end + end end diff --git a/hyrax/app/views/hyrax/base/_download_all.html.erb b/hyrax/app/views/hyrax/base/_download_all.html.erb index 4c6e89c68c787ca931b2f398185023ae5251e117..fd68f5ec2d946884d6de4994651b14b1cbf42ec4 100644 --- a/hyrax/app/views/hyrax/base/_download_all.html.erb +++ b/hyrax/app/views/hyrax/base/_download_all.html.erb @@ -4,7 +4,7 @@ <%= link_to t(:'hyrax.download_all'), main_app.download_all_path(presenter.id, format: :zip), id: "download-all", - class: "btn btn-default", + class: "btn btn-default matomo_download", target: "_new" %> </div> diff --git a/hyrax/app/views/hyrax/base/_form_relationships.html.erb b/hyrax/app/views/hyrax/base/_form_relationships.html.erb old mode 100644 new mode 100755 index 3991208549700399664ff95e07943153f15f0714..a99322667a276c2bcca9e607257b5f1ce4090243 --- a/hyrax/app/views/hyrax/base/_form_relationships.html.erb +++ b/hyrax/app/views/hyrax/base/_form_relationships.html.erb @@ -2,7 +2,8 @@ <%= f.input :admin_set_id, as: :select, include_blank: false, collection: admin_set_options, - input_html: { class: 'form-control' } %> + selected: f.object.model.default_admin_set.id, + input_html: { class: 'form-control hidden' } %> <% end %> <%= render 'form_in_works', f: f %> diff --git a/hyrax/app/views/hyrax/base/_show_actions.html.erb b/hyrax/app/views/hyrax/base/_show_actions.html.erb index 2a99963cba9db51bdaf7986de2aaab7830ba28ee..adeead6366ebb11807bd202495fe10f5ff2db1d1 100644 --- a/hyrax/app/views/hyrax/base/_show_actions.html.erb +++ b/hyrax/app/views/hyrax/base/_show_actions.html.erb @@ -26,8 +26,8 @@ <% unless is_permanently_tombstoned?(presenter) %> <div class="col-sm-6 text-right"> - <% if presenter.editor? && !workflow_restriction?(presenter) && !current_user.publication_manager? %> - <% unless is_published?(presenter) || is_archived?(presenter) %> + <% if presenter.editor? && !workflow_restriction?(presenter) %> + <%# unless is_published?(presenter) || is_archived?(presenter) %> <%= link_to t('.edit'), edit_polymorphic_path([main_app, presenter]), class: 'btn btn-secondary' %> <% if presenter.member_count > 1 %> @@ -49,7 +49,7 @@ <% end %> <%= link_to t('.delete'), [main_app, presenter], class: 'btn btn-danger', data: { confirm: t('.confirm_delete', work_type: presenter.human_readable_type) }, method: :delete %> - <% end %> + <%# end %> <% end %> </div> <% end %> diff --git a/hyrax/app/views/hyrax/base/_workflow_actions.html.erb b/hyrax/app/views/hyrax/base/_workflow_actions.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..444c7e7a280c110573e7109269b4a2aa15f6d825 --- /dev/null +++ b/hyrax/app/views/hyrax/base/_workflow_actions.html.erb @@ -0,0 +1,40 @@ +<div id="workflow_controls" class="panel panel-workflow"> + <div class="panel-heading"> + <a data-toggle="collapse" href="#workflow_controls_collapse"> + <h2 class="panel-title"><%= t('.title') %> <span class="fa fa-chevron-right pull-right"></span></h2> + </a> + </div> + <%= form_tag main_app.hyrax_workflow_action_path(presenter), method: :put do %> + <div id="workflow_controls_collapse" class="panel-body panel-collapse collapse"> + <div class="col-sm-3 workflow-actions"> + <h3><%= t('.actions') %></h3> + + <% presenter.workflow.actions.each do |key, label| %> + <div class="radio"> + <label> + <%= radio_button_tag 'workflow_action[name]', key, key == 'comment_only' %> + <%= label %> + </label> + </div> + <% end %> + </div> + <div class="col-sm-9 workflow-comments"> + <div class="form-group"> + <label for="workflow_action_comment"><%= t('.review_comment') %>:</label> + <div><%= t('.review_comment_text') %></div> + <textarea class="form-control" name="workflow_action[comment]" id="workflow_action_comment"></textarea> + </div> + + <input class="btn btn-primary" type="submit" value="Submit" /> + + <h4><%= t('.previous_comments') %></h4> + <dl> + <% presenter.workflow.comments.each do |comment| %> + <dt><%= comment.name_of_commentor %></dt> + <dd><%= comment.comment %></dd> + <% end %> + </dl> + </div> + </div> + <% end %> +</div> \ No newline at end of file diff --git a/hyrax/app/views/hyrax/dashboard/profiles/_edit_primary.html.erb b/hyrax/app/views/hyrax/dashboard/profiles/_edit_primary.html.erb index fe910b446ce8892bd20ae435f194a0cfbda71cd4..bb87e5f148a70a02edbf6b2e967f8fd4fe59d462 100644 --- a/hyrax/app/views/hyrax/dashboard/profiles/_edit_primary.html.erb +++ b/hyrax/app/views/hyrax/dashboard/profiles/_edit_primary.html.erb @@ -2,8 +2,8 @@ url: hyrax.dashboard_profile_path(@user.to_param), html: { multipart: true, class: 'form-horizontal' } do |f| %> <div class="form-group"> - <%= f.label :avatar, t(".change_picture").html_safe, class: "col-xs-4 control-label" %> - <div class="col-xs-8"> + <%= f.label :avatar, t(".change_picture").html_safe, class: "col-xs-2 control-label" %> + <div class="col-xs-10"> <%= image_tag @user.avatar.url(:thumb) if @user.avatar? %> <%= f.file_field :avatar %> <%= f.hidden_field :avatar_cache %> @@ -24,31 +24,38 @@ <% end %> <div class="form-group"> - <%= f.label :orcid, class: 'col-xs-4 control-label' do %> + <%= f.label :orcid, class: 'col-xs-2 control-label' do %> <%= orcid_label %> <% end %> - <div class="col-xs-8"> + <div class="col-xs-6"> <%= f.text_field :orcid, class: "form-control", disabled: "disabled" %> </div> + <div class="col-xs-2"> + <% if @user.orcid.nil? %> + <%= link_to omniauth_authorize_path(User, :orcid), method: :post, class: "btn btn-primary" do %> + <%= t("hyrax.connect_with_orcid") %> + <% end %> + <% end %> + </div> </div><!-- .form-group --> <div class="form-group"> - <%= f.label :twitter_handle, t(".twitter_handle").html_safe, class: 'col-xs-4 control-label' %> - <div class="col-xs-8"> + <%= f.label :twitter_handle, t(".twitter_handle").html_safe, class: 'col-xs-2 control-label' %> + <div class="col-xs-6"> <%= f.text_field :twitter_handle, class: "form-control" %> </div> </div><!-- .form-group --> <div class="form-group"> - <%= f.label :facebook_handle, t(".facebook_handle").html_safe, class: 'col-xs-4 control-label' %> - <div class="col-xs-8"> + <%= f.label :facebook_handle, t(".facebook_handle").html_safe, class: 'col-xs-2 control-label' %> + <div class="col-xs-6"> <%= f.text_field :facebook_handle, class: "form-control" %> </div> </div><!-- .form-group --> <div class="form-group"> - <%= f.label :googleplus_handle, t(".google_handle").html_safe, class: 'col-xs-4 control-label' %> - <div class="col-xs-8"> + <%= f.label :googleplus_handle, t(".google_handle").html_safe, class: 'col-xs-2 control-label' %> + <div class="col-xs-6"> <%= f.text_field :googleplus_handle, class: "form-control" %> </div> </div><!-- .form-group --> diff --git a/hyrax/app/views/hyrax/dashboard/profiles/edit.html.erb b/hyrax/app/views/hyrax/dashboard/profiles/edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..e9ac9da4f2acd8b10e967fc295e30fc4b255d055 --- /dev/null +++ b/hyrax/app/views/hyrax/dashboard/profiles/edit.html.erb @@ -0,0 +1,14 @@ +<% provide :page_header do %> + <h1><span class="fa fa-id-card" aria-hidden="true"></span> Edit Profile</h1> +<% end %> +<div class="card"> + <div class="card-body"> + <div class="col-sm-12 profile"> + <%= render 'edit_primary' %> + </div> + + <div class="col-sm-6 profile"> + <%= render 'edit_secondary' %> + </div> + </div> +</div> \ No newline at end of file diff --git a/hyrax/app/views/hyrax/datasets/show.html.erb b/hyrax/app/views/hyrax/datasets/show.html.erb index 18ed39b7a48fa1f4d79be480b261b04f1c008331..706676e5d52e5c0968814197f3d4d2f2e4ac7382 100644 --- a/hyrax/app/views/hyrax/datasets/show.html.erb +++ b/hyrax/app/views/hyrax/datasets/show.html.erb @@ -19,7 +19,7 @@ </div> <% end %> <div class="col-sm-3 text-center"> - <% if ['deposited', 'published'].include?(@presenter.workflow.state) %> + <% if ['published',].include?(@presenter.workflow.state) %> <%= render 'download_all', presenter: @presenter %> <%= render 'citations', presenter: @presenter %> <%= render 'social_media' %> @@ -56,10 +56,10 @@ <%# = render 'user_activity', presenter: @presenter %> <span class='hide analytics-event' data-category="work" data-action="work-view" data-name="<%= @presenter.id %>" > -<% @presenter.member_of_collection_ids.each do |collection_id| %> - <span class='hide analytics-event' data-category="work-in-collection" data-action="work-in-collection-view" data-name="<%= collection_id %>" > -<% end %> - + <% @presenter.member_of_collection_ids.each do |collection_id| %> + <span class='hide analytics-event' data-category="work-in-collection" data-action="work-in-collection-view" data-name="<%= collection_id %>"/> + <% end %> + </span> </div> </div> diff --git a/hyrax/app/views/hyrax/file_sets/_actions.html.erb b/hyrax/app/views/hyrax/file_sets/_actions.html.erb index ece63f0aa021e93d9cb70788990c1789d54a6de9..361360753685f1d778670dc784a4e2764297b4cc 100644 --- a/hyrax/app/views/hyrax/file_sets/_actions.html.erb +++ b/hyrax/app/views/hyrax/file_sets/_actions.html.erb @@ -2,7 +2,7 @@ <% if can?(:download, file_set.id) && !(can?(:edit, file_set.id) || can?(:destroy, file_set.id)) && s3_file_download_url_for_file_set(file_set.id).present? %> <%= link_to t('.download'), s3_file_download_url_for_file_set(file_set.id), - class: 'btn btn-secondary btn-sm', + class: 'btn btn-secondary btn-sm matomo_download', title: t('.download_title', file_set: file_set), target: "_blank", id: "file_download", @@ -42,7 +42,7 @@ title: t('.download_title', file_set: file_set), target: "_blank", id: "file_download", - class: "download", + class: "download matomo_download", data: { label: file_set.id, work_id: @presenter.id, collection_ids: @presenter.member_of_collection_ids } %> </li> <% end %> diff --git a/hyrax/app/views/hyrax/file_sets/media_display/_audio.html.erb b/hyrax/app/views/hyrax/file_sets/media_display/_audio.html.erb index cbb90ccd590b1bb94af55ab22edb749e16caa24f..a56b24fec60899c18b12c5eb72b5e4692c3635a8 100644 --- a/hyrax/app/views/hyrax/file_sets/media_display/_audio.html.erb +++ b/hyrax/app/views/hyrax/file_sets/media_display/_audio.html.erb @@ -12,6 +12,7 @@ s3_file_download_url_for_file_set(file_set.id), data: { label: file_set.id }, target: :_blank, + class: "matomo_download", id: "file_download" %> </div> <% else %> diff --git a/hyrax/app/views/hyrax/file_sets/media_display/_default.html.erb b/hyrax/app/views/hyrax/file_sets/media_display/_default.html.erb index 73077358b4c4e24eb0a395a60536de996d61af6c..a448337391ff96e9eec3d94466eba956f3c9d404 100644 --- a/hyrax/app/views/hyrax/file_sets/media_display/_default.html.erb +++ b/hyrax/app/views/hyrax/file_sets/media_display/_default.html.erb @@ -5,6 +5,7 @@ s3_file_download_url_for_file_set(file_set.id), id: "file_download", data: { label: file_set.id }, + class: "matomo_download", target: "_new" %> <% end %> </div> \ No newline at end of file diff --git a/hyrax/app/views/hyrax/file_sets/media_display/_image.html.erb b/hyrax/app/views/hyrax/file_sets/media_display/_image.html.erb index c20cd6777f92cc6c1929c436f316e20df6fe0623..a61cb6f32518a3a487ad083512192e1fed685019 100644 --- a/hyrax/app/views/hyrax/file_sets/media_display/_image.html.erb +++ b/hyrax/app/views/hyrax/file_sets/media_display/_image.html.erb @@ -9,6 +9,7 @@ s3_file_download_url_for_file_set(file_set.id), data: { label: file_set.id }, target: :_blank, + class: "matomo_download", id: "file_download" %> </div> <% elsif s3_file_download_url_for_file_set(file_set.id).present? %> diff --git a/hyrax/app/views/hyrax/file_sets/media_display/_office_document.html.erb b/hyrax/app/views/hyrax/file_sets/media_display/_office_document.html.erb index 095afd8618c94bd116d5e5fcd59a21097a1fc285..e755581ec85c46c10bdbb1021c940cebf8bbf4de 100644 --- a/hyrax/app/views/hyrax/file_sets/media_display/_office_document.html.erb +++ b/hyrax/app/views/hyrax/file_sets/media_display/_office_document.html.erb @@ -9,6 +9,7 @@ s3_file_download_url_for_file_set(file_set.id), target: :_blank, id: "file_download", + class: "matomo_download", data: { label: file_set.id } %> </div> <% else %> diff --git a/hyrax/app/views/hyrax/file_sets/media_display/_pdf.html.erb b/hyrax/app/views/hyrax/file_sets/media_display/_pdf.html.erb index 16737e0df4494474d39db27b98054758d2e10048..39b247f63d69dc417d09662b5e8b5ce2cd7d09ac 100644 --- a/hyrax/app/views/hyrax/file_sets/media_display/_pdf.html.erb +++ b/hyrax/app/views/hyrax/file_sets/media_display/_pdf.html.erb @@ -9,6 +9,7 @@ s3_file_download_url_for_file_set(file_set.id), target: :_blank, id: "file_download", + class: "matomo_download", data: { label: file_set.id } %> </div> <% else %> diff --git a/hyrax/app/views/hyrax/file_sets/media_display/_video.html.erb b/hyrax/app/views/hyrax/file_sets/media_display/_video.html.erb index 78550ced398ba5f34983baeae00cef0b60fe0b72..8bf57815290bad9de0003339cdc6b99137e49bc5 100644 --- a/hyrax/app/views/hyrax/file_sets/media_display/_video.html.erb +++ b/hyrax/app/views/hyrax/file_sets/media_display/_video.html.erb @@ -12,6 +12,7 @@ s3_file_url, data: { label: file_set.id }, target: :_blank, + class: "matomo_download", id: "file_download" %> </div> <% else %> diff --git a/hyrax/app/views/records/edit_fields/_complex_relation.html.erb b/hyrax/app/views/records/edit_fields/_complex_relation.html.erb index d6b0648c6c7c6f7277d81b07c14e837986ddf578..1ef15b704ca8adc5d5cbfcc324bcc4d0ff1da0c3 100644 --- a/hyrax/app/views/records/edit_fields/_complex_relation.html.erb +++ b/hyrax/app/views/records/edit_fields/_complex_relation.html.erb @@ -1,4 +1,4 @@ -<div class="multi-nested"> +<div class="multi-nested multi_value"> <%= f.input :complex_relation, as: :nested_relation, include_blank: false, diff --git a/hyrax/config/initializers/hyrax.rb b/hyrax/config/initializers/hyrax.rb index 44cb7c1a2b73657f485e86e23a9d94af1814a96a..7acfa8c6f939e09dcd93136bdb139b7e9d3205a7 100644 --- a/hyrax/config/initializers/hyrax.rb +++ b/hyrax/config/initializers/hyrax.rb @@ -14,7 +14,7 @@ Hyrax.config do |config| # When an admin set is created, we need to activate a workflow. # The :default_active_workflow_name is the name of the workflow we will activate. # @see Hyrax::Configuration for additional details and defaults. - # config.default_active_workflow_name = 'default' + config.default_active_workflow_name = 'rub_publication_workflow' # Which RDF term should be used to relate objects to an admin set? # If this is a new repository, you may want to set a custom predicate term here to @@ -53,7 +53,7 @@ Hyrax.config do |config| # config.temp_file_base = '/home/developer1' # Hostpath to be used in Endnote exports - # config.persistent_hostpath = 'http://localhost/files/' + config.persistent_hostpath = "#{ENV['APPLICATION_URL'] || 'http://localhost'}/files/" # If you have ffmpeg installed and want to transcode audio and video set to true config.enable_ffmpeg = true diff --git a/hyrax/config/initializers/riiif.rb b/hyrax/config/initializers/riiif.rb index 76e7e59bf93779a8317a5920a32ec4c59f0d8b11..74330ba99e1e556dd26fc9795e3cc97daa930a13 100644 --- a/hyrax/config/initializers/riiif.rb +++ b/hyrax/config/initializers/riiif.rb @@ -14,9 +14,8 @@ ActiveSupport::Reloader.to_prepare do end Riiif::Image.file_resolver.id_to_uri = lambda do |id| - Hyrax::Base.id_to_uri(CGI.unescape(id)).tap do |url| - Rails.logger.info "Riiif resolved #{id} to #{url}" - end + fs_id = id.sub(/\A([^\/]*)\/.*/, '\1') + s3_file_url(fs_id) end Riiif::Image.authorization_service = Hyrax::IIIFAuthorizationService @@ -25,4 +24,14 @@ ActiveSupport::Reloader.to_prepare do Riiif.unauthorized_image = Rails.root.join('app', 'assets', 'images', 'us_404.svg') Riiif::Engine.config.cache_duration = 365.days + + def s3_file_url(fs_id) + s3 = S3StorageService.new + s3.init_client + + file_set = FileSet.find(fs_id) + bucket_name = s3.sanitise_name(file_set.parent_works.first.id) + file_key = "/files/#{file_set.title.first}" + s3.presigned_url_for_downlad(bucket_name, file_key) + end end diff --git a/hyrax/config/locales/crc_dataset.en.yml b/hyrax/config/locales/crc_dataset.en.yml index fbcea096cebd3ce7f25f4089db5c5d637b3382d2..47e57156c21fe1b045b8c77a91172ffaa34a866b 100644 --- a/hyrax/config/locales/crc_dataset.en.yml +++ b/hyrax/config/locales/crc_dataset.en.yml @@ -1,5 +1,8 @@ en: hyrax: + base: + workflow_actions: + review_comment_text: "Let the CRC manager know if you would like the dataset to be published or archived." icons: crc_dataset: 'fa fa-file-text-o' select_type: diff --git a/hyrax/config/locales/dataset.en.yml b/hyrax/config/locales/dataset.en.yml index 9f8c528d19f22fdb3f75afadf56bec0ace4c0462..aa9103fadfac8751d4924eab667b2fa016f7caaa 100644 --- a/hyrax/config/locales/dataset.en.yml +++ b/hyrax/config/locales/dataset.en.yml @@ -1,5 +1,8 @@ en: hyrax: + base: + workflow_actions: + review_comment_text: "Let the reviewer know if you would like the dataset to be published or archived." icons: dataset: 'fa fa-file-text-o' select_type: diff --git a/hyrax/config/locales/en.yml b/hyrax/config/locales/en.yml index fd52b8fc03b532b890de0e96b63352da0036e78d..c78edf12794322405199c7bc46f1da183288b52b 100644 --- a/hyrax/config/locales/en.yml +++ b/hyrax/config/locales/en.yml @@ -70,6 +70,7 @@ en: publisher: The person or group making the work (dataset) available. complex_person: 'Authors or contributors to the work (dataset). Enter the Surname, the Given name, and select their Role. A person can have multiple Given names. <br/>For affiliation, enter details of the affiliation, e.g. Chair, Institute, Faculty, University' complex_identifier: External identifiers, if applicable. + complex_relation: If adding a relationship, all of the three fields are required. The URL needs to be the complete canonical URL of the item. placeholders: defaults: language: "De" diff --git a/hyrax/config/locales/hyrax.en.yml b/hyrax/config/locales/hyrax.en.yml index af2d75682ebe5bf2d31ebc02072ec1e9d16b3747..ab2c05cc02630638658b50889e6a7440502b4ebc 100644 --- a/hyrax/config/locales/hyrax.en.yml +++ b/hyrax/config/locales/hyrax.en.yml @@ -208,6 +208,7 @@ en: new: Add New Work (dataset) hyrax: account_name: My Institution Account Id + connect_with_orcid: Connect With ORCID admin: admin_sets: document_list: @@ -346,6 +347,7 @@ en: create_service: admin_set_description: An aggregation of works (datasets) that is intended to help with administrative control. Admin Sets provide a way of defining behaviors and policies around a set of works. default_description: A User Collection can be created by any user to organize their works (datasets). + download_all: Download All dashboard: admin_sets: works: Works (datasets) @@ -447,6 +449,9 @@ en: %{title} (%{link}) requires additional changes before approval. '%{comment}' subject: Deposit requires changes + draft: + message: "You have created the dataset %{title} (%{link}). You can edit and make changes to the dataset. When ready, click on deposit in the `Review and Approval` section. Add a comment to let a reviewer know if you would like the dataset to be archived or published." + subject: "We have your new dataset" sent_for_review: message: "Deposit %{title} (%{link}) has been sent to %{approval_from} for approval. %{comment}" subject: "Deposit sent for review" diff --git a/hyrax/config/workflows/three_step_mediated_deposit_workflow.json b/hyrax/config/workflows/crc_1280_publication_workflow.json similarity index 99% rename from hyrax/config/workflows/three_step_mediated_deposit_workflow.json rename to hyrax/config/workflows/crc_1280_publication_workflow.json index 92938eb59cac3d08f18808706e1e60f510302a5c..439d5cf7b3382cf6a90937d751a21863e2055d16 100644 --- a/hyrax/config/workflows/three_step_mediated_deposit_workflow.json +++ b/hyrax/config/workflows/crc_1280_publication_workflow.json @@ -1,8 +1,8 @@ { "workflows": [ { - "name": "three_step_mediated_deposit", - "label": "Three-step mediated deposit workflow", + "name": "crc_1280_publication_workflow", + "label": "CRC 1280 publication workflow", "description": "A three-step workflow for mediated deposit in which all deposits must be approved by a reviewer. Reviewer may also send deposits back to the depositor.", "allows_access_grant": false, "actions": [ diff --git a/hyrax/config/workflows/default_workflow.json b/hyrax/config/workflows/default_workflow.json deleted file mode 100644 index c0a8d0eab392943276de1a56e9535bb7e957ce95..0000000000000000000000000000000000000000 --- a/hyrax/config/workflows/default_workflow.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "workflows": [ - { - "name": "default", - "label": "Default workflow", - "description": "A single submission step, default workflow", - "allows_access_grant": true, - "actions": [ - { - "name": "deposit", - "from_states": [], - "transition_to": "deposited", - "methods": [ - "Hyrax::Workflow::GrantEditToDepositor", - "Hyrax::Workflow::ActivateObject" - ] - } - ] - } - ] -} diff --git a/hyrax/config/workflows/mediated_deposit_workflow.json b/hyrax/config/workflows/mediated_deposit_workflow.json deleted file mode 100644 index d31256e87ce2dcb635bf2271b285966a9894ccaa..0000000000000000000000000000000000000000 --- a/hyrax/config/workflows/mediated_deposit_workflow.json +++ /dev/null @@ -1,131 +0,0 @@ -{ - "workflows": [ - { - "name": "one_step_mediated_deposit", - "label": "One-step mediated deposit workflow", - "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.", - "allows_access_grant": false, - "actions": [ - { - "name": "deposit", - "from_states": [], - "transition_to": "pending_review", - "notifications": [ - { - "notification_type": "email", - "name": "Hyrax::Workflow::PendingReviewNotification", - "to": [ - "approving" - ] - } - ], - "methods": [ - "Hyrax::Workflow::GrantReadToDepositor", - "Hyrax::Workflow::DeactivateObject" - ] - }, - { - "name": "request_changes", - "from_states": [ - { - "names": [ - "deposited", - "pending_review" - ], - "roles": [ - "approving" - ] - } - ], - "transition_to": "changes_required", - "notifications": [ - { - "notification_type": "email", - "name": "Hyrax::Workflow::ChangesRequiredNotification", - "to": [ - "approving" - ] - } - ], - "methods": [ - "Hyrax::Workflow::DeactivateObject", - "Hyrax::Workflow::GrantEditToDepositor" - ] - }, - { - "name": "approve", - "from_states": [ - { - "names": [ - "pending_review" - ], - "roles": [ - "approving" - ] - } - ], - "transition_to": "deposited", - "notifications": [ - { - "notification_type": "email", - "name": "Hyrax::Workflow::DepositedNotification", - "to": [ - "approving" - ] - } - ], - "methods": [ - "Hyrax::Workflow::GrantReadToDepositor", - "Hyrax::Workflow::RevokeEditFromDepositor", - "Hyrax::Workflow::ActivateObject" - ] - }, - { - "name": "request_review", - "from_states": [ - { - "names": [ - "changes_required" - ], - "roles": [ - "depositing" - ] - } - ], - "transition_to": "pending_review", - "notifications": [ - { - "notification_type": "email", - "name": "Hyrax::Workflow::PendingReviewNotification", - "to": [ - "approving" - ] - } - ] - }, - { - "name": "comment_only", - "from_states": [ - { - "names": [ - "pending_review", - "deposited" - ], - "roles": [ - "approving" - ] - }, - { - "names": [ - "changes_required" - ], - "roles": [ - "depositing" - ] - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/hyrax/config/workflows/one_step_mediated_deposit_workflow.json b/hyrax/config/workflows/rub_publication_workflow.json similarity index 86% rename from hyrax/config/workflows/one_step_mediated_deposit_workflow.json rename to hyrax/config/workflows/rub_publication_workflow.json index b0e5781a700d37e5db130af531c4c081658b34c9..73f480bcebc445dd0088ba1a2963249960d8d5d7 100644 --- a/hyrax/config/workflows/one_step_mediated_deposit_workflow.json +++ b/hyrax/config/workflows/rub_publication_workflow.json @@ -4,13 +4,21 @@ "name": "rub_publication_workflow", "label": "RUB publication workflow", "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.", - "allows_access_grant": false, + "allows_access_grant": true, "actions": [ { "name": "draft", "from_states": [], "transition_to": "draft", - "notifications": [], + "notifications": [ + { + "notification_type": "email", + "name": "Hyrax::Workflow::DraftNotification", + "to": [ + "depositor" + ] + } + ], "methods": [ "Hyrax::Workflow::GrantEditToDepositor", "Hyrax::Workflow::DeactivateObject" @@ -48,8 +56,7 @@ "methods": [ "Hyrax::Workflow::GrantReadToDepositor", "Hyrax::Workflow::RevokeEditFromDepositor", - "Hyrax::Workflow::GrantReadToPublicationManager", - "Hyrax::Workflow::DeactivateObject" + "Hyrax::Workflow::GrantReadToPublicationManager" ] }, { @@ -76,40 +83,46 @@ ], "methods": [ "Hyrax::Workflow::GrantEditToDepositor", - "Hyrax::Workflow::GrantReadToPublicationManager", - "Hyrax::Workflow::DeactivateObject" + "Hyrax::Workflow::GrantReadToPublicationManager" ] }, { - "name": "archive_from_publication_manager", + "name": "request_review_to_publication_manager", "from_states": [ { "names": [ - "pending_review_from_publication_manager" + "changes_required_from_publication_manager" ], "roles": [ - "approving_publication_manager" + "depositing" ] } ], - "transition_to": "archived", + "transition_to": "pending_review_from_publication_manager", "notifications": [ { "notification_type": "email", - "name": "Hyrax::Workflow::ArchiveNotification", + "name": "Hyrax::Workflow::SentForReview::DepositorNotification", "to": [ "depositor" ] + }, + { + "notification_type": "email", + "name": "Hyrax::Workflow::PendingReview::PublicationManagerNotification", + "to": [ + "approving_publication_manager" + ] } ], "methods": [ - "Hyrax::Workflow::GrantEditToDepositor", - "Hyrax::Workflow::GrantReadToPublicationManager", + "Hyrax::Workflow::GrantReadToDepositor", + "Hyrax::Workflow::RevokeEditFromDepositor", "Hyrax::Workflow::DeactivateObject" ] }, { - "name": "approval_from_publication_manager", + "name": "archive_from_publication_manager", "from_states": [ { "names": [ @@ -120,50 +133,43 @@ ] } ], - "transition_to": "published", + "transition_to": "archived", "notifications": [ { "notification_type": "email", - "name": "Hyrax::Workflow::DepositedNotification", + "name": "Hyrax::Workflow::ArchiveNotification", "to": [ - "depositor", - "approving_publication_manager" + "depositor" ] } ], "methods": [ "Hyrax::Workflow::GrantReadToDepositor", "Hyrax::Workflow::RevokeEditFromDepositor", - "Hyrax::Workflow::GrantReadToPublicationManager", + "Hyrax::Workflow::GrantEditToPublicationManager", "Hyrax::Workflow::ActivateObject", - "Hyrax::Workflow::RegisterDoi" + "Hyrax::Workflow::TransferOwnership" ] }, { - "name": "request_review_to_publication_manager", + "name": "approval_from_publication_manager", "from_states": [ { "names": [ - "changes_required_from_publication_manager" + "pending_review_from_publication_manager" ], "roles": [ - "depositing" + "approving_publication_manager" ] } ], - "transition_to": "pending_review_from_publication_manager", + "transition_to": "published", "notifications": [ { "notification_type": "email", - "name": "Hyrax::Workflow::SentForReview::DepositorNotification", - "to": [ - "depositor" - ] - }, - { - "notification_type": "email", - "name": "Hyrax::Workflow::PendingReview::PublicationManagerNotification", + "name": "Hyrax::Workflow::DepositedNotification", "to": [ + "depositor", "approving_publication_manager" ] } @@ -171,7 +177,12 @@ "methods": [ "Hyrax::Workflow::GrantReadToDepositor", "Hyrax::Workflow::RevokeEditFromDepositor", - "Hyrax::Workflow::DeactivateObject" + "Hyrax::Workflow::GrantReadToPublicationManager", + "Hyrax::Workflow::RevokeEditFromPublicationManager", + "Hyrax::Workflow::ActivateObject", + "Hyrax::Workflow::RegisterDoi", + "Hyrax::Workflow::TransferOwnership", + "Hyrax::Workflow::MakeVisibilityPublic" ] }, { @@ -211,7 +222,7 @@ "published" ], "roles": [ - "depositing" + "approving_publication_manager" ] } ], @@ -229,7 +240,7 @@ "tomstoned_initiated" ], "roles": [ - "depositing" + "approving_publication_manager" ] } ], @@ -247,7 +258,7 @@ "tomstoned_initiated" ], "roles": [ - "depositing" + "approving_publication_manager" ] } ], @@ -260,4 +271,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/hyrax/lib/tasks/create_publication_manager.rake b/hyrax/lib/tasks/create_publication_manager.rake new file mode 100644 index 0000000000000000000000000000000000000000..ec72f8b96d6aa3c6d0b6789ebc73328716385bf9 --- /dev/null +++ b/hyrax/lib/tasks/create_publication_manager.rake @@ -0,0 +1,9 @@ +namespace :rdms do + namespace :publication_manager do + desc 'Create system publication manager' + task :create => :environment do + _success, message, _user = User.find_or_create_publication_manager + puts message + end + end +end diff --git a/hyrax/lib/tasks/default_admin_set_for_workflow.rake b/hyrax/lib/tasks/default_admin_set_for_workflow.rake new file mode 100644 index 0000000000000000000000000000000000000000..6ced8e1de54eb0c20af140e9b973515c6d6006a3 --- /dev/null +++ b/hyrax/lib/tasks/default_admin_set_for_workflow.rake @@ -0,0 +1,33 @@ + +# frozen_string_literal: true +namespace :hyrax do + namespace :default_admin_set_for_workflow do + desc "Create the Default Admin Set" + task create: :environment do + admin_role = Role.find_by(name: "admin") + admin_user = admin_role&.users&.first + + if admin_user.present? + rub_default_admin_set_title = ENV.fetch('RUB_ADMIN_SET_TITLE', 'RUB publication workflow') + crc_default_admin_set_title = ENV.fetch('CRC_ADMIN_SET_TITLE', 'CRC 1280 Publishing Workflow') + + [rub_default_admin_set_title, crc_default_admin_set_title].each do |title| + unless AdminSet.where(title: [title]).present? + admin_set = AdminSet.new(title: [title]) + admin_set.save + + Hyrax::AdminSetCreateService.call(admin_set: admin_set, creating_user: admin_user) + + workflow_name = title == rub_default_admin_set_title ? 'rub_publication_workflow' : 'crc_1280_publication_workflow' + + mediated_workflow = admin_set.permission_template.available_workflows.where(name: workflow_name).first + + Sipity::Workflow.activate!(permission_template: admin_set.permission_template, workflow_id: mediated_workflow.id) + end + end + else + puts "Admin Sets not created, No Admin user exist" + end + end + end +end diff --git a/hyrax/lib/tasks/setup_hyrax.rake b/hyrax/lib/tasks/setup_hyrax.rake index e8fe880f563ab85a3cc335065ca63192a4e4e155..203fb492434a6e98f2a35c356bbe2b3a5a870133 100644 --- a/hyrax/lib/tasks/setup_hyrax.rake +++ b/hyrax/lib/tasks/setup_hyrax.rake @@ -13,7 +13,7 @@ namespace :rdms do if (File.exists?(seedfile)) Rake::Task["rdms:setup_users"].invoke(seedfile, false) end - + Rake::Task['rdms:publication_manager:create'].invoke ###### # finished creating users ############################################## @@ -22,6 +22,7 @@ namespace :rdms do # Create default administrative set and load workflow ###### Rake::Task['hyrax:default_admin_set:create'].invoke + Rake::Task['hyrax:default_admin_set_for_workflow:create'].invoke Rake::Task['hyrax:workflow:load'].invoke Rake::Task['hyrax:default_collection_types:create'].invoke Rake::Task['rdms:crc_1280_collection:create'].invoke diff --git a/hyrax/lib/tasks/setup_users.rake b/hyrax/lib/tasks/setup_users.rake index ed6e1f663799f7b4ea6086031e35e9c95bd78b29..04eb808d14717035aa2ad7706df76752cad969e7 100644 --- a/hyrax/lib/tasks/setup_users.rake +++ b/hyrax/lib/tasks/setup_users.rake @@ -23,28 +23,11 @@ namespace :rdms do seed.fetch('users', []).each_with_index do |parsed_user, index| messages = [] user_count = index + 1 - email = nil - user = nil - if parsed_user.fetch('email', nil).present? - user = User.find_by(email: parsed_user['email']) - email = parsed_user['email'] - elsif parsed_user.fetch('saml_id', nil).present? - user = User.find_by(provider: "saml", uid: parsed_user['saml_id']) - if user.present? - email = user.email - else - email = parsed_user['saml_id'] - email = "#{parsed_user['saml_id']}@saml" unless parsed_user['saml_id'].include?('@') - end - elsif parsed_user.fetch('orcid', nil).present? - orcid = parsed_user['orcid'] - orcid = "https://orcid.org/#{parsed_user['orcid']}" unless orcid.start_with?("https://orcid.org/") - user = User.find_by(orcid: orcid) - if user.present? - email = user.email - else - email = "#{parsed_user['orcid']}@orcid" - end + user = User.find_by_hash(parsed_user) + if user + email = user.email + else + email = User.find_or_create_user_email(parsed_user) end if user @@ -56,9 +39,6 @@ namespace :rdms do end elsif email.blank? messages << "Error: Not creating user #{user_count}. User has no email, saml_id or orcid." - elsif parsed_user.fetch('saml_id', nil).blank? and - parsed_user.fetch('orcid', nil).blank? and parsed_user.fetch('password', nil).blank? - messages << "Error: Not creating user #{email}. User has no password, saml_id or orcid." else messages << "Info: Creating user #{email}" user = User.new @@ -69,7 +49,7 @@ namespace :rdms do if parsed_user.fetch('password', nil).present? user.password = parsed_user['password'] - else + elsif user.password.blank? user.password = SecureRandom.random_bytes(32) end @@ -83,7 +63,7 @@ namespace :rdms do user.orcid = parsed_user['orcid'] if parsed_user.fetch('orcid', nil).present? if user.save - _success, message = assign_user_to_role(user, parsed_user) + _success, message = User.assign_user_to_role(user, parsed_user) messages << message else messages << "Error: #{user.errors.full_messages}" @@ -97,31 +77,6 @@ namespace :rdms do end end - def assign_user_to_role(user, parsed_user) - role_name = parsed_user.fetch('role', nil) - group_id = parsed_user.fetch('group_id', nil) - return true, '' if role_name.blank? - - role = if %w(admin publication_manager crc_1280_manager crc_1280_member).include?(role_name) - Role.find_or_create_by(name: role_name) - elsif role_name == "crc_1280_group_manager" and group_id.present? - Role.find_or_create_by(name: "crc_1280_#{group_id}_manager") - elsif role_name == "crc_1280_group_member" and group_id.present? - Role.find_or_create_by(name: "crc_1280_#{group_id}_member") - end - - unless role.present? - if %w(crc_1280_group_manager crc_1280_group_member).include?(role_name) and group_id.blank? - return false, "Error: #{role_name} needs a group id" - else - return false, "Error: #{role_name} is not a valid role" - end - end - - role.users << user if role.users.where(id: user.id).blank? - - return true, "Assigned user #{user.email} role #{role.name}" - end end # Example json file