Skip to content
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

5781 standard court orders per org #5910

Closed
wants to merge 11 commits into from
5 changes: 5 additions & 0 deletions app/controllers/casa_org_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class CasaOrgController < ApplicationController
before_action :set_learning_hour_topics, only: %i[edit update]
before_action :set_sent_emails, only: %i[edit update]
before_action :set_contact_topics, only: %i[edit update]
before_action :set_standard_court_orders, only: %i[edit update]
before_action :require_organization!
after_action :verify_authorized
before_action :set_active_storage_url_options, only: %i[edit update]
Expand Down Expand Up @@ -90,6 +91,10 @@ def set_contact_topics
@contact_topics = @casa_org.contact_topics.where(soft_delete: false)
end

def set_standard_court_orders
@standard_court_orders = @casa_org.standard_court_orders
end

def set_active_storage_url_options
ActiveStorage::Current.url_options = {host: request.base_url}
end
Expand Down
52 changes: 52 additions & 0 deletions app/controllers/standard_court_orders_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class StandardCourtOrdersController < ApplicationController
before_action :set_standard_court_order, only: %i[edit update destroy]
after_action :verify_authorized

def new
authorize StandardCourtOrder
standard_court_order = StandardCourtOrder.new(casa_org_id: current_user.casa_org_id)
@standard_court_order = standard_court_order
end

def edit
authorize @standard_court_order
end

def create
authorize StandardCourtOrder
@standard_court_order = StandardCourtOrder.new(standard_court_order_params)

if @standard_court_order.save
redirect_to edit_casa_org_path(current_organization), notice: "Standard court order was successfully created."
else
render :new, status: :unprocessable_entity
end
end

def update
authorize @standard_court_order

if @standard_court_order.update(standard_court_order_params)
redirect_to edit_casa_org_path(current_organization), notice: "Standard court order was successfully updated."
else
render :edit, status: :unprocessable_entity
end
end

def destroy
authorize @standard_court_order

@standard_court_order.destroy
redirect_to edit_casa_org_path(current_organization), notice: "Standard court order was successfully deleted."
end

private

def set_standard_court_order
@standard_court_order = StandardCourtOrder.find(params[:id])
end

def standard_court_order_params
params.require(:standard_court_order).permit(:casa_org_id, :value)
end
end
1 change: 1 addition & 0 deletions app/models/casa_org.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class CasaOrg < ApplicationRecord
has_many :learning_hour_topics, dependent: :destroy
has_many :case_groups, dependent: :destroy
has_many :contact_topics
has_many :standard_court_orders, dependent: :destroy
has_one_attached :logo
has_one_attached :court_report_template

Expand Down
29 changes: 0 additions & 29 deletions app/models/case_court_order.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@
class CaseCourtOrder < ApplicationRecord
IMPLEMENTATION_STATUSES = {unimplemented: 1, partially_implemented: 2, implemented: 3}
STANDARD_COURT_ORDERS = [
"Birth certificate for the Respondent’s",
"Domestic Violence Education/Group",
"Educational monitoring for the Respondent",
"Educational or Vocational referrals",
"Family therapy",
"Housing support for the [parent]",
"Independent living skills classes or workshops",
"Individual therapy for the [parent]",
"Individual therapy for the Respondent",
"Learners’ permit for the Respondent, drivers’ education and driving hours when needed",
"No contact with (mother, father, other guardian)",
"Parenting Classes (mother, father, other guardian)",
"Psychiatric Evaluation and follow all recommendations (child, mother, father, other guardian)",
"Substance abuse assessment for the [parent]",
"Substance Abuse Evaluation and follow all recommendations (child, mother, father, other guardian)",
"Substance Abuse Treatment (child, mother, father, other guardian)",
"Supervised visits",
"Supervised visits at DSS",
"Therapy (child, mother, father, other guardian)",
"Tutor for the Respondent",
"Urinalysis (child, mother, father, other guardian)",
"Virtual Visits",
"Visitation assistance for the Respondent to see [family]"
].freeze

belongs_to :casa_case
belongs_to :court_date, optional: true
Expand All @@ -33,10 +8,6 @@ class CaseCourtOrder < ApplicationRecord

enum implementation_status: IMPLEMENTATION_STATUSES

def self.court_order_options
STANDARD_COURT_ORDERS.map { |o| [o, o] }
end

def implementation_status_symbol
case implementation_status
when "implemented"
Expand Down
25 changes: 25 additions & 0 deletions app/models/standard_court_order.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class StandardCourtOrder < ApplicationRecord
belongs_to :casa_org

