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

Sj jtm available statuses fixes #1139

Merged
merged 10 commits into from
Oct 5, 2017
5 changes: 5 additions & 0 deletions app/assets/javascripts/catalog_manager/catalog.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,11 @@ $ ->
$('#available_statuses_wrapper').toggle()
)

$(document).on('change', 'input[id*="_use_default_statuses"]', ->
$('#all_statuses').toggle()
$('#default_statuses').toggle()
)

$(document).on('change', 'input[id*="_tag_list_clinical_work_fulfillment"]', ->
$('#cwf_wrapper').toggle()
$('#cwf_wrapper input.cwf_clear').val('')
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/catalog_manager/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def organization_params(type)
:ack_language,
:process_ssrs,
:is_available,
:use_default_statuses,
{ tag_list: [] },
subsidy_map_attributes: [:organization_id,
:max_dollar_cap,
Expand All @@ -79,11 +80,13 @@ def organization_params(type)
:unfunded_rate_type],
submission_emails_attributes: [:organization_id, :email],
available_statuses_attributes: [:organization_id,
:id,
:status,
:new,
:position,
:_destroy],
editable_statuses_attributes: [:organization_id,
:id,
:status,
:new,
:_destroy])
Expand Down
3 changes: 1 addition & 2 deletions app/lib/organization_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ def update_organization
else
true
end
@organization.available_statuses.destroy_all
@organization.editable_statuses.destroy_all

if services_updated && @organization.update_attributes(@attributes)
@organization.update_ssr_org_name if name_change
@organization.update_descendants_availability(@attributes[:is_available])
Expand Down
22 changes: 9 additions & 13 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class Organization < ApplicationRecord
audited
acts_as_taggable

after_create :build_default_statuses

belongs_to :parent, :class_name => 'Organization'
has_many :submission_emails, :dependent => :destroy
has_many :associated_surveys, as: :surveyable, dependent: :destroy
Expand Down Expand Up @@ -118,7 +116,7 @@ def submission_emails_lookup
end

def has_editable_status?(status)
self.editable_statuses.where(status: status).any?
self.get_editable_statuses[status].present?
end

# Returns the immediate children of this organization (shallow search)
Expand Down Expand Up @@ -359,7 +357,10 @@ def setup_available_statuses
def get_available_statuses
tmp_available_statuses = self.available_statuses.reject{|status| status.new_record?}
statuses = []
if tmp_available_statuses.empty? || tmp_available_statuses.collect(&:status) == DEFAULT_STATUSES

if self.use_default_statuses
statuses = AVAILABLE_STATUSES.select{|k,v| DEFAULT_STATUSES.include? k}
elsif tmp_available_statuses.empty?
self.parents.each do |parent|
if !parent.available_statuses.empty?
statuses = AVAILABLE_STATUSES.select{|k,v| parent.available_statuses.map(&:status).include? k}
Expand All @@ -369,9 +370,6 @@ def get_available_statuses
else
statuses = AVAILABLE_STATUSES.select{|k,v| tmp_available_statuses.map(&:status).include? k}
end
if statuses.empty?
statuses = AVAILABLE_STATUSES.select{|k,v| DEFAULT_STATUSES.include? k}
end
statuses
end

Expand All @@ -385,6 +383,10 @@ def setup_editable_statuses
end
end

def get_editable_statuses
self.use_default_statuses ? AVAILABLE_STATUSES.select{|k,v| DEFAULT_STATUSES.include? k} : AVAILABLE_STATUSES.select{|k,v| self.editable_statuses.pluck(:status).include? k}
end

def has_tag? tag
if self.tag_list.include? tag
return true
Expand Down Expand Up @@ -412,10 +414,4 @@ def self.authorized_child_organizations(org_ids)
orgs | authorized_child_organizations(orgs.pluck(:id))
end
end

def build_default_statuses
DEFAULT_STATUSES.each do |status|
AvailableStatus.find_or_create_by(organization_id: self.id, status: status)
end
end
end
59 changes: 20 additions & 39 deletions app/views/catalog_manager/shared/_available_statuses.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,26 @@
-# 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.

