diff --git a/app/controllers/org_admin/templates_controller.rb b/app/controllers/org_admin/templates_controller.rb index acb5121..15993e0 100644 --- a/app/controllers/org_admin/templates_controller.rb +++ b/app/controllers/org_admin/templates_controller.rb @@ -376,7 +376,7 @@ # Load the funder's template(s) templates = Template.valid.publicly_visible.where(published: true, org_id: funder_id).to_a - if org_id.present? + unless org_id.blank? # Swap out any organisational cusotmizations of a funder template templates.each do |tmplt| customization = Template.valid.find_by(published: true, org_id: org_id, customization_of: tmplt.dmptemplate_id) @@ -386,20 +386,15 @@ end end end + else + # If no funder was selected retrieve the Org's templates + templates << Template.organisationally_visible.valid.where(published: true, org_id: org_id, customization_of: nil).to_a end - # Load the org's template(s) - if org_id.present? - # If the Research Org is not also a Funder OR the selected Research Org - # matches the selected Funder (Use case where Org is both a Funder and Org) - if !Org.find(org_id).funder? || org_id == funder_id - templates << Template.organisationally_visible.valid.where(published: true, org_id: org_id, customization_of: nil).to_a - end - templates = templates.flatten.uniq - end + templates = templates.flatten.uniq end - # If no templates were available use the generic templates + # If no templates were available use the default template if templates.empty? templates << Template.where(is_default: true, published: true).first end diff --git a/app/models/template.rb b/app/models/template.rb index d84606a..0da0b23 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -263,7 +263,7 @@ self.published = false self.migrated = false self.dirty = false - self.visibility = 1 + self.visibility = 0 # Organisationally visible by default self.is_default = false self.version = 0 if self.version.nil? self.visibility = Template.visibilities[:organisationally_visible] if self.visibility.nil? diff --git a/test/integration/template_selection_test.rb b/test/integration/template_selection_test.rb index bfc98b2..7f3bfb8 100644 --- a/test/integration/template_selection_test.rb +++ b/test/integration/template_selection_test.rb @@ -118,7 +118,7 @@ assert_response :success json = JSON.parse(@response.body) - assert_equal 2, json['templates'].size + assert_equal 1, json['templates'].size assert_equal @funder_template.id, json['templates'][0]['id'] end @@ -136,8 +136,8 @@ get "#{org_admin_template_options_path}?plan[org_id]=#{@org.id}&plan[funder_id]=#{@funder.id}" assert_response :success json = JSON.parse(@response.body) - - assert_equal 2, json['templates'].size + + assert_equal 1, json['templates'].size assert_equal customization.id, json['templates'][0]['id'] end @@ -155,7 +155,7 @@ assert_response :success json = JSON.parse(@response.body) - assert_equal 3, json['templates'].size + assert_equal 2, json['templates'].size assert_equal @funder_template.id, json['templates'][0]['id'] assert_equal funder_template2.id, json['templates'][1]['id'] end