Its been a while
CI / scan_ruby (push) Failing after 2m13s
CI / lint (push) Failing after 20s

This commit is contained in:
Jason Jordan
2026-07-23 10:41:46 -04:00
parent 16fadfd529
commit 9853d58469
83 changed files with 1978 additions and 243 deletions
+4 -4
View File
@@ -42,15 +42,15 @@ module Api
end
end
# post /logout -> NOW with real token blacklisting
# adds the current token to blacklist so it can't be used again
# post /logout -> NOW with real token retireing
# adds the current token to retire so it can't be used again
# authorize_request ensures @current_user and token are present
def logout
header = request.headers["Authorization"]
token = header.split(" ").last if header
decoded = JsonWebToken.decode(token)
BlacklistedToken.create!(
RetiredToken.create!(
jti: decoded[:jti],
user_id: decoded[:user_id],
exp: Time.at(decoded[:exp])
@@ -59,7 +59,7 @@ module Api
# also revoke all refresh tokens for this user
@current_user.refresh_tokens.update_all(revoked: true)
render json: { message: "Successfully logged out. Token blacklisted." }, status: :ok
render json: { message: "Successfully logged out. Token retired." }, status: :ok
rescue StandardError => e
render json: { error: "Logout failed: #{e.message}" }, status: :unprocessable_entity
end
@@ -0,0 +1,16 @@
module Api
module V1
class BrokersController < ApplicationController
# before_action :authenticate_user!
def employers_list
broker_id = params[:id]
broker = Baclight::Broker.find(broker_id)
employers = broker.baclight_employers.order(:name).map { |emp| {name: emp.name, entity_key: emp.pl_plan_key }}
render json: employers, status: :ok
end
end
end
end
@@ -0,0 +1,8 @@
module Api
module V1
class CarriersController < ApplicationController
before_action :authenticate_user!
end
end
end
@@ -0,0 +1,18 @@
module Api
module V1
class ClaimsController < ApplicationController
def member_claims
pb_entity_key = params[:id]
member_claims = MemberClaimsService.new(pb_entity_key).call
if member_claims.present?
render json: member_claims, status: :ok
else
render json: { error: "Member Claims not found" }, status: :not_found
end
end
end
end
end
@@ -0,0 +1,36 @@
module Api
module V1
class EmployersController < ApplicationController
# before_action :authenticate_user!
def id_cards
pl_plan_key = params[:id]
id_cards = EmployersService::IdCards.new(pl_plan_key).call
if id_cards.code == 200
content_disposition = id_cards.headers['Content-Disposition']
filename = content_disposition[/filename="?([^"]*)"?/, 1]
# filename = params[:filename].presence || 'employer_idcards.zip'
send_data(
id_cards.body,
type: 'application/zip',
filename: filename,
disposition: 'attachment'
)
else
render json: { error: "Employer not found" }, status: :not_found
end
end
def members_list
pl_plan_key = params[:id]
employer = Baclight::Employer.find_by(pl_plan_key: pl_plan_key)
members = employer.baclight_members.active.order(:name).map { |mem| {name: mem.name, entity_key: mem.pb_entity_key}}
render json: members, status: :ok
end
end
end
end
@@ -0,0 +1,96 @@
module Api
module V1
class IdCardsController < ApplicationController
def member_card
pb_entity_key = params[:id]
layout = params[:layout]
@member = Baclight::Member.find_by(pb_entity_key: pb_entity_key)
# authorize :id_cards, @member
url_components = {
host: ENV["BACLIGHT_SERVER_HOST"],
port: ENV["BACLIGHT_SERVER_PORT"],
path: "/api/v1/web_id_cards/member_card/#{pb_entity_key}/#{layout}"
}
response = HTTParty.get(
URI::HTTP.build(url_components),
headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/pdf' },
stream_body: true
)
if response.code == 200
content_disposition = response.headers['Content-Disposition']
filename = content_disposition[/filename="?([^"]*)"?/, 1]
disposition = layout == "MobileDisplayCard" ? 'inline' : 'attachment'
send_data(
response.body,
type: 'application/pdf',
filename: filename,
disposition: disposition
)
else
render json: { error: "Member not found" }, status: :not_found
end
end
def member_benefits
pb_entity_key = params[:id]
@member = Baclight::Member.find_by(pb_entity_key: pb_entity_key)
plan_id = @member.id_card_plan_id
plan_benefits = Baclight::IdCardPlan.joins(:baclight_id_card_plan_benefits)
.select('id_card_plans.id, id_card_plans.title, id_card_plan_benefits.id, id_card_plan_benefits.sequence, id_card_plan_benefits.benefit, id_card_plan_benefits.benefit_desc')
.where(id: plan_id)
.distinct
if plan_benefits.present?
render json: plan_benefits, status: :ok
else
render json: { error: "Plan Benefits not found" }, status: :not_found
end
end
def employer_cards
pl_plan_key = params[:id]
@employer = Baclight::Employer.find_by(pl_plan_key: pl_plan_key)
# authorize :id_cards, @employer
url_components = {
host: ENV["BACLIGHT_SERVER_HOST"],
port: ENV["BACLIGHT_SERVER_PORT"],
path: "/api/v1/web_id_cards/employer_cards/#{pl_plan_key}"
}
# Send POST with params and enable streaming
response = HTTParty.get(
URI::HTTP.build(url_components),
headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/zip' },
stream_body: true
)
if response.code == 200
content_disposition = response.headers['Content-Disposition']
filename = content_disposition[/filename="?([^"]*)"?/, 1]
# filename = params[:filename].presence || 'employer_idcards.zip'
send_data(
response.body,
type: 'application/zip',
filename: filename,
disposition: 'attachment'
)
else
render json: { error: "Employer not found" }, status: :not_found
end
end
end
end
end
@@ -0,0 +1,74 @@
module Api
module V1
class MembersController < ApplicationController
# before_action :authenticate_user!
def initialize_dashboard
pb_entity_key = params[:id]
@member = Baclight::Member.find_by(pb_entity_key: pb_entity_key)
authorize @member
dashboard_data = MembersService::InitializeDashboard.new(@member).call
render json: dashboard_data, status: :ok
end
def id_card
pb_entity_key = params[:id]
layout = params[:layout]
@member = Baclight::Member.find_by(pb_entity_key: pb_entity_key)
# authorize @member
generated_id_card = MembersService::IdCard.new(@member, layout).call
if generated_id_card.code == 200
content_disposition = generated_id_card.headers['Content-Disposition']
filename = content_disposition[/filename="?([^"]*)"?/, 1]
# filename = params[:filename].presence || 'employer_idcards.zip'
send_data(
generated_id_card.body,
type: 'application/pdf',
filename: filename,
disposition: 'inline'
)
else
render json: { error: "Member not found" }, status: :not_found
end
end
def network_provider
pl_plan_key = params[:id]
network_provider = Baclight::IdCardSetup.find_by(pl_plan_key: pl_plan_key).slice(:network_provider)
if network_provider.present?
render json: network_provider, status: :ok
else
render json: { error: "Network Provider not found" }, status: :not_found
end
end
def plan_benefits
pb_entity_key = params[:id]
plan_benefits = MembersService::PlanBenefits.new(pb_entity_key).call
if plan_benefits.present?
render json: plan_benefits, status: :ok
else
render json: { error: "Plan Benefits not found" }, status: :not_found
end
end
def claims
pb_entity_key = params[:id]
@member = Baclight::Member.find_by(pb_entity_key: pb_entity_key)
recent_claims = MembersService::Claims.new(@member).call
render json: recent_claims, status: :ok
end
end
end
end
@@ -0,0 +1,19 @@
module Api
module V1
class NetworkProviderController < ApplicationController
def employer_network_provider
pl_plan_key = params[:id]
network_provider = Baclight::IdCardSetup.find_by(pl_plan_key: pl_plan_key).slice(:network_provider)
if network_provider.present?
render json: network_provider, status: :ok
else
render json: { error: "Network Provider not found" }, status: :not_found
end
end
end
end
end
@@ -0,0 +1,8 @@
module Api
module V1
class ProvidersController < ApplicationController
before_action :authenticate_user!
end
end
end
@@ -1,2 +1,3 @@
class ApplicationController < ActionController::API
include Pundit::Authorization
end
@@ -19,8 +19,8 @@ module AuthorizeRequest
begin
decoded = JsonWebToken.decode(token)
# check if token is blacklisted (logged out)
if BlacklistedToken.blacklisted?(decoded[:jti])
# check if token is retired (logged out)
if RetiredToken.retired?(decoded[:jti])
render json: { error: "Token has been revoked" }, status: :unauthorized
return
end
@@ -0,0 +1,30 @@
# frozen_string_literal: true
class Users::ConfirmationsController < Devise::ConfirmationsController
# GET /resource/confirmation/new
# def new
# super
# end
# POST /resource/confirmation
# def create
# super
# end
# GET /resource/confirmation?confirmation_token=abcdef
# def show
# super
# end
# protected
# The path used after resending confirmation instructions.
# def after_resending_confirmation_instructions_path_for(resource_name)
# super(resource_name)
# end
# The path used after confirmation.
# def after_confirmation_path_for(resource_name, resource)
# super(resource_name, resource)
# end
end
@@ -0,0 +1,30 @@
# frozen_string_literal: true
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
# You should configure your model like this:
# devise :omniauthable, omniauth_providers: [:twitter]
# You should also create an action method in this controller like this:
# def twitter
# end
# More info at:
# https://github.com/heartcombo/devise#omniauth
# GET|POST /resource/auth/twitter
# def passthru
# super
# end
# GET|POST /users/auth/twitter/callback
# def failure
# super
# end
# protected
# The path used when OmniAuth fails
# def after_omniauth_failure_path_for(scope)
# super(scope)
# end
end
@@ -0,0 +1,34 @@
# frozen_string_literal: true
class Users::PasswordsController < Devise::PasswordsController
# GET /resource/password/new
# def new
# super
# end
# POST /resource/password
# def create
# super
# end
# GET /resource/password/edit?reset_password_token=abcdef
# def edit
# super
# end
# PUT /resource/password
# def update
# super
# end
# protected
# def after_resetting_password_path_for(resource)
# super(resource)
# end
# The path used after sending reset password instructions
# def after_sending_reset_password_instructions_path_for(resource_name)
# super(resource_name)
# end
end
@@ -0,0 +1,105 @@
# frozen_string_literal: true
class Users::RegistrationsController < Devise::RegistrationsController
respond_to :json
before_action :configure_sign_up_params, only: [:create]
# before_action :configure_account_update_params, only: [:update]
# GET /resource/sign_up
# def new
# super
# end
# POST /resource
# def create
# super do |resource|
# resource.sync_role_entity!
# end
# end
# GET /resource/edit
# def edit
# super
# end
# PUT /resource
# def update
# super
# end
# DELETE /resource
# def destroy
# super
# end
# GET /resource/cancel
# Forces the session data which is usually expired after sign
# in to be expired now. This is useful if the user wants to
# cancel oauth signing in/up in the middle of the process,
# removing all OAuth session data.
# def cancel
# super
# end
# protected
private
# def respond_with(resource, _opts = {})
# if resource.persisted?
# render json: {
# status: { code: 200, message: 'Signed up successfully.' },
# data: resource
# }, status: :ok
# else
# render json: {
# status: { message: "User couldn't be created successfully. #{resource.errors.full_messages.to_sentence}" }
# }, status: :unprocessable_entity
# end
# end
def respond_with(resource, _opts = {})
if resource.persisted?
# Customize what is returned upon successful login here
render json: {
message: "Signed up successfully.",
user: {
id: resource.id,
email: resource.email,
name: resource.name,
role: resource.role,
role_id: resource.role_id,
jti: resource.jti,
keychain: resource.keychain,
created_at: resource.created_at,
updated_at: resource.updated_at
}
}, status: :ok
else
render json: {
status: { message: "User couldn't be created successfully. #{resource.errors.full_messages.to_sentence}" }
}, status: :unprocessable_entity
end
end
# If you have extra params to permit, append them to the sanitizer.
def configure_sign_up_params
devise_parameter_sanitizer.permit(:sign_up, keys: [:role, :role_id, :date_of_birth, :last_four_ssn])
end
# If you have extra params to permit, append them to the sanitizer.
# def configure_account_update_params
# devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
# end
# The path used after sign up.
# def after_sign_up_path_for(resource)
# super(resource)
# end
# The path used after sign up for inactive accounts.
# def after_inactive_sign_up_path_for(resource)
# super(resource)
# end
end
@@ -0,0 +1,49 @@
# frozen_string_literal: true
class Users::SessionsController < Devise::SessionsController
respond_to :json
# POST /resource/sign_in
# def create
# super
# end
# DELETE /resource/sign_out
# def destroy
# super
# end
private
def respond_with(resource, _opts = {})
puts
render json: {
status: { code: 200, message: 'Logged in successfully.' },
user: {
id: resource.id,
email: resource.email,
name: resource.name,
role: resource.role,
role_id: resource.role_id,
jti: resource.jti,
keychain: resource.keychain,
created_at: resource.created_at,
updated_at: resource.updated_at
}
}, status: :ok
end
def respond_to_on_destroy
if current_user
render json: {
status: 200,
message: "Logged out successfully."
}, status: :ok
else
render json: {
status: 401,
message: "Couldn't find an active session."
}, status: :unauthorized
end
end
end
@@ -0,0 +1,30 @@
# frozen_string_literal: true
class Users::UnlocksController < Devise::UnlocksController
# GET /resource/unlock/new
# def new
# super
# end
# POST /resource/unlock
# def create
# super
# end
# GET /resource/unlock?unlock_token=abcdef
# def show
# super
# end
# protected
# The path used after sending unlock password instructions
# def after_sending_unlock_instructions_path_for(resource)
# super(resource)
# end
# The path used after unlocking the resource
# def after_unlock_path_for(resource)
# super(resource)
# end
end