Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Samvera labs main #6

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Metrics/BlockLength:
- 'lib/hyrax/doi/spec/shared_specs/*'
- 'spec/**/*'

Metrics/MethodLength:
Exclude:
- 'app/controllers/hyrax/doi/hyrax_doi_controller.rb'

Layout/LineLength:
Exclude:
- 'spec/support/datacite_api_stubs.rb'
Expand Down
27 changes: 16 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PATH
specs:
hyrax-doi (0.2.0)
bolognese (~> 1.8, >= 1.8.6)
flipflop (~> 2.3)
hyrax (~> 2.9)
rails (~> 5.2.4, >= 5.2.4.3)

Expand Down Expand Up @@ -115,7 +116,7 @@ GEM
i18n
bcrypt (3.1.13)
benchmark_methods (0.7)
bibtex-ruby (5.1.4)
bibtex-ruby (6.0.0)
latex-decode (~> 0.0)
bixby (3.0.1)
rubocop (= 0.85.1)
Expand All @@ -141,7 +142,7 @@ GEM
bootstrap-sass (~> 3.0)
openseadragon (>= 0.2.0)
rails
bolognese (1.8.9)
bolognese (1.9.2)
activesupport (>= 4.2.5)
benchmark_methods (~> 0.7)
bibtex-ruby (>= 5.1.0)
Expand Down Expand Up @@ -207,9 +208,9 @@ GEM
nokogiri (~> 1.8)
citeproc (1.0.10)
namae (~> 1.0)
citeproc-ruby (1.1.12)
citeproc-ruby (1.1.14)
citeproc (~> 1.0, >= 1.0.9)
csl (~> 1.5)
csl (~> 1.6)
clipboard-rails (1.7.1)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
Expand All @@ -224,9 +225,10 @@ GEM
crack (0.4.3)
safe_yaml (~> 1.0.0)
crass (1.0.6)
csl (1.5.1)
csl (1.6.0)
namae (~> 1.0)
csl-styles (1.0.1.10)
rexml
csl-styles (1.0.1.11)
csl (~> 1.0)
declarative (0.0.20)
declarative-option (0.1.0)
Expand Down Expand Up @@ -314,7 +316,7 @@ GEM
rdf (~> 3.1)
scanf (~> 1.0)
sxp (~> 1.1)
edtf (3.0.5)
edtf (3.0.6)
activesupport (>= 3.0, < 7.0)
equivalent-xml (0.6.0)
nokogiri (>= 1.4.3)
Expand Down Expand Up @@ -523,7 +525,7 @@ GEM
kaminari-core (1.2.1)
kaminari_route_prefix (0.1.1)
kaminari (~> 1.0)
latex-decode (0.3.1)
latex-decode (0.3.2)
ld-patch (3.1.1)
ebnf (~> 2.0)
rdf (~> 3.1)
Expand Down Expand Up @@ -599,7 +601,9 @@ GEM
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2020.0512)
mimemagic (0.3.5)
mimemagic (0.3.10)
nokogiri (~> 1)
rake
mini_magick (4.10.1)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
Expand All @@ -608,7 +612,7 @@ GEM
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.1.1)
namae (1.0.1)
namae (1.1.1)
nest (3.2.0)
redic
net-http-persistent (3.1.0)
Expand All @@ -629,7 +633,7 @@ GEM
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
oj (3.10.14)
oj (3.13.1)
oj_mimic_json (1.0.1)
openseadragon (0.5.0)
rails (> 3.2.0)
Expand Down Expand Up @@ -956,6 +960,7 @@ DEPENDENCIES
devise-guests (~> 0.6)
factory_bot_rails
fcrepo_wrapper
flipflop
hyrax (= 2.9.0)
hyrax-doi!
jbuilder (~> 2.5)
Expand Down
11 changes: 9 additions & 2 deletions app/actors/hyrax/actors/doi_actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ module Actors
# env = Hyrax::Actors::Environment.new(object, ability, attributes)
# last_actor = Hyrax::Actors::Terminator.new
# stack.build(last_actor).create(env)
class DOIActor < AbstractActor
class DOIActor < BaseActor
delegate :destroy, to: :next_actor

##
# @return [Boolean]
#
Expand All @@ -30,13 +32,18 @@ def create(env)
#
# @see Hyrax::Actors::AbstractActor
def update(env)
# Ensure that the work has any changed attributes persisted before we create the job
apply_save_data_to_curation_concern(env)
save(env)

create_or_update_doi(env.curation_concern) && next_actor.update(env)
end

private