%fieldset#available_statuses_fieldset.parent
.legend= t(:organization_form)[:status_legend]
%fieldset.single_fieldset
%table
#all_statuses{style: @organization.use_default_statuses ? "display: none;" : "display: block;"}
%table
%tr
%td
%legend= t(:organization_form)[:available_statuses]
%table
= f.fields_for :available_statuses, @organization.available_statuses.sort{|x, y| AVAILABLE_STATUSES[x.status] <=> AVAILABLE_STATUSES[y.status]} do |as|
%tr
%th= as.label :status, "#{AvailableStatus::TYPES[as.object.status].gsub('CTRC', 'Nexus')}:"
%td= as.check_box "_destroy", {class: 'available-status', checked: (as.object.new_record? ? @organization.use_default_statuses && DEFAULT_STATUSES.include?(as.object.status) : true), disabled: ["Draft", "Get a Cost Estimate", "Submitted"].include?(AVAILABLE_STATUSES[as.object.status]), data: { status: as.object.status }}, false, true
= as.hidden_field :status, :value => as.object.status

- if current_user.is_overlord?
%tr
%td
%legend= t(:organization_form)[:available_statuses]
%table
= f.fields_for :available_statuses, @organization.available_statuses.sort{|x, y| AVAILABLE_STATUSES[x.status] <=> AVAILABLE_STATUSES[y.status]} do |as|
%tr
%th= as.label :status, "#{AvailableStatus::TYPES[as.object.status].gsub('CTRC', 'Nexus')}:"
%td= as.check_box "_destroy", {class: 'available-status', checked: !as.object.new_record?, disabled: ["Draft", "Get a Cost Estimate", "Submitted"].include?(AVAILABLE_STATUSES[as.object.status]), data: { status: as.object.status }}, false, true
= as.hidden_field :status, :value => as.object.status
%td
%legend= t(:organization_form)[:selected_statuses]
%br
%legend= t(:organization_form)[:editable_statuses]
%table
%tr
- @organization.available_statuses.sort{|x, y| AVAILABLE_STATUSES[x.status] <=> AVAILABLE_STATUSES[y.status]}.each do |as|
-if !as.id.nil?
%tr
%th= AVAILABLE_STATUSES[as.status]

- if current_user.is_overlord?
%tr
%td
%br
%legend= t(:organization_form)[:editable_statuses]
%table
= f.fields_for :editable_statuses, @organization.editable_statuses.sort{|x, y| AVAILABLE_STATUSES[x.status] <=> AVAILABLE_STATUSES[y.status]} do |es|
%tr{ class: "#{es.object.status}-dependent", style: @organization.available_statuses.select{ |as| !as.new_record? }.map(&:status).include?(es.object.status) ? "display:table-row;" : "display:none;" }
%th= es.label :status, "#{AVAILABLE_STATUSES[es.object.status].gsub('CTRC', 'Nexus')}:"
%td= es.check_box "_destroy", {:checked => !es.object.new_record?}, false, true
= es.hidden_field :status, :value => es.object.status
%td
%br
%legend= t(:organization_form)[:selected_statuses]
%table
%tr
- @organization.editable_statuses.sort{|x, y| AVAILABLE_STATUSES[x.status] <=> AVAILABLE_STATUSES[y.status]}.each do |es|
- unless es.id.nil?
%tr{ class: "#{es.status}-dependent", style: @organization.available_statuses.select{ |as| !as.new_record? }.map(&:status).include?(es.status) ? "display:table-row;" : "display:none;" }
%th= AVAILABLE_STATUSES[es.status]
= f.fields_for :editable_statuses, @organization.editable_statuses.sort{|x, y| AVAILABLE_STATUSES[x.status] <=> AVAILABLE_STATUSES[y.status]} do |es|
%tr{ class: "#{es.object.status}-dependent", style: @organization.available_statuses.select{|as| as.new_record? ? @organization.use_default_statuses && DEFAULT_STATUSES.include?(as.status) : true}.map(&:status).include?(es.object.status) ? "display:table-row;" : "display:none;" }
%th= es.label :status, "#{AVAILABLE_STATUSES[es.object.status].gsub('CTRC', 'Nexus')}:"
%td= es.check_box "_destroy", {:checked => !es.object.new_record?}, false, true
= es.hidden_field :status, :value => es.object.status
2 changes: 1 addition & 1 deletion app/views/catalog_manager/shared/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
%span= f.check_box :tag_list, { multiple: true }, tag.name, nil