validates :value, uniqueness: {scope: :casa_org_id, case_sensitive: false}, presence: true
end

# == Schema Information
#
# Table name: standard_court_orders
#
# id :bigint not null, primary key
# value :string
# created_at :datetime not null
# updated_at :datetime not null
# casa_org_id :bigint not null
#
# Indexes
#
# index_standard_court_orders_on_casa_org_id (casa_org_id)
# index_standard_court_orders_on_casa_org_id_and_value (casa_org_id,value) UNIQUE
#
# Foreign Keys
#
# fk_rails_... (casa_org_id => casa_orgs.id)
#
2 changes: 1 addition & 1 deletion app/policies/application_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def same_org?
case record
when CasaOrg
user.casa_org == record
when CasaAdmin, CasaCase, Volunteer, Supervisor, HearingType, ContactTypeGroup, ContactTopic
when CasaAdmin, CasaCase, Volunteer, Supervisor, HearingType, ContactTypeGroup, ContactTopic, StandardCourtOrder
user.casa_org == record.casa_org
when CourtDate, CaseContact, CaseAssignment
user.casa_org == record&.casa_case&.casa_org
Expand Down
21 changes: 21 additions & 0 deletions app/policies/standard_court_order_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class StandardCourtOrderPolicy < ApplicationPolicy
def create?
is_admin_same_org?
end

def new?
is_admin_same_org?
end

def update?
is_admin_same_org?
end

def edit?
is_admin_same_org?
end

def destroy?
is_admin_same_org?
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Deployment
class CreateDefaultStandardCourtOrdersService
DEFAULT_STANDARD_COURT_ORDERS = [
"Birth certificate for the Respondent’s",
"Domestic Violence Education/Group",
"Educational monitoring for the Respondent",
"Educational or Vocational referrals",
"Family therapy",
"Housing support for the [parent]",
"Independent living skills classes or workshops",
"Individual therapy for the [parent]",
"Individual therapy for the Respondent",
"Learners’ permit for the Respondent, drivers’ education and driving hours when needed",
"No contact with (mother, father, other guardian)",
"Parenting Classes (mother, father, other guardian)",
"Psychiatric Evaluation and follow all recommendations (child, mother, father, other guardian)",
"Substance abuse assessment for the [parent]",
"Substance Abuse Evaluation and follow all recommendations (child, mother, father, other guardian)",
"Substance Abuse Treatment (child, mother, father, other guardian)",
"Supervised visits",
"Supervised visits at DSS",
"Therapy (child, mother, father, other guardian)",
"Tutor for the Respondent",
"Urinalysis (child, mother, father, other guardian)",
"Virtual Visits",
"Visitation assistance for the Respondent to see [family]"
].freeze

def create_defaults
CasaOrg.all.each do |casa_org|
DEFAULT_STANDARD_COURT_ORDERS.each do |order|
StandardCourtOrder.create(value: order, casa_org: casa_org)
end
end
end
end
end
57 changes: 57 additions & 0 deletions app/views/casa_org/_standard_court_orders.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<div class="row">
<div class="col-lg-12">
<div class="card-style mb-30">
<div class="row align-items-center">
<div class="col-md-6">
<h3>Standard Court Orders</h3>
</div>
<div class="col-md-6">
<div class="breadcrumb-wrapper">
<span class="ml-5">
<%= link_to new_standard_court_order_path, class: "btn-sm main-btn primary-btn btn-hover" do %>
<i class="lni lni-plus mr-10"></i>
New Standard Court Order
<% end %>
</span>
</div>
</div>
</div>
<div class="table-wrapper table-responsive">
<table class="table striped-table" id="standard-court-orders">
<thead>
<tr>
<th class="min-width">Standard Court Order</th>
<th class="min-width">Actions</th>
</tr>
</thead>
<tbody>
<% @standard_court_orders&.each do |standard_court_order| %>
<% id = "standard_court_order-#{standard_court_order.id}" %>
<tr>
<td scope="row" class="min-width">
<%= standard_court_order.value %>
</td>
<td class="max-width">
<%= render(DropdownMenuComponent.new(menu_title: "Actions Menu", hide_label: true)) do %>
<li><%= link_to "Edit", edit_standard_court_order_path(standard_court_order), class: "dropdown-item" %></li>
<li><%= render(Modal::OpenLinkComponent.new(text: "Delete", target: id, klass: "dropdown-item")) %></li>
<% end %>
</td>
</tr>
<%= render(Modal::GroupComponent.new(id: id)) do |component| %>
<% component.with_header(text: "Delete Standard Court Order?", id: id) %>
<% component.with_footer do %>
<%= link_to standard_court_order_path(standard_court_order), method: :delete,
class: "btn-sm main-btn danger-btn btn-hover ms-auto" do %>
<i class="lni lni-trash-can mr-10"></i>
Delete Standard Court Order
<% end %>
<% end %>
<% end %>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
</div>
14 changes: 14 additions & 0 deletions app/views/casa_org/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,17 @@
<div class="tables-wrapper">
<%= render "contact_topics" %>
</div>
<div class="title-wrapper pt-30">
<div class="row align-items-center">
<div class="col-md-6">
<div class="title mb-30">
<h2>
Manage Standard Court Orders
</h2>
</div>
</div>
</div>
</div>
<div class="tables-wrapper">
<%= render "standard_court_orders" %>
</div>
2 changes: 1 addition & 1 deletion app/views/shared/_court_order_list.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<%= label_tag :selectedCourtOrder, "Court Order Type" %>
<div class="select-position">
<%= select_tag :selectedCourtOrder,
options_for_select(CaseCourtOrder.court_order_options),
options_for_select(current_organization.standard_court_orders.map(&:value)),
{ include_blank: "Create custom court order", data: {court_order_form_target: "selectedCourtOrder"} }
%>
</div>
Expand Down
31 changes: 31 additions & 0 deletions app/views/standard_court_orders/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div class="title-wrapper pt-30">
<div class="row align-items-center">
<div class="col-md-6">
<div class="title mb-30">
<h1>
<%= title %>
</h1>
</div>
</div>
</div>
</div><!-- ==== end title ==== -->

<!-- ========== card start ========== -->
<div class="card-style mb-30">
<%= form_with(model: standard_court_order, local: true) do |form| %>
<%= form.hidden_field :casa_org_id %>
<div class="alert-box danger-alert">
<%= render "/shared/error_messages", resource: standard_court_order %>
</div>
<div class="input-style-1">
<%= form.label :value, "Standard Court Order" %>
<%= form.text_field :value, class: "form-control", required: true %>
</div>
<div class="actions mb-10">
<%= button_tag(type: "submit", class: "btn-sm main-btn primary-btn btn-hover") do %>
<i class="lni lni-checkmark-circle mr-5"></i> Submit
<% end %>
</div>
<% end %>
</div>
<!-- card end -->
1 change: 1 addition & 0 deletions app/views/standard_court_orders/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render partial: "form", locals: {title: "Standard Court Order", standard_court_order: @standard_court_order} %>
1 change: 1 addition & 0 deletions app/views/standard_court_orders/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render partial: "form", locals: {title: "New Standard Court Order", standard_court_order: @standard_court_order} %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@
delete "soft_delete", on: :member
end

resources :standard_court_orders, except: %i[index show]

resources :followup_reports, only: :index
resources :placement_reports, only: :index
resources :banners, except: %i[show] do
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20240619005250_create_standard_court_orders.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateStandardCourtOrders < ActiveRecord::Migration[7.1]
def change
create_table :standard_court_orders do |t|
t.string :value
t.references :casa_org, null: false, foreign_key: true

t.timestamps
end

add_index :standard_court_orders, [:casa_org_id, :value], unique: true
end
end
10 changes: 10 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,15 @@
t.datetime "updated_at", null: false
end

create_table "standard_court_orders", force: :cascade do |t|
t.string "value"
t.bigint "casa_org_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["casa_org_id", "value"], name: "index_standard_court_orders_on_casa_org_id_and_value", unique: true
t.index ["casa_org_id"], name: "index_standard_court_orders_on_casa_org_id"
end

create_table "supervisor_volunteers", force: :cascade do |t|
t.bigint "supervisor_id", null: false
t.bigint "volunteer_id", null: false
Expand Down Expand Up @@ -739,6 +748,7 @@
add_foreign_key "preference_sets", "users"
add_foreign_key "sent_emails", "casa_orgs"
add_foreign_key "sent_emails", "users"
add_foreign_key "standard_court_orders", "casa_orgs"
add_foreign_key "supervisor_volunteers", "users", column: "supervisor_id"
add_foreign_key "supervisor_volunteers", "users", column: "volunteer_id"
add_foreign_key "user_reminder_times", "users"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace :after_party do
desc "Deployment task: Create default standard court orders for every CASA org"
task create_default_standard_court_orders: :environment do
puts "Running deploy task 'create_default_standard_court_orders'"

# Put your task implementation HERE.
Deployment::CreateDefaultStandardCourtOrdersService.new.create_defaults

# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end
Loading
Loading