def create_or_update_doi(work)
return true unless doi_enabled_work_type?(work) && work.doi.present?
return true unless doi_enabled_work_type?(work) && Flipflop.enabled?(:doi_minting)


Hyrax::DOI::RegisterDOIJob.perform_later(work, registrar: work.doi_registrar.presence, registrar_opts: work.doi_registrar_opts)
end
Expand Down
15 changes: 11 additions & 4 deletions app/controllers/hyrax/doi/hyrax_doi_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ class HyraxDOIController < ApplicationController
before_action :check_authorization

def create_draft_doi
draft_doi = mint_draft_doi
if Flipflop.enabled?(:doi_minting)
draft_doi = mint_draft_doi

respond_to do |format|
format.js { render js: autofill_field(doi_attribute_name, draft_doi), status: :created }
format.json { render_json_response(response_type: :created, options: { data: draft_doi }) }
respond_to do |format|
format.js { render js: autofill_field(doi_attribute_name, draft_doi), status: :created }
format.json { render_json_response(response_type: :created, options: { data: draft_doi }) }
end
else
respond_to do |format|
format.js { render plain: I18n.t("errors.doi_minting.disabled"), status: :internal_error }
format.json { render_json_response(response_type: :internal_error, message: I18n.t("errors.doi_minting.disabled")) }
end
end
rescue Hyrax::DOI::DataCiteClient::Error => e
respond_to do |format|
Expand Down
1 change: 0 additions & 1 deletion app/helpers/hyrax/doi/work_form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module DOI
module WorkFormHelper
def form_tabs_for(form:)
if form.model_class.ancestors.include? Hyrax::DOI::DOIBehavior
# TODO: Add check for feature flipper?
super.prepend("doi")
else
super
Expand Down
70 changes: 33 additions & 37 deletions app/views/hyrax/base/_form_doi.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
style: "max-width: 40em" } %>

<%# Only show an actionable button if the work doesn't have a DOI already %>
<% if @curation_concern.doi.blank? %>
<% if @curation_concern.doi.blank? && Flipflop.enabled?(:doi_minting) %>
<%= link_to "Create draft DOI",
Hyrax::DOI::Engine.routes.url_helpers.create_draft_doi_path,
remote: true,
method: :get,
data: {
disable_with: "Creating draft DOI...",
disable_with: t("hyrax.works.form.mint.button.disable_with"),
params: {
curation_concern: @curation_concern.class.name.underscore,
attribute: 'doi'
Expand All @@ -32,37 +32,39 @@
remote: true,
method: :get,
data: {
confirm: "This operation is destructive and will replace any information already filled in on this form.",
disable_with: "Autofilling form...",
confirm: t("hyrax.works.form.autofill.button.confirm"),
disable_with: t("hyrax.works.form.autofill.button.disable_with"),
params: { curation_concern: curation_concern.class.name.underscore }
},
class: 'btn btn-primary',
id: 'doi-autofill-btn' %>

<br/><br/><br/>

<fieldset class="set-doi-status-when-public">
<label class="control-label">DOI status when work is public</label>
<% if Flipflop.enabled?(:doi_minting) %>
<fieldset class="set-doi-status-when-public">
<label class="control-label">DOI status when work is public</label>

<div class="form-group" style="margin-left: 20px">
<label class="radio" style="font-weight: normal">
<%= f.radio_button :doi_status_when_public, '', disabled: disable_do_not_mint, style: 'margin-top: 0px;' %>
Do not mint
</label>
<label class="radio" style="font-weight: normal">
<%= f.radio_button :doi_status_when_public, 'draft', disabled: disable_draft, style: 'margin-top: 0px;' %>
Draft
</label>
<label class="radio" style="font-weight: normal">
<%= f.radio_button :doi_status_when_public, 'registered', style: 'margin-top: 0px;' %>
Registered
</label>
<label class="radio" style="font-weight: normal">
<%= f.radio_button :doi_status_when_public, 'findable', style: 'margin-top: 0px;' %>
Findable
</label>
</div>
</fieldset>
<div class="form-group" style="margin-left: 20px">
<label class="radio" style="font-weight: normal">
<%= f.radio_button :doi_status_when_public, '', disabled: disable_do_not_mint, style: 'margin-top: 0px;' %>
Do not mint
</label>
<label class="radio" style="font-weight: normal">
<%= f.radio_button :doi_status_when_public, 'draft', disabled: disable_draft, style: 'margin-top: 0px;' %>
Draft
</label>
<label class="radio" style="font-weight: normal">
<%= f.radio_button :doi_status_when_public, 'registered', style: 'margin-top: 0px;' %>
Registered
</label>
<label class="radio" style="font-weight: normal">
<%= f.radio_button :doi_status_when_public, 'findable', style: 'margin-top: 0px;' %>
Findable
</label>
</div>
</fieldset>
<% end %>
</div>

<script type="text/javascript">
Expand All @@ -74,20 +76,14 @@
settings.url = settings.url + "&doi=" + encodeURIComponent(doi)
});

$("#doi-autofill-btn").on("ajax:error", function(e, xhr, status, error) {
alert('Some form fields prefilled. Please check for accuracy.');
});

$("#doi-autofill-btn").on("ajax:success", function(e, xhr, status, error) {
alert('Form fields autofilled');
});

$("#doi-create-draft-btn").on("ajax:error", function(e, xhr, status, error) {
alert('Please check DOI credentials');
alert(xhr.responseText);
});

$("#doi-create-draft-btn").on("ajax:success", function(e, xhr, status, error) {
alert('Draft DOI created');
// To override this action and add your own ajax error listener, you can use jQuery's `off` method,
// before registering your own listener. E.g. $("#doi-autofill-btn").off("ajax:error")
$("#doi-autofill-btn").on("ajax:error", function(e, xhr, status, error) {
alert(xhr.responseText);
});

// Force the user to confirm using fallback defaults when DataCite mandatory fields
Expand All @@ -96,7 +92,7 @@
$(document).ready(function() {
curation_concern = '<%= curation_concern.class.name.underscore %>';
document.getElementById('with_files_submit').addEventListener("click", function(event){
if (["findable", "registered"].indexOf(document.querySelector('input[name='+curation_concern+'"[doi_status_when_public]"]:checked').value) < 0)
if (["findable", "registered"].indexOf(document.querySelector('input[name="' + curation_concern + '[doi_status_when_public]"]:checked').value) < 0)
return;

const empty_fields = [];
Expand Down
7 changes: 7 additions & 0 deletions config/features.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

Flipflop.configure do
feature :doi_minting,
default: true,
description: "Toggle the DOI minting for this tenant"
end
12 changes: 11 additions & 1 deletion config/locales/hyrax_doi.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,15 @@ en:
hyrax:
works:
form:
mint:
button:
disable_with: Creating draft DOI...
autofill:
button:
disable_with: Autofilling form...
confirm: This operation is destructive and will replace any information already filled in on this form.
tab:
doi: DOI
doi: DOI
errors:
doi_minting:
disabled: DOI minting is disabled by your administrator
3 changes: 2 additions & 1 deletion hyrax-doi.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ Gem::Specification.new do |spec|
spec.add_dependency "rails", "~> 5.2.4", ">= 5.2.4.3"

spec.add_dependency "hyrax", "~> 2.9"

spec.add_dependency "flipflop", "~> 2.3"
spec.add_dependency "bolognese", "~> 1.8", ">= 1.8.6"

spec.add_development_dependency 'flipflop'
spec.add_development_dependency 'ammeter'
spec.add_development_dependency 'capybara'
spec.add_development_dependency 'chromedriver-helper', '~> 2.1'
Expand Down
1 change: 1 addition & 0 deletions lib/hyrax/doi.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true
require "hyrax/doi/engine"
require "hyrax/doi/errors"
require "flipflop"

module Hyrax
module DOI
Expand Down
6 changes: 6 additions & 0 deletions lib/hyrax/doi/engine.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module Hyrax
module DOI
class Engine < ::Rails::Engine
Expand All @@ -13,6 +14,11 @@ class Engine < ::Rails::Engine
end
end

# Allow flipflop to load config/features.rb from the Hyrax gem:
initializer 'configure' do
Flipflop::FeatureLoader.current.append(self)
end

config.after_initialize do
Hyrax::CurationConcern.actor_factory.use Hyrax::Actors::DOIActor

Expand Down
18 changes: 18 additions & 0 deletions spec/features/create_draft_doi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,22 @@
click_link "doi-create-draft-btn"
expect(page).to have_field('generic_work_doi', with: '10.1234/draft-doi')
end

describe "when the DOI has been disabled" do
before do
test_strategy = Flipflop::FeatureSet.current.test!
test_strategy.switch!(:doi_minting, false)

visit "/concern/generic_works/new"
end

scenario "disables the button" do
# For some reason page.find_button('#doi-create-draft-btn', disabled: true) isn't working
expect(page.find('#doi-create-draft-btn')[:disabled]).to eq "true"
end

scenario "hides the minting options" do
expect(page).not_to have_selector(".set-doi-status-when-public")
end
end
end