Skip to content

Commit

Permalink
Merge pull request #174 from samvera/bugfix_for_hyrax
Browse files Browse the repository at this point in the history
revert controllers to inherit from including app ApplicationController
  • Loading branch information
elrayle committed Sep 7, 2018
2 parents 2db8843 + 9f53336 commit 7ca7615
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 17 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
### 2.1.1 (2018-09-05)

* bugfix that allows application's ApplicationController to interact appropriately with engine's controllers

### 2.1.0 (2018-09-04)

* security vulnerability for rubocop resolved by moving to using bixby for rubocop
* add ability to sort linked data results based on a numeric ranking predicate
* filter out blanknodes from the linked data result set
* update supporting documents to match samvera community support documents
* add support for Rails 5.1
* add support for Rails 5.2
* add support for CORS headers (configurable; off by default)

### 2.0.1 (2018-02-22)
Expand Down
19 changes: 12 additions & 7 deletions app/controllers/qa/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Qa
class ApplicationController < ActionController::Base
# See https://fetch.spec.whatwg.org/#http-access-control-allow-headers
# Process the OPTIONS method for all routes
# @see route definitions in /config/routes.rb
# @note Reference: https://fetch.spec.whatwg.org/#http-access-control-allow-headers
def options
unless Qa.config.cors_headers?
head :not_implemented
Expand All @@ -11,11 +13,14 @@ def options
head :no_content
end

private

# See https://fetch.spec.whatwg.org/#http-access-control-allow-origin
def cors_allow_origin_header
response.headers['Access-Control-Allow-Origin'] = '*' if Qa.config.cors_headers?
end
# Add cors headers to the passed in http response if cors_headers are enabled. Called by all controller actions
# to adjust the response.
# @param http response
# @see /lib/generators/qa/install/templates/config/initializers/qa.rb
# @note The qa.rb initializer is copied to /config/initializers/qa.rb and can be modified to enable/disable cors headers.
# @note Reference: https://fetch.spec.whatwg.org/#http-access-control-allow-headers
def self.cors_allow_origin_header(response)
response.headers['Access-Control-Allow-Origin'] = '*' if Qa.config.cors_headers?
end
end
end
8 changes: 5 additions & 3 deletions app/controllers/qa/linked_data_terms_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# This controller is used for all requests to linked data authorities. It will verify params and figure
# out which linked data authority to query based on the 'vocab' param.

class Qa::LinkedDataTermsController < Qa::ApplicationController
class Qa::LinkedDataTermsController < ::ApplicationController
before_action :check_authority, :init_authority
before_action :check_search_subauthority, :check_query_param, only: :search
before_action :check_show_subauthority, :check_id_param, only: :show

delegate :cors_allow_origin_header, to: Qa::ApplicationController

# Provide a warning if there is a request for all terms.
def index
logger.warn 'Linked data authorities do not support retrieving all terms.'
Expand All @@ -31,7 +33,7 @@ def search # rubocop:disable Metrics/MethodLength
head :internal_server_error
return
end
cors_allow_origin_header
cors_allow_origin_header(response)
render json: terms
end

Expand All @@ -58,7 +60,7 @@ def show # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
head :internal_server_error
return
end
cors_allow_origin_header
cors_allow_origin_header(response)
render json: term
end

Expand Down
10 changes: 6 additions & 4 deletions app/controllers/qa/terms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
# All the authority classes inherit from a super class so they implement the
# same methods.

class Qa::TermsController < Qa::ApplicationController
class Qa::TermsController < ::ApplicationController
before_action :check_vocab_param, :init_authority
before_action :check_query_param, only: :search

delegate :cors_allow_origin_header, to: Qa::ApplicationController

# If the subauthority supports it, return a list of all terms in the authority
def index
cors_allow_origin_header
cors_allow_origin_header(response)
render json: begin
@authority.all
rescue NotImplementedError
Expand All @@ -20,14 +22,14 @@ def index
# Return a list of terms based on a query
def search
terms = @authority.method(:search).arity == 2 ? @authority.search(url_search, self) : @authority.search(url_search)
cors_allow_origin_header
cors_allow_origin_header(response)
render json: terms
end

# If the subauthority supports it, return all the information for a given term
def show
term = @authority.find(params[:id])
cors_allow_origin_header
cors_allow_origin_header(response)
render json: term
end

Expand Down
2 changes: 1 addition & 1 deletion lib/qa/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Qa
VERSION = "2.1.0".freeze
VERSION = "2.1.1".freeze
end
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@ Niger–Congo family.</rdfs:comment>
<lvont:label rdf:resource="http://lexvo.org/id/term/pms/Lenga%20Ari" /> <!-- Lenga Ari -->
<skos:prefLabel xml:lang="en">Ari</skos:prefLabel>
</rdf:Description>
</rdf:RDF>
2 changes: 1 addition & 1 deletion spec/lib/services/rdf_authority_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'spec_helper'

describe Qa::Services::RDFAuthorityParser do
let(:source) { [File.join(fixture_path, 'lexvo_snippet.rdf')] }
let(:source) { [File.join(fixture_path, 'lexvo_snippet.rdf.xml')] }
let(:format) { 'rdfxml' }
let(:predicate) { RDF::URI("http://www.w3.org/2008/05/skos#prefLabel") }
let(:name) { 'language' }
Expand Down

0 comments on commit 7ca7615

Please sign in to comment.