-
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
base: main
Are you sure you want to change the base?
Committee API endpoint #1001
Changes from 25 commits
d50a5e0
2b9cead
c6fd0cb
215cc48
6cbd4ce
15d9cf1
ccbad19
77caf9a
06f70e2
2a81bc6
1e5aa60
4dc14fe
214bb98
3e1dce5
e3f5d38
c822da2
7d949d6
481d26b
d608160
4718825
2e93edf
553e627
8ace73c
2e9f672
05943a8
b40fe34
049a3a5
f764690
b02b68e
f8df7f4
14f3b55
42d7a5b
5634d04
42b3050
1938712
817af32
ff06adf
45d1dbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| module Api | ||
| module V1 | ||
| class CommitteeRecordsController < ApplicationController | ||
| # Skip CSRF token verification for API requests | ||
| skip_before_action :verify_authenticity_token | ||
|
|
||
| # Authentication filter | ||
| before_action :authenticate_api_key | ||
|
|
||
| # POST /api/v1/committee_records/faculty_committees | ||
| # Expected params: { access_id: "xyz123" } | ||
| # Returns: JSON with all committee memberships for the faculty member | ||
| # | ||
| # Example request: | ||
| # curl -X POST http://localhost:3000/api/v1/committee_records/faculty_committees \ | ||
| # -H "Content-Type: application/json" \ | ||
| # -H "Authorization: Bearer your_token_here"\ | ||
| # -d '{"access_id": "aab27"}' | ||
|
||
|
|
||
| def faculty_committees | ||
| access_id = params[:access_id] | ||
| # Validate required parameter | ||
| if access_id.blank? | ||
| render json: { error: 'access_id is required' }, status: :bad_request | ||
| return | ||
| end | ||
|
|
||
| # Find all committee memberships for this faculty member | ||
| # Note: We search by access_id which is the PSU ID | ||
| 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 | ||
|
|
||
| # Authenticate using API Key from environment variable | ||
| # The API Key should be passed in the Authorization header | ||
| def authenticate_api_key | ||
| raw = request.headers["Authorization"].to_s.strip | ||
|
|
||
| token = | ||
| if raw.downcase.start_with?("bearer ") | ||
| raw.split(" ", 2).last.to_s.strip | ||
| else | ||
| raw | ||
| end | ||
|
|
||
| @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 | ||
|
|
||
| # Build the committee data object | ||
| { | ||
| # Committee member info | ||
| committee_member_id: membership.id, | ||
|
|
||
| # Committee role | ||
| role: membership.committee_role&.name, | ||
| role_code: membership.committee_role&.code, | ||
|
|
||
| # Student information | ||
| student_fname: author&.first_name, | ||
| student_lname: author&.last_name, | ||
| student_access_id: author&.access_id, | ||
|
|
||
| # Submission information | ||
| submission_id: submission.id, | ||
| title: submission.title, | ||
| degree_name: submission.degree&.name, | ||
| program_name: submission.program&.name, | ||
| semester: submission.semester, | ||
| year: submission.year, | ||
|
|
||
| # Important dates | ||
| approval_started_at: membership.approval_started_at, | ||
| final_submission_approved_at: submission.final_submission_approved_at, | ||
|
|
||
| # Status information | ||
| submission_status: submission.status, | ||
| committee_member_status: membership.status | ||
| } | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <div> | ||
| <h3 class='control-label mb-3'> <%= I18n.t("#{current_partner.id}.accessible_version_heading")%></h3> | ||
| <p> <%= I18n.t("#{current_partner.id}.accessible_version_notice")%> </p> | ||
| </div> |
| 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 |
| 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 '/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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
| require 'sidekiq/web' | ||
|
|
||
| Rails.application.routes.draw do | ||
| mount Rswag::Api::Engine => '/api-docs' | ||
| mount Rswag::Ui::Engine => '/api-docs' | ||
|
||
|
|
||
| devise_for :approvers, path: 'approver' | ||
| devise_for :authors, path: 'author' | ||
|
|
@@ -18,10 +20,14 @@ | |
|
|
||
| get '/', to: redirect(path: '/main') | ||
|
|
||
| mount Sidekiq::Web => '/sidekiq' | ||
|
|
||
| mount OkComputer::Engine, at: "/healthcheck" | ||
|
|
||
| namespace :api do | ||
| namespace :v1 do | ||
| post "committee_records/faculty_committees" | ||
| end | ||
| end | ||
|
|
||
| ## works: get '/committee_members/autocomplete', to: 'ldap_lookup#autocomplete', as: :committee_members_autocomplete | ||
| get '/committee_members/autocomplete', to: 'application#autocomplete', as: :committee_members_autocomplete | ||
|
|
||
|
|
@@ -43,6 +49,10 @@ | |
| resources :approval_configurations, except: [:new, :create, :destroy] | ||
| resources :authors, except: [:new, :create, :show, :destroy] | ||
|
|
||
| authenticate :admin do | ||
| mount Sidekiq::Web => '/sidekiq' | ||
| end | ||
|
Comment on lines
49
to
53
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are some things in here that aren't a part of your changes. Have you merged recent changes from |
||
|
|
||
| get '/custom_report', to: 'reports#custom_report_index', as: :custom_report_index | ||
| patch '/custom_report_export', to: 'reports#custom_report_export', defaults: { format: 'csv' }, as: :custom_report_export | ||
| get '/committee_report', to: 'reports#committee_report_index', as: :committee_report_index | ||
|
|
@@ -53,7 +63,6 @@ | |
| patch '/committee_member_report_export', to: 'reports#committee_member_report_export', defaults: { format: 'csv' }, as: :committee_member_report_export | ||
| patch '/graduate_data_report_export', to: 'reports#graduate_data_report_export', defaults: { format: 'json' }, as: :graduate_data_report_export | ||
|
|
||
|
|
||
| get '/authors/contact_list', to: 'authors#email_contact_list', as: :email_contact_list | ||
|
|
||
| get '/submissions/:id/edit', to: 'submissions#edit', as: :edit_submission | ||
|
|
||
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.