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

Expense option bug fix #4899

Merged
merged 6 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .allow_skipping_tests
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ controllers/placement_reports_controller.rb
controllers/reports_controller.rb
controllers/supervisor_volunteers_controller.rb
controllers/supervisors_controller.rb
controllers/system_settings_controller.rb
controllers/users/passwords_controller.rb
controllers/users/sessions_controller.rb
controllers/users_controller.rb
Expand Down
1 change: 1 addition & 0 deletions app/controllers/casa_org_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def casa_org_update_params
:logo,
:court_report_template,
:show_driving_reimbursement,
:additional_expenses_enabled,
:twilio_account_sid,
:twilio_phone_number,
:twilio_api_key_sid,
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/case_contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def update
@current_organization_groups = current_organization.contact_type_groups

if @case_contact.update_cleaning_contact_types(update_case_contact_params)
if additional_expense_params&.any? && FeatureFlagService.is_enabled?(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG)
if additional_expense_params&.any? && policy(:case_contact).additional_expenses_allowed?
update_or_create_additional_expense(additional_expense_params, @case_contact)
end
if @case_contact.valid?
Expand Down Expand Up @@ -156,7 +156,7 @@ def save_or_add_error(obj, case_contact)

def create_case_contact_for_every_selected_casa_case(selected_cases)
selected_cases.map do |casa_case|
if FeatureFlagService.is_enabled?(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG)
if policy(:case_contact).additional_expenses_allowed?
new_cc = casa_case.case_contacts.new(create_case_contact_params.except(:casa_case_attributes))
update_or_create_additional_expense(additional_expense_params, new_cc)
if new_cc.valid?
Expand Down
19 changes: 0 additions & 19 deletions app/controllers/system_settings_controller.rb

This file was deleted.

31 changes: 16 additions & 15 deletions app/models/casa_org.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,22 @@ def normalize_phone_number
#
# Table name: casa_orgs
#
# id :bigint not null, primary key
# address :string
# display_name :string
# footer_links :string default([]), is an Array
# name :string not null
# show_driving_reimbursement :boolean default(TRUE)
# show_fund_request :boolean default(FALSE)
# slug :string
# twilio_account_sid :string
# twilio_api_key_secret :string
# twilio_api_key_sid :string
# twilio_enabled :boolean default(FALSE)
# twilio_phone_number :string
# created_at :datetime not null
# updated_at :datetime not null
# id :bigint not null, primary key
# additional_expenses_enabled :boolean default(FALSE)
# address :string
# display_name :string
# footer_links :string default([]), is an Array
# name :string not null
# show_driving_reimbursement :boolean default(TRUE)
# show_fund_request :boolean default(FALSE)
# slug :string
# twilio_account_sid :string
# twilio_api_key_secret :string
# twilio_api_key_sid :string
# twilio_enabled :boolean default(FALSE)
# twilio_phone_number :string
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
Expand Down
1 change: 0 additions & 1 deletion app/policies/application_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,5 @@ def current_organization
end

alias_method :modify_organization?, :is_admin?
alias_method :edit_system_settings?, :is_admin?
alias_method :see_import_page?, :is_admin?
end
5 changes: 5 additions & 0 deletions app/policies/case_contact_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ def is_creator_or_supervisor_or_casa_admin?
is_creator? || admin_or_supervisor?
end

def additional_expenses_allowed?
FeatureFlagService.is_enabled?(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) &&
current_organization.additional_expenses_enabled
end

alias_method :index?, :admin_or_supervisor_or_volunteer?
alias_method :new?, :admin_or_supervisor_or_volunteer?
alias_method :show?, :is_creator_or_casa_admin?
Expand Down
4 changes: 4 additions & 0 deletions app/views/casa_org/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
<%= form.check_box :show_driving_reimbursement, class: 'form-check-input' %>
<%= form.label :show_driving_reimbursement, "Show driving reimbursement", class: 'form-check-label mb-2' %>
</div>
<div class="form-check checkbox-style mb-20">
<%= form.check_box :additional_expenses_enabled, class: 'form-check-input' %>
<%= form.label :additional_expenses_enabled, "Volunteers can add Other Expenses", class: 'form-check-label mb-2' %>
</div>
<div class="actions mb-10">
<%= button_tag(
type: "submit",
Expand Down
2 changes: 1 addition & 1 deletion app/views/case_contacts/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ readonly: true %>
</div>
<% end %>

<% if FeatureFlagService.is_enabled?(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG) %>
<% if Pundit.policy(current_user, case_contact).additional_expenses_allowed? %>
<div class="other-expenses">
<h5 class="mb-3"><%= form.label :additional_expense, "d. Other Expenses" %></h5>
<ol>
Expand Down
9 changes: 0 additions & 9 deletions app/views/layouts/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,6 @@
</li>
<% end %>

<% if policy(:application).edit_system_settings? %>
<li>
<%= link_to settings_path, class: "#{active_class(settings_path)}" do %>
<i class="lni lni-cog mr-10"></i>
System Settings
<% end %>
</li>
<% end %>

<% if policy(:application).see_mileage_rate? %>
<li>
<%= link_to mileage_rates_path, class: "#{active_class(mileage_rates_path)}" do %>
Expand Down
33 changes: 0 additions & 33 deletions app/views/system_settings/index.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
get :download_failed
end
end
resources :settings, only: %i[index create], controller: "system_settings"
resources :case_contact_reports, only: %i[index]
resources :mileage_reports, only: %i[index]
resources :mileage_rates, only: %i[index new create edit update]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAdditionalExpensesToCasaOrgs < ActiveRecord::Migration[7.0]
def change
add_column :casa_orgs, :additional_expenses_enabled, :boolean, default: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_06_15_155223) do
ActiveRecord::Schema[7.0].define(version: 2023_06_21_161252) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -141,6 +141,7 @@
t.string "twilio_api_key_sid"
t.string "twilio_api_key_secret"
t.boolean "twilio_enabled", default: false
t.boolean "additional_expenses_enabled", default: false
t.index ["slug"], name: "index_casa_orgs_on_slug", unique: true
end

Expand Down
14 changes: 0 additions & 14 deletions spec/policies/application_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,4 @@
end
end
end

permissions :edit_system_settings? do
it "does not allow volunters" do
is_expected.not_to permit(volunteer)
end

it "does not allow supervisors" do
is_expected.not_to permit(supervisor)
end

it "allow casa_admins for same org" do
is_expected.to permit(casa_admin)
end
end
end
5 changes: 4 additions & 1 deletion spec/requests/casa_org_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
{
name: "name", display_name: "display_name", address: "address",
twilio_account_sid: "articuno34", twilio_api_key_sid: "Aladdin",
twilio_api_key_secret: "open sesame", twilio_phone_number: "+12223334444"
twilio_api_key_secret: "open sesame", twilio_phone_number: "+12223334444",
show_driving_reimbursement: "1", additional_expenses_enabled: "1"
}
end

Expand All @@ -41,6 +42,8 @@
expect(casa_org.display_name).to eq "display_name"
expect(casa_org.address).to eq "address"
expect(casa_org.twilio_phone_number).to eq "+12223334444"
expect(casa_org.show_driving_reimbursement).to be true
expect(casa_org.additional_expenses_enabled).to be true
end

describe "on logo update" do
Expand Down
1 change: 1 addition & 0 deletions spec/requests/case_contacts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@

before do
FeatureFlagService.enable!(FeatureFlagService::SHOW_ADDITIONAL_EXPENSES_FLAG)
organization.additional_expenses_enabled = true
end

it "creates an additional expense with correct values", :aggregate_failures do
Expand Down
46 changes: 0 additions & 46 deletions spec/requests/system_settings_spec.rb

This file was deleted.

4 changes: 4 additions & 0 deletions spec/system/casa_org/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@
expect(page).to have_text("Twilio Phone Number")
end

it "has option to enable additional expenses" do
expect(page).to have_text("Volunteers can add Other Expenses")
end

it "requires name text field" do
expect(page).to have_selector("input[required=required]", id: "casa_org_name")
end
Expand Down
Loading
Loading