Skip to content

Commit

Permalink
Remove admin case creation (#2416)
Browse files Browse the repository at this point in the history
  • Loading branch information
vertism authored Jul 10, 2024
1 parent 5b72645 commit 2db31e2
Show file tree
Hide file tree
Showing 34 changed files with 3 additions and 2,692 deletions.
8 changes: 0 additions & 8 deletions README.docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,6 @@ Some of these older migrations made use of the gem `schema_plus_enums` which is

Individual correspondence items can be quickly created by logging in as David Attenborough, and using the admin tab to create any kind of case in any state.

##### Creating bulk test correspondence items

To create 200 cases in various states with various responders for search testing, you can use the following rake task:
```
rake seed:search:data
```
It appears that redis needs to be running to attempt this task - but it doesn't currently work for unknown reasons.

### Additional Setup

#### Libreoffice
Expand Down
151 changes: 0 additions & 151 deletions app/controllers/admin/cases_controller.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,4 @@
require "cts/cases/create"
require "cts/cases/constants"

class Admin::CasesController < AdminController
before_action :set_correspondence_type,
only: %i[
create
new
]

def create
@correspondence_type_key = params.fetch(:correspondence_type).downcase
case_params = params[case_and_type]
case_params[:creator] = current_user

prepare_flagged_options_for_creation(params)
case_creator = CTS::Cases::Create.new(Rails.logger, case_params)

@case = case_creator.new_case
@selected_state = case_params[:target_state]
(result, _case) = case_creator.call(@selected_state, @case)
if result == :ok
flash[:notice] = "Case created: #{@case.number}"
redirect_to(admin_cases_path)
else
@case.responding_team = BusinessUnit.find(
case_params[:responding_team],
)
prepare_flagged_options_for_displaying
@target_states = available_target_states
@s3_direct_post = S3Uploader.s3_direct_post_for_case(@case, "requests")
render :new
end
end

def index
@dates = {}
5.times do |n|
Expand All @@ -42,126 +8,9 @@ def index
@cases = Case::Base.all.order(id: :desc).page(params[:page]).decorate
end

def new
if params[:correspondence_type].present?
@correspondence_type_key = params[:correspondence_type]
prepare_new_case(creator: current_user)
else
select_type
end
end

private

def count_cases_created_on(date)
Case::Base.where(created_at: date.all_day).count
end

def select_type
permitted_correspondence_types

render :select_type
end

def prepare_new_case(creator:)
case_creator = CTS::Cases::Create.new(
Rails.logger,
type: class_for_case,
creator:,
)

@case = case_creator.new_case.decorate
@case.responding_team = BusinessUnit
.responding
.responding_for_correspondence_type(correspondence_type_for_case)
.active
.sample
@case.flag_for_disclosure_specialists = "no"
@target_states = available_target_states
@selected_state = "drafting"
@s3_direct_post = S3Uploader.s3_direct_post_for_case(@case, "requests")
end

def permitted_correspondence_types
@permitted_correspondence_types = [
CorrespondenceType.foi,
CorrespondenceType.sar,
CorrespondenceType.ico,
CorrespondenceType.overturned_sar,
CorrespondenceType.overturned_foi,
]
end

def correspondence_type_for_case
correspondence_types = {
"foi" => CorrespondenceType.foi,
"sar" => CorrespondenceType.sar,
"ico" => CorrespondenceType.ico,
"overturned_foi" => CorrespondenceType.foi,
"overturned_sar" => CorrespondenceType.sar,
}
correspondence_types[@correspondence_type_key]
end

def class_for_case
case_classes = {
"foi" => "Case::FOI::Standard",
"sar" => "Case::SAR::Standard",
"ico" => "Case::ICO::FOI",
"overturned_foi" => "Case::OverturnedICO::FOI",
"overturned_sar" => "Case::OverturnedICO::SAR",
}
case_classes[@correspondence_type_key]
end

def available_target_states
CTS::Cases::Constants::CASE_JOURNEYS[@case.class.state_machine_name.to_sym].values.flatten.uniq.sort
end

def param_flag_for_ds?
params[case_and_type][:flagged_for_disclosure_specialist_clearance] == "1" ||
case_and_type == :case_ico
end

def param_flag_for_press?
params[case_and_type][:flagged_for_press_office_clearance] == "1"
end

def param_flag_for_private?
params[case_and_type][:flagged_for_private_office_clearance] == "1"
end

def gather_teams_for_flagging
teams_for_flagging = []
teams_for_flagging << "disclosure" if param_flag_for_ds?
teams_for_flagging << "press" if param_flag_for_press?
teams_for_flagging << "private" if param_flag_for_private?
teams_for_flagging
end

def prepare_flagged_options_for_creation(params)
if param_flag_for_ds? && !param_flag_for_press? && !param_flag_for_private?
params[case_and_type][:flag_for_disclosure] = true
else
params[case_and_type][:flag_for_team] = gather_teams_for_flagging.join(",")
end
end

def prepare_flagged_options_for_displaying
@case.approving_teams << BusinessUnit.dacu_disclosure if param_flag_for_ds?
@case.approving_teams << BusinessUnit.press_office if param_flag_for_press?
@case.approving_teams << BusinessUnit.private_office if param_flag_for_private?
end

def case_and_type
"case_#{@correspondence_type_key}".to_sym
end

def set_correspondence_type
if params[:correspondence_type].present?
@correspondence_type = CorrespondenceType.find_by(
abbreviation: params[:correspondence_type].upcase,
)
end
end
end
65 changes: 0 additions & 65 deletions app/views/admin/cases/foi/_new.html.slim

This file was deleted.

34 changes: 0 additions & 34 deletions app/views/admin/cases/ico/_new.html.slim

This file was deleted.

4 changes: 0 additions & 4 deletions app/views/admin/cases/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
.column-full.button-holder
= link_to t('admin.cases.index.download_audit_csv_file'), download_audit_stats_path, target: '_blank'

.grid-row
.column-full.button-holder
= link_to t('common.new_case_button'), new_admin_case_path, class: 'button'

.grid-row
.column-full.table-container.container
h2.heading-medium
Expand Down
15 changes: 0 additions & 15 deletions app/views/admin/cases/new.html.slim

This file was deleted.

23 changes: 0 additions & 23 deletions app/views/admin/cases/overturned_foi/_new.html.slim

This file was deleted.

21 changes: 0 additions & 21 deletions app/views/admin/cases/overturned_sar/_new.html.slim

This file was deleted.

Loading

0 comments on commit 2db31e2

Please sign in to comment.