Skip to content

Commit

Permalink
Merge pull request #689 from sparc-request/sj-fixing_disabled_message
Browse files Browse the repository at this point in the history
Sj fixing disabled message [#131171377]
  • Loading branch information
Stuart-Johnson committed Sep 28, 2016
2 parents 0a5393e + 42049d5 commit 97e24eb
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 30 deletions.
14 changes: 2 additions & 12 deletions app/helpers/catalog_manager/catalog_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,8 @@ def display_organization_tree(organization)
end

def disabled_parent organization
if organization.parent.is_available
organization.name
else
disabled_parent(organization.parent)
end
end

def disabled_service_parent service
if service.organization.is_available
service.name
else
disabled_parent(service.organization)
if (orgs = organization.parents.insert(0, organization).select{|org| !org.is_available}).any?
I18n.t('organization_form.disabled_at', disabled_parent: orgs.last.name)
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions app/views/catalog_manager/services/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@
%tr
%th= f.label :one_time_fee, t(:organization_form)[:one_time_fee]
%td= f.check_box :one_time_fee, :class => "one_time_fee", :'data-pricing_map_ids' => pricing_map_ids(@service), :disabled => (@service.line_items_count > 0)

%tr
%th= f.label :disabled, t(:organization_form)[:disabled]
%td
= f.check_box :is_available, {:checked => !@service.is_available, disabled: !@service.organization.is_available }, false, true
- if !@service.organization.is_available
%span
= disabled_parent(@service.organization)

%tr
%th
= t(:additional_details)[:add]
Expand Down
8 changes: 4 additions & 4 deletions app/views/catalog_manager/shared/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@
%tr
%th= t(:organization_form)[:disabled]
%td
= f.check_box :is_available, {checked: (@organization.is_available.nil? ? false : !@organization.is_available), disabled: @organization.parent.nil? ? false : !@organization.parent.is_available }, false, true
%span
- unless (@organization.type == 'Institution') || @organization.parent.is_available
= I18n.t('organization_form.disabled_at', disabled_parent: disabled_parent(@organization))
= f.check_box :is_available, {checked: !@organization.is_available, disabled: @organization.parent ? !@organization.parent.is_available : false }, false, true
- if @organization.parent && !@organization.parent.is_available
%span
= disabled_parent(@organization)

- unless @organization.type == 'Institution'
%tr
Expand Down
27 changes: 27 additions & 0 deletions db/migrate/20160928140834_disable_services_under_disabled_orgs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright © 2011-2016 MUSC Foundation for Research Development~
# All rights reserved.~

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:~

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.~

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following~
# disclaimer in the documentation and/or other materials provided with the distribution.~

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products~
# derived from this software without specific prior written permission.~

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,~
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT~
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL~
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS~
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR~
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.~

class DisableServicesUnderDisabledOrgs < ActiveRecord::Migration
def change
Organization.where(is_available: false).each do |org|
org.services.where(is_available: true).update_all(is_available: false)
end
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160921130908) do
ActiveRecord::Schema.define(version: 20160928140834) do

create_table "admin_rates", force: :cascade do |t|
t.integer "line_item_id", limit: 4
Expand Down
14 changes: 1 addition & 13 deletions spec/helpers/catalog_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,7 @@
program = create(:program, name: 'Program', parent_id: provider.id, is_available: false)
core = create(:core, name: 'Core', parent_id: program.id, is_available: false)

expect(helper.disabled_parent(core)).to eq(provider.name)
end
end

context '#disabled_service_parent' do
it 'should return the name of the highest disabled organization in the tree' do
institution = create(:institution, name: 'Institution', is_available: true)
provider = create(:provider, name: 'Provider', parent_id: institution.id, is_available: false)
program = create(:program, name: 'Program', parent_id: provider.id, is_available: false)
core = create(:core, name: 'Core', parent_id: program.id, is_available: false)
service = create(:service, name: 'Service', organization_id: core.id, is_available: false)

expect(helper.disabled_service_parent(service)).to eq(provider.name)
expect(helper.disabled_parent(core)).to eq("Disabled at: #{provider.name}")
end
end
end

0 comments on commit 97e24eb

Please sign in to comment.