#available_statuses_wrapper{style: @organization.process_ssrs? ? "display: block;" : "display: none;"}
= render partial: 'catalog_manager/shared/available_statuses', locals: {f: f}
= render partial: 'catalog_manager/shared/status_options_box', locals: {f: f}

%fieldset#user_rights.parent
.legend= t(:organization_form)[:user_rights]
Expand Down
47 changes: 47 additions & 0 deletions app/views/catalog_manager/shared/_status_options_box.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
-# Copyright © 2011-2017 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.

%fieldset#available_statuses_fieldset.parent
.legend= t(:organization_form)[:status_legend]
%fieldset.single_fieldset
%label
= t(:organization_form)[:use_default_statuses]
= f.check_box :use_default_statuses
#default_statuses{style: @organization.use_default_statuses? ? "display: block;" : "display: none;"}
%table
%tr
%td
%legend= t(:organization_form)[:default_available_statuses]
%table
- DEFAULT_STATUSES.sort.each do |status|
%tr
%th= f.label :status, "#{AvailableStatus::TYPES[status].titleize}"
- if current_user.is_overlord?
%tr
%td
%br
%legend= t(:organization_form)[:default_editable_statuses]
%table
- DEFAULT_STATUSES.sort.each do |status|
%tr
%th= f.label :status, "#{AvailableStatus::TYPES[status].titleize}"
= render partial: 'catalog_manager/shared/available_statuses', locals: {f: f}


2 changes: 1 addition & 1 deletion app/views/catalog_manager/shared/_update.js.haml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
- my_class = @entity.class.to_s.downcase
- url = eval("catalog_manager_#{my_class}_path")
- @f = nil; form_for(@entity, :url => url) {|f| @f = f}
$('#available_statuses_fieldset').replaceWith("#{escape_javascript(render :partial => 'catalog_manager/shared/available_statuses', :locals => {:f => @f})}")
$('#available_statuses_wrapper').html("#{escape_javascript(render :partial => 'catalog_manager/shared/status_options_box', :locals => {:f => @f})}")

-# re-render pricing_setups if the entity is a Provider or Program
- if @entity.instance_of? Provider or @entity.instance_of? Program
Expand Down
4 changes: 3 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,8 @@ en:
cpt_code: "CPT Code"
css_class: "Color"
ctrc_label: "Administrative Approvals"
default_statuses: "Default Statuses:"
default_available_statuses: "Default Statuses:"
default_editable_statuses: "Default Editable Statuses:"
description: "Description"
disabled: "Display in SPARC"
disabled_all_services: "Disable All Services"
Expand Down Expand Up @@ -907,6 +908,7 @@ en:
super_users: "Super Users"
tag_list: "Tags"
user_rights: "User Rights"
use_default_statuses: "Use Default Statuses"

pricing_map_form:
clinical_quantity_type: "Clinical Quantity Type (hours, each, slides, etc.)"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class AddUseDefaultStatusesColumnToOrgs < ActiveRecord::Migration[5.1]
def change
add_column :organizations, :use_default_statuses, :boolean, default: true
Organization.all.each do |org|
org.update(use_default_statuses: false) if org.available_statuses.any? || org.parent.available_statuses.any?
end
end
end
4 changes: 2 additions & 2 deletions spec/controllers/search/get_services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@

it 'should not return services from a locked organization' do
sr = create(:service_request_without_validations)
org = create(:organization)
org = create(:organization, use_default_statuses: false)
inst = create(:institution)
prvdr = create(:provider, parent: inst)
org2 = create(:program, parent: prvdr)
org2 = create(:program, parent: prvdr, use_default_statuses: false)
ssr = create(:sub_service_request_without_validations, service_request: sr, organization: org, status: 'on_hold')
s1 = create(:service, organization: org, name: 'Service 123')
s2 = create(:service, organization: org2, name: 'Service 321')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
context 'editing a service request that has been previously submitted' do
context 'ssr status is set to a locked status' do
before :each do
@org = create(:organization)
@org = create(:organization, use_default_statuses: false)
service = create(:service, organization: @org, one_time_fee: true)
protocol = create(:protocol_federally_funded, primary_pi: logged_in_user, type: 'Study')
@sr = create(:service_request_without_validations, protocol: protocol, original_submitted_date: Time.now.yesterday)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@

context 'ssr is locked' do
it 'should not update status' do
org = create(:organization, process_ssrs: true)
org = create(:organization, process_ssrs: true, use_default_statuses: false)
service = create(:service, organization: org)
protocol = create(:protocol_without_validations, primary_pi: logged_in_user)
sr = create(:service_request_without_validations, protocol: protocol)
Expand Down
5 changes: 5 additions & 0 deletions spec/factories/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
ack_language { Faker::Lorem.paragraph(4) }
process_ssrs { false }
is_available { true }
use_default_statuses { true }

trait :ctrc do
after(:create) do |organization, evaluator|
Expand Down Expand Up @@ -110,6 +111,7 @@
ack_language { Faker::Lorem.paragraph(4) }
process_ssrs { false }
is_available { true }
use_default_statuses { true }

trait :disabled do
is_available false
Expand Down Expand Up @@ -142,6 +144,7 @@
ack_language { Faker::Lorem.paragraph(4) }
process_ssrs { false }
is_available { true }
use_default_statuses { true }

trait :process_ssrs do
process_ssrs true
Expand Down Expand Up @@ -193,6 +196,7 @@
ack_language { Faker::Lorem.paragraph(4) }
process_ssrs { false }
is_available { true }
use_default_statuses { true }

trait :process_ssrs do
process_ssrs true
Expand Down Expand Up @@ -261,6 +265,7 @@
ack_language { Faker::Lorem.paragraph(4) }
process_ssrs { false }
is_available { true }
use_default_statuses { true }

trait :process_ssrs do
process_ssrs true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def go_to_show_protocol(protocol_id)
context 'for a locked SSR' do
let!(:protocol) { create(:unarchived_study_without_validations, primary_pi: jug2) }
let!(:service_request) { create(:service_request_without_validations, protocol: protocol, status: 'draft') }
let!(:organization) { create(:organization,type: 'Institution', name: 'Megacorp', admin: bob, service_provider: bob) }
let!(:organization) { create(:organization,type: 'Institution', name: 'Megacorp', admin: bob, service_provider: bob, use_default_statuses: false) }

scenario 'and sees View but not Edit' do
organization.editable_statuses.where(status: 'on_hold').destroy_all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
fake_login_for_each_test

before :each do
org = create(:organization)
org2 = create(:organization)
org = create(:organization, use_default_statuses: false)
org2 = create(:organization, use_default_statuses: false)
create(:pricing_setup, organization: org)
create(:pricing_setup, organization: org2)
service = create(:service, organization: org, one_time_fee: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
fake_login_for_each_test

before :each do
org = create(:organization)
org = create(:organization, use_default_statuses: false)
create(:pricing_setup, organization: org)
service = create(:service, organization: org, one_time_fee: false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
fake_login_for_each_test

before :each do
org = create(:organization)
org = create(:organization, use_default_statuses: false)
create(:pricing_setup, organization: org)
pppv = create(:service, organization: org, one_time_fee: false)
otf = create(:service, organization: org, one_time_fee: true)
Expand Down
8 changes: 4 additions & 4 deletions spec/models/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,10 @@
end

it 'should return false otherwise' do
organization1 = Organization.create
organization2 = Organization.create
organization2.editable_statuses.destroy_all
expect(organization2.has_editable_status?('draft')).to eq(false)
org1 = create(:organization)
org2 = create(:organization, use_default_statuses: false)
org2.editable_statuses.destroy_all
expect(org2.has_editable_status?('draft')).to eq(false)
end
end
end
Expand Down