-
Notifications
You must be signed in to change notification settings - Fork 1
Committee API endpoint #1001
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
Joao Vitor Barros da Silva (jvitorbarros15)
wants to merge
38
commits into
main
Choose a base branch
from
api-controller
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.
Open
Committee API endpoint #1001
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
d50a5e0
Add api folder and committee api controller
jvitorbarros15 2b9cead
updated controller, added routes and added a format_committees helper…
usmannsiddiqui c6fd0cb
Add Render JSON and keys to_s
jvitorbarros15 215cc48
Api key set in .envrc
usmannsiddiqui 6cbd4ce
Removed some .md docs from version control
usmannsiddiqui 15d9cf1
Merge main
jvitorbarros15 ccbad19
Replace ENV API key auth with ExternalApp token authentication and ad…
jvitorbarros15 77caf9a
Rubocop Corrections
jvitorbarros15 06f70e2
Add committee_role_normalizer and request specs
jvitorbarros15 2a81bc6
Merge branch 'main' into api-controller
jvitorbarros15 1e5aa60
Fix Student name with student_fname and student_lname and add interna…
jvitorbarros15 4dc14fe
Remove normalizer and moved it to FAMS_TOOL
jvitorbarros15 214bb98
Simplified Routes for API and add basic spec for committee_records_co…
jvitorbarros15 3e1dce5
Refactor committee formatting to reduce RuboCop complexity
jvitorbarros15 e3f5d38
Merge branch 'main' into api-controller
jvitorbarros15 c822da2
Simplified the API controller objects and add join scope methods
jvitorbarros15 7d949d6
Add more rspec tests for API controller
jvitorbarros15 481d26b
Merge main
jvitorbarros15 d608160
Add request specs for committee records response structure
jvitorbarros15 4718825
Add request spec for multiple committee memberships response
jvitorbarros15 2e93edf
Add gem rswag
jvitorbarros15 553e627
Add rswag initial documentation
jvitorbarros15 8ace73c
Add rswag docs with auth (working)
jvitorbarros15 2e9f672
Fix rswag spec (All tests passing)
jvitorbarros15 05943a8
Rubocop corrections
jvitorbarros15 b40fe34
added a class for fams tools
madhurakhandkar 049a3a5
Add the Rswag documentation back, move gem rswag to global scope, rem…
jvitorbarros15 f764690
Merge branch 'api-controller' of https://github.com/psu-libraries/etd…
madhurakhandkar b02b68e
Resolve merge conflict in committee_records_spec.rb, keeping remote c…
madhurakhandkar f8df7f4
Fix RuboCop Rswag DSL issues, exclude Rswag spec from problematic cop…
jvitorbarros15 14f3b55
Remove more comments froom api controller
jvitorbarros15 42d7a5b
Resolve merge conflict in routes.rb and keep admin mounts for Sidekiq…
jvitorbarros15 5634d04
Merge branch 'api-controller' of https://github.com/psu-libraries/etd…
jvitorbarros15 42b3050
Remove response 400 using x-api-key from committee_records_spec
jvitorbarros15 1938712
Switch committee records API auth from Bearer token to X-API-KEY header
usmannsiddiqui 817af32
Rubocop corrections
jvitorbarros15 ff06adf
Fix committee_records_controller_spec.rb changing the authorization h…
jvitorbarros15 45d1dbe
Enable swagger_filter to dynamically set host from request
usmannsiddiqui 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,3 +55,4 @@ config/settings/*.local.yml | |
| config/environments/*.local.yml | ||
|
|
||
| /config/master.key | ||
| docs/development/ | ||
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
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,80 @@ | ||
| module Api | ||
| module V1 | ||
| class CommitteeRecordsController < ApplicationController | ||
| skip_before_action :verify_authenticity_token | ||
|
|
||
| before_action :authenticate_api_key | ||
|
|
||
| def faculty_committees | ||
| access_id = params[:access_id] | ||
| if access_id.blank? | ||
| render json: { error: 'access_id is required' }, status: :bad_request | ||
| return | ||
| end | ||
|
|
||
| committee_memberships = CommitteeMember | ||
| .joins(:submission).where('submissions.status LIKE "released for publication%" OR submissions.status = "waiting for publication release"') | ||
| .includes(:committee_role, submission: [:author, :degree, :program]) | ||
| .where(access_id: access_id) | ||
|
|
||
| render json: { | ||
| faculty_access_id: access_id, | ||
| committees: format_committees(committee_memberships) | ||
| }, status: :ok | ||
| rescue StandardError => e | ||
| render json: { error: e.message }, status: :internal_server_error | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def authenticate_api_key | ||
| token = request.headers['HTTP_X_API_KEY'] | ||
|
|
||
| @api_token = ApiToken.includes(:external_app).find_by(token: token) | ||
| return unauthorized! unless @api_token | ||
|
|
||
| @external_app = @api_token.external_app | ||
| @api_token.update_column(:last_used_at, Time.current) | ||
|
|
||
| true | ||
| end | ||
|
|
||
| def unauthorized! | ||
| render json: { error: "Unauthorized" }, status: :unauthorized | ||
| end | ||
|
|
||
| def format_committees(committee_memberships) | ||
| committee_memberships.map { |membership| committee_payload(membership) } | ||
| end | ||
|
|
||
| def committee_payload(membership) | ||
| submission = membership.submission | ||
| author = submission&.author | ||
|
|
||
| { | ||
| committee_member_id: membership.id, | ||
|
|
||
| role: membership.committee_role&.name, | ||
| role_code: membership.committee_role&.code, | ||
|
|
||
| student_fname: author&.first_name, | ||
| student_lname: author&.last_name, | ||
| student_access_id: author&.access_id, | ||
|
|
||
| submission_id: submission.id, | ||
| title: submission.title, | ||
| degree_name: submission.degree&.name, | ||
| program_name: submission.program&.name, | ||
| semester: submission.semester, | ||
| year: submission.year, | ||
|
|
||
| approval_started_at: membership.approval_started_at, | ||
| final_submission_approved_at: submission.final_submission_approved_at, | ||
|
|
||
| submission_status: submission.status, | ||
| committee_member_status: membership.status | ||
| } | ||
| end | ||
| end | ||
| 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
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,14 @@ | ||
| Rswag::Api.configure do |c| | ||
|
|
||
| # Specify a root folder where Swagger JSON files are located | ||
| # This is used by the Swagger middleware to serve requests for API descriptions | ||
| # NOTE: If you're using rswag-specs to generate Swagger, you'll need to ensure | ||
| # that it's configured to generate files in the same folder | ||
| c.openapi_root = Rails.root.to_s + '/swagger' | ||
|
|
||
| # Inject a lambda function to alter the returned Swagger prior to serialization | ||
| # The function will have access to the rack env for the current request | ||
| # For example, you could leverage this to dynamically assign the "host" property | ||
| # | ||
| c.swagger_filter = lambda { |swagger, env| swagger['host'] = env['HTTP_HOST'] } | ||
| 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,16 @@ | ||
| Rswag::Ui.configure do |c| | ||
|
|
||
| # List the Swagger endpoints that you want to be documented through the | ||
| # swagger-ui. The first parameter is the path (absolute or relative to the UI | ||
| # host) to the corresponding endpoint and the second is a title that will be | ||
| # displayed in the document selector. | ||
| # NOTE: If you're using rspec-api to expose Swagger files | ||
| # (under openapi_root) as JSON or YAML endpoints, then the list below should | ||
| # correspond to the relative paths for those endpoints. | ||
|
|
||
| c.swagger_endpoint '/admin/api-docs/v1/swagger.yaml', 'API V1 Docs' | ||
|
|
||
| # Add Basic Auth in case your API is private | ||
| # c.basic_auth_enabled = true | ||
| # c.basic_auth_credentials 'username', 'password' | ||
| 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
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.
This will actually need to be moved up into the global scope. This is why CI is failing, the RSwag engine is used to display the documentation in production, but we don't have it installing in production environments.