-
Notifications
You must be signed in to change notification settings - Fork 57
Expose isa tags through api #2448
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
Open
kdp-cloud
wants to merge
9
commits into
main
Choose a base branch
from
expose-isa-tags-through-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+88
−1
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d5aeec3
Add controller
kdp-cloud e7ce06f
Add routes
kdp-cloud cfeea53
Add serializer
kdp-cloud 003485a
Adjust so request resolves to the correct controller
kdp-cloud d4e6a6c
Add controller methods
kdp-cloud 8f2ea0e
Convert to singular
kdp-cloud f819307
Remove fixtures
kdp-cloud eccbf33
Use test helper to create all isa tags at setup
kdp-cloud 624e24d
Undo removing fixtures
kdp-cloud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| class ISATagsController < ApplicationController | ||
| respond_to :json | ||
| api_actions :show, :index | ||
| before_action :ensure_json_request | ||
| before_action :isa_json_compliance_enabled? | ||
| before_action :login_required | ||
|
|
||
| def index | ||
| respond_to do |format| | ||
| format.json { | ||
| render json: ISATag.all, | ||
| each_serializer: ISATagSerializer, | ||
| meta: { | ||
| base_url: Seek::Config.site_base_host, | ||
| api_version: ActiveModel::Serializer.config.api_version | ||
| } | ||
| } | ||
| end | ||
| end | ||
|
|
||
| def show | ||
| respond_to do |format| | ||
| format.json { render json: ISATag.find(params[:id]) } | ||
| end | ||
| end | ||
|
|
||
|
|
||
| private | ||
|
|
||
| def ensure_json_request | ||
| # Accept header or URL format must request JSON | ||
| return if request.format.json? | ||
|
|
||
| render json: { | ||
| error: "Not Acceptable", | ||
| message: "This endpoint only serves application/json." | ||
| }, status: :not_acceptable # 406 | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class ISATagSerializer < ActiveModel::Serializer | ||
| attributes :title | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # frozen_string_literal: true | ||
| require 'test_helper' | ||
|
|
||
| class ISATagsControllerTest < ActionController::TestCase | ||
| include AuthenticatedTestHelper | ||
| fixtures :isa_tags | ||
|
|
||
| def setup | ||
| @authenticated_user = FactoryBot.create(:person) | ||
| Seek::Config.isa_json_compliance_enabled = true | ||
| end | ||
|
|
||
| def teardown | ||
| Seek::Config.isa_json_compliance_enabled = false | ||
| end | ||
|
|
||
| test 'should return ISA tags if logged in' do | ||
| login_as @authenticated_user | ||
|
|
||
| get :index, as: :json | ||
| assert_response :success | ||
| response_body = JSON.parse(response.body) | ||
| assert_equal response_body["data"].count, 10 | ||
| end | ||
|
|
||
| test 'should not return ISA tags if not logged in' do | ||
| get :index, as: :json | ||
| assert_response :unauthorized | ||
| assert_equal response.body, "HTTP Basic: Access denied.\n" | ||
| end | ||
|
|
||
| test 'should not respond to anything else than json requests' do | ||
| get :index, as: :xml | ||
| assert_response :not_acceptable | ||
| response_body = JSON.parse(response.body) | ||
| assert_equal response_body["error"], "Not Acceptable" | ||
| end | ||
|
|
||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be based off
BaseSerializerorSimpleBaseSerializerto get the jsonapi and meta blocks