-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Everything needed to load all lists from the app store
- Loading branch information
1 parent
93fb689
commit cc49040
Showing
12 changed files
with
268 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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,33 @@ | ||
module V1 | ||
class AssignmentsController < ApplicationController | ||
def create | ||
current_submission.with_lock do | ||
current_submission.assigned_user_id = params[:caseworker_id] | ||
current_submission.save! | ||
end | ||
head :created | ||
end | ||
|
||
def destroy | ||
current_submission.with_lock do | ||
# `unassigned_user_ids allows us to log which caseworkers have ever been | ||
# assigned to a claim, both for search filtering and to allow us to run | ||
# automatic assignment logic | ||
current_submission.unassigned_user_ids << current_submission.assigned_user_id | ||
current_submission.assigned_user_id = nil | ||
current_submission.save! | ||
end | ||
head :no_content | ||
end | ||
|
||
private | ||
|
||
def current_submission | ||
@current_submission ||= Submission.find(params[:submission_id]) | ||
end | ||
|
||
def authorization_object | ||
current_submission | ||
end | ||
end | ||
end |
This file contains 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 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 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 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 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
25 changes: 25 additions & 0 deletions
25
db/migrate/20241105091753_add_assignment_fields_to_application.rb
This file contains 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,25 @@ | ||
class AddAssignmentFieldsToApplication < ActiveRecord::Migration[7.2] | ||
def up | ||
add_column :application, :assigned_user_id, :string | ||
add_column :application, :unassigned_user_ids, :string, array: true, default: [] | ||
|
||
Submission.find_each do |submission| | ||
ass_and_unass_events = submission.events.select { _1['event_type'].in?(%w[assignment unassignment send_back]) } | ||
.sort_by { DateTime.parse(_1['created_at']) } | ||
last_event = ass_and_unass_events.last | ||
|
||
if last_event['event_type'] == 'assignment' | ||
assigned_user_id = last_event['primary_user_id'] | ||
end | ||
|
||
unassigned_user_ids = ass_and_unass_events.map { _1['primary_user_id'] }.compact.uniq - [assigned_user_id] | ||
|
||
submission.update!(assigned_user_id:, unassigned_user_ids:) | ||
end | ||
end | ||
|
||
def down | ||
remove_column :application, :assigned_user_id, :string | ||
remove_column :application, :unassigned_user_ids, :string, array: true, default: [] | ||
end | ||
end |
This file contains 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 @@ | ||
class UpdateSearchesToVersion6 < ActiveRecord::Migration[7.2] | ||
def change | ||
update_view :searches, version: 6, revert_to_version: 5 | ||
end | ||
end |
This file contains 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 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 @@ | ||
WITH defendants AS ( | ||
SELECT | ||
app.id, | ||
CASE WHEN app.application_type = 'crm4' THEN | ||
(app_ver.application -> 'defendant' ->> 'first_name') || ' ' || (app_ver.application -> 'defendant' ->> 'last_name') | ||
ELSE | ||
( | ||
SELECT (defendants.value->>'first_name') || ' ' || (defendants.value->>'last_name') | ||
FROM jsonb_array_elements(app_ver.application->'defendants') AS defendants | ||
WHERE defendants.value->>'main' = 'true' | ||
) | ||
END AS client_name | ||
FROM application AS app | ||
JOIN application_version AS app_ver | ||
ON app.id = app_ver.application_id AND app.current_version = app_ver.version | ||
) | ||
SELECT | ||
app.id, | ||
app_ver.id as application_version_id, | ||
app_ver.application ->> 'laa_reference' as laa_reference, | ||
app_ver.application -> 'firm_office' ->> 'name' as firm_name, | ||
app_ver.application -> 'firm_office' ->> 'account_number' as account_number, | ||
def.client_name, | ||
app_ver.search_fields, | ||
app.has_been_assigned_to, | ||
app.assigned_user_id, | ||
app.created_at as date_submitted, | ||
app.last_updated_at as last_updated, -- latest event's created_at date in most instances | ||
CASE WHEN app.state = 'submitted' AND app.assigned_user_id IS NOT NULL THEN 'in_progress' | ||
WHEN app.state = 'submitted' AND app.assigned_user_id IS NULL THEN 'not_assigned' | ||
ELSE app.state | ||
END AS status_with_assignment, | ||
app.application_type as application_type, | ||
app.application_risk as risk | ||
FROM application AS app | ||
JOIN application_version AS app_ver | ||
ON app.id = app_ver.application_id AND app.current_version = app_ver.version | ||
JOIN defendants AS def | ||
ON def.id = app.id |
This file contains 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,35 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "Assignments" do | ||
let(:submission) { create(:submission) } | ||
let(:caseworker_id) { SecureRandom.uuid } | ||
|
||
before { allow(Tokens::VerificationService).to receive(:call).and_return(valid: true, role: :caseworker) } | ||
|
||
describe "#create" do | ||
it "records the assignment" do | ||
post "/v1/submissions/#{submission.id}/assignment", params: { caseworker_id: } | ||
expect(response).to have_http_status :created | ||
|
||
expect(submission.reload.assigned_user_id).to eq caseworker_id | ||
end | ||
end | ||
|
||
describe "#destroy" do | ||
before { submission.update(assigned_user_id: caseworker_id, unassigned_user_ids: %w[foo]) } | ||
|
||
it "removes the assignment" do | ||
delete "/v1/submissions/#{submission.id}/assignment" | ||
expect(response).to have_http_status :no_content | ||
|
||
expect(submission.reload.assigned_user_id).to be_nil | ||
end | ||
|
||
it "adds to the previous assignee list" do | ||
delete "/v1/submissions/#{submission.id}/assignment" | ||
expect(response).to have_http_status :no_content | ||
|
||
expect(submission.reload.unassigned_user_ids).to eq ["foo", caseworker_id] | ||
end | ||
end | ||
end |
This file contains 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