From 93f5269ac58f8cbd96806d8c766199c4b0695da2 Mon Sep 17 00:00:00 2001 From: Paul Danelli Date: Tue, 2 Mar 2021 22:08:00 +0000 Subject: [PATCH 01/11] Enable Flipflop toggle for DOI minting (#28) * Add flip flop to control toggle Co-authored-by: Chris Colvard --- .rubocop.yml | 4 ++ Gemfile.lock | 2 + app/actors/hyrax/actors/doi_actor.rb | 2 +- .../hyrax/doi/hyrax_doi_controller.rb | 15 ++++-- app/helpers/hyrax/doi/work_form_helper.rb | 1 - app/views/hyrax/base/_form_doi.html.erb | 46 ++++++++++--------- config/features.rb | 7 +++ config/locales/hyrax_doi.en.yml | 5 +- hyrax-doi.gemspec | 3 +- lib/hyrax/doi.rb | 1 + lib/hyrax/doi/engine.rb | 6 +++ spec/features/create_draft_doi_spec.rb | 18 ++++++++ 12 files changed, 80 insertions(+), 30 deletions(-) create mode 100644 config/features.rb diff --git a/.rubocop.yml b/.rubocop.yml index 1749c23..2edf7ea 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 0d604e7..8056db6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -956,6 +957,7 @@ DEPENDENCIES devise-guests (~> 0.6) factory_bot_rails fcrepo_wrapper + flipflop hyrax (= 2.9.0) hyrax-doi! jbuilder (~> 2.5) diff --git a/app/actors/hyrax/actors/doi_actor.rb b/app/actors/hyrax/actors/doi_actor.rb index 808b520..71a3ef1 100644 --- a/app/actors/hyrax/actors/doi_actor.rb +++ b/app/actors/hyrax/actors/doi_actor.rb @@ -36,7 +36,7 @@ def update(env) private def create_or_update_doi(work) - return true unless doi_enabled_work_type?(work) + 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 diff --git a/app/controllers/hyrax/doi/hyrax_doi_controller.rb b/app/controllers/hyrax/doi/hyrax_doi_controller.rb index b9f32bd..b5435e3 100644 --- a/app/controllers/hyrax/doi/hyrax_doi_controller.rb +++ b/app/controllers/hyrax/doi/hyrax_doi_controller.rb @@ -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| diff --git a/app/helpers/hyrax/doi/work_form_helper.rb b/app/helpers/hyrax/doi/work_form_helper.rb index 8cccea2..89266f0 100644 --- a/app/helpers/hyrax/doi/work_form_helper.rb +++ b/app/helpers/hyrax/doi/work_form_helper.rb @@ -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 diff --git a/app/views/hyrax/base/_form_doi.html.erb b/app/views/hyrax/base/_form_doi.html.erb index 8315f66..cfbe12d 100644 --- a/app/views/hyrax/base/_form_doi.html.erb +++ b/app/views/hyrax/base/_form_doi.html.erb @@ -9,7 +9,7 @@ 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, @@ -41,28 +41,30 @@


-
- + <% if Flipflop.enabled?(:doi_minting) %> +
+ -
- - - - -
-
+
+ + + + +
+
+ <% end %>