Skip to content

Commit

Permalink
Merge pull request #2168 from sul-dlss/revert-revert
Browse files Browse the repository at this point in the history
Revert "Revert "Inline the render_ds_profile_header""
  • Loading branch information
jcoyne authored Jul 6, 2020
2 parents c2fc875 + b6bcacc commit c1165e4
Show file tree
Hide file tree
Showing 18 changed files with 260 additions and 231 deletions.
88 changes: 22 additions & 66 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-07-01 21:29:33 UTC using RuboCop version 0.86.0.
# on 2020-07-06 17:37:04 UTC using RuboCop version 0.86.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -47,52 +47,29 @@ Metrics/AbcSize:
Max: 82

# Offense count: 5
# Configuration parameters: CountComments, Max.
# Configuration parameters: CountComments.
Metrics/ClassLength:
Exclude:
- 'app/controllers/apo_controller.rb'
- 'app/controllers/catalog_controller.rb'
- 'app/forms/apo_form.rb'
- 'app/models/user_log.rb'
- 'app/presenters/buttons_presenter.rb'
Max: 173

# Offense count: 11
# Configuration parameters: IgnoredMethods, Max.
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Exclude:
- 'app/controllers/tags_controller.rb'
- 'app/forms/registration_form.rb'
- 'app/helpers/value_helper.rb'
- 'app/models/ability.rb'
- 'app/models/report.rb'
- 'app/models/track_sheet.rb'
- 'app/models/user.rb'
- 'app/models/user_log.rb'
- 'app/presenters/buttons_presenter.rb'
- 'app/services/apply_mods_metadata.rb'
- 'spec/support/fixtures.rb'
Max: 14

# Offense count: 74
# Offense count: 80
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength:
Max: 50

# Offense count: 3
# Configuration parameters: Max, CountKeywordArgs.
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Exclude:
- 'app/components/action_button.rb'
- 'app/jobs/modsulator_job.rb'
- 'app/services/apply_mods_metadata.rb'
Max: 7

# Offense count: 4
# Configuration parameters: IgnoredMethods, Max.
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
Exclude:
- 'app/models/ability.rb'
- 'app/models/track_sheet.rb'
- 'app/presenters/buttons_presenter.rb'
- 'app/services/apply_mods_metadata.rb'
Max: 12

# Offense count: 1
Naming/AccessorMethodName:
Expand All @@ -106,14 +83,7 @@ Naming/MemoizedInstanceVariableName:
Exclude:
- 'config/initializers/okcomputer.rb'

# Offense count: 1
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp
Naming/MethodParameterName:
Exclude:
- 'app/helpers/dor_object_helper.rb'

# Offense count: 16
# Offense count: 17
RSpec/AnyInstance:
Exclude:
- 'spec/controllers/bulk_actions_controller_spec.rb'
Expand All @@ -124,20 +94,21 @@ RSpec/AnyInstance:
- 'spec/features/enable_buttons_spec.rb'
- 'spec/features/item_registration_spec.rb'
- 'spec/features/set_governing_apo_spec.rb'
- 'spec/requests/edit_datastream_spec.rb'
- 'spec/requests/item_files_download_spec.rb'
- 'spec/requests/manage_release_spec.rb'

# Offense count: 83
# Offense count: 85
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Enabled: false

# Offense count: 74
# Offense count: 76
RSpec/DescribeClass:
Enabled: false

# Offense count: 182
# Offense count: 183
# Configuration parameters: Max.
RSpec/ExampleLength:
Enabled: false
Expand Down Expand Up @@ -183,37 +154,22 @@ RSpec/MessageChain:
- 'spec/jobs/descmetadata_download_job_spec.rb'
- 'spec/views/items/_collection_ui.html.erb_spec.rb'

# Offense count: 233
# Offense count: 232
# Configuration parameters: EnforcedStyle.
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
Enabled: false

# Offense count: 188
# Offense count: 189
# Configuration parameters: IgnoreSharedExamples.
RSpec/NamedSubject:
Enabled: false

# Offense count: 53
# Configuration parameters: Max.
RSpec/NestedGroups:
Exclude:
- 'spec/components/workflow_table_process_component_spec.rb'
- 'spec/controllers/bulk_actions_controller_spec.rb'
- 'spec/controllers/catalog_controller_spec.rb'
- 'spec/controllers/content_types_controller_spec.rb'
- 'spec/controllers/files_controller_spec.rb'
- 'spec/controllers/items_controller_spec.rb'
- 'spec/controllers/report_controller_spec.rb'
- 'spec/controllers/workflow_service_controller_spec.rb'
- 'spec/controllers/workflows_controller_spec.rb'
- 'spec/forms/apo_form_spec.rb'
- 'spec/jobs/checksum_report_job_spec.rb'
- 'spec/jobs/create_virtual_objects_job_spec.rb'
- 'spec/models/user_spec.rb'
- 'spec/services/state_service_spec.rb'
Max: 6

# Offense count: 3
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: Strict, EnforcedStyle.
# SupportedStyles: inflected, explicit
Expand Down Expand Up @@ -253,7 +209,7 @@ Rails/ApplicationJob:
- 'app/jobs/generic_job.rb'
- 'app/jobs/modsulator_job.rb'

# Offense count: 6
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: NilOrEmpty, NotPresent, UnlessPresent.
Rails/Blank:
Expand Down Expand Up @@ -345,7 +301,7 @@ Style/CommentedKeyword:
- 'lib/tasks/argo.rake'
- 'lib/tasks/argo_testing.rake'

# Offense count: 62
# Offense count: 63
Style/Documentation:
Enabled: false

Expand All @@ -372,7 +328,7 @@ Style/NumericPredicate:
- 'spec/**/*'
- 'app/jobs/descmetadata_download_job.rb'

# Offense count: 290
# Offense count: 291
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Expand Down
2 changes: 1 addition & 1 deletion app/components/datastream_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def control_group
end

def link_to_identifier
link_to dsid, ds_solr_document_path(pid, dsid), title: dsid, data: { blacklight_modal: 'trigger' }
link_to dsid, item_datastream_path(pid, dsid), title: dsid, data: { blacklight_modal: 'trigger' }
end

def size
Expand Down
19 changes: 0 additions & 19 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class CatalogController < ApplicationController
helper ArgoHelper
include DateFacetConfigurations

before_action :show_aspect, only: %i[dc ds]
before_action :limit_facets_on_home_page, only: [:index]

configure_blacklight do |config|
Expand Down Expand Up @@ -215,26 +214,8 @@ def show
end
end

def dc
respond_to do |format|
format.html { render layout: !request.xhr? }
end
end

def ds
respond_to do |format|
format.html { render layout: !request.xhr? }
end
end

private

def show_aspect
pid = params[:id].include?('druid') ? params[:id] : "druid:#{params[:id]}"
@obj ||= Dor.find(pid)
@response, @document = search_service.fetch pid
end

def limit_facets_on_home_page
return if has_search_parameters? || params[:all]

Expand Down
72 changes: 72 additions & 0 deletions app/controllers/datastreams_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# frozen_string_literal: true

class DatastreamsController < ApplicationController
include Blacklight::Catalog
copy_blacklight_config_from CatalogController

before_action :show_aspect, only: %i[dc show edit]

def dc
respond_to do |format|
format.html { render layout: !request.xhr? }
end
end

def edit
@ds = @obj.datastreams[params[:id]]
render layout: !request.xhr?
end

def show
if params[:dsid] == 'full_dc'
@content = Nokogiri::XML(Dor::Services::Client.object(@obj.pid).metadata.dublin_core).prettify
else
@ds = @obj.datastreams[params[:id]]

@content = if @ds.respond_to? :ng_xml
Nokogiri::XML(@ds.ng_xml.to_s, &:noblanks).to_s
else
Nokogiri::XML(@ds.content, &:noblanks).to_s
end
end

raise ActionController::RoutingError, 'Not Found' if @content.nil?

respond_to do |format|
format.html { render layout: !request.xhr? }
end
end

##
# @option params [String] `:content` the XML with which to replace the datastream
# @option params [String] `:id` the identifier for the datastream, e.g., `identityMetadata`
# @option params [String] `:item_id` the druid to modify
def update
@object = Dor.find params[:item_id]
authorize! :manage_item, @object

raise ArgumentError, 'Missing content' if params[:content].blank?

begin
# check that the content is well-formed xml
Nokogiri::XML(params[:content], &:strict)
rescue Nokogiri::XML::SyntaxError
raise ArgumentError, 'XML is not well formed!'
end
@object.datastreams[params[:id]].content = params[:content] # set the XML to be verbatim as posted
@object.save
Argo::Indexer.reindex_pid_remotely(@object.pid)

respond_to do |format|
format.any { redirect_to solr_document_path(params[:item_id]), notice: 'Datastream was successfully updated' }
end
end

private

def show_aspect
pid = params[:item_id].include?('druid') ? params[:item_id] : "druid:#{params[:item_id]}"
@obj = Dor.find(pid)
@response, @document = search_service.fetch pid # this does the authorization
end
end
23 changes: 0 additions & 23 deletions app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class ItemsController < ApplicationController
before_action :create_obj, except: :purl_preview
before_action :authorize_manage!, only: %i[
add_collection set_collection remove_collection
datastream_update
mods
purge_object
source_id
Expand Down Expand Up @@ -116,28 +115,6 @@ def embargo_update
end
end

##
# @option params [String] `:content` the XML with which to replace the datastream
# @option params [String] `:dsid` the identifier for the datastream, e.g., `identityMetadata`
# @option params [String] `:id` the druid to modify
def datastream_update
raise ArgumentError, 'Missing content' unless params[:content].present?
raise ArgumentError, 'Missing datastream identifier' unless params[:dsid].present?

begin
# check that the content is well-formed xml
Nokogiri::XML(params[:content], &:strict)
rescue Nokogiri::XML::SyntaxError
raise ArgumentError, 'XML is not well formed!'
end
@object.datastreams[params[:dsid]].content = params[:content] # set the XML to be verbatim as posted
save_and_reindex

respond_to do |format|
format.any { redirect_to solr_document_path(params[:id]), notice: 'Datastream was successfully updated' }
end
end

# Given two instances of VersionTag, find the most significant difference
# between the two (return nil if either one is nil or if they're the same)
# @param [String] cur_version_tag current version tag
Expand Down
8 changes: 0 additions & 8 deletions app/helpers/dor_object_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,4 @@ def render_workflows(doc)
end
render 'catalog/show_workflows', document_id: doc.id, workflows: workflows
end

# rubocop:disable Layout/LineLength
def render_ds_profile_header(ds)
dscd = ds.createDate
dscd = dscd.xmlschema if dscd.is_a?(Time)
%(<foxml:datastream ID="#{ds.dsid}" STATE="#{ds.state}" CONTROL_GROUP="#{ds.controlGroup}" VERSIONABLE="#{ds.versionable}">\n <foxml:datastreamVersion ID="#{ds.dsVersionID}" LABEL="#{ds.label}" CREATED="#{dscd}" MIMETYPE="#{ds.mimeType}">)
end
# rubocop:enable Layout/LineLength
end
2 changes: 1 addition & 1 deletion app/views/catalog/_full_view_links_default.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class='btn-group full-view-links' role='group'>
<%= link_to 'View full Dublin Core', dc_solr_document_path(document.id), title: 'Dublin Core (derived from MODS)', class: 'btn btn-secondary btn-sm', data: { blacklight_modal: 'trigger' } %>
<%= link_to 'View full Dublin Core', dc_item_datastream_path(document.id), title: 'Dublin Core (derived from MODS)', class: 'btn btn-secondary btn-sm', data: { blacklight_modal: 'trigger' } %>
<%= link_to 'View MODS', purl_preview_item_url(document.id), title: 'MODS View', class: 'btn btn-secondary btn-sm', data: { blacklight_modal: 'trigger' } %>
</div>
45 changes: 0 additions & 45 deletions app/views/catalog/ds.html.erb

This file was deleted.

Loading

0 comments on commit c1165e4

Please sign in to comment.