diff --git a/app/controllers/public_pages_controller.rb b/app/controllers/public_pages_controller.rb index bf33360..cdf5041 100644 --- a/app/controllers/public_pages_controller.rb +++ b/app/controllers/public_pages_controller.rb @@ -4,7 +4,7 @@ # GET template_index # ----------------------------------------------------- def template_index - template_ids = Template.where(org_id: Org.funders.pluck(:id)).valid.pluck(:dmptemplate_id).uniq << Template.where(is_default: true, published: true).pluck(:dmptemplate_id) + template_ids = Template.where(org_id: Org.funders.pluck(:id), visibility: Template.visibilities[:publicly_visible]).valid.pluck(:dmptemplate_id).uniq << Template.where(is_default: true, published: true).pluck(:dmptemplate_id) @templates = [] template_ids.flatten.each do |tid| t = Template.live(tid) diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 03c3bc2..0fdb404 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -274,6 +274,14 @@ @template.description = params["template-desc"] @template.links = JSON.parse(params["template-links"]) if params["template-links"].present? + + # If the visibility checkbox is not checked and the user's org is a funder set the visibility to public + # otherwise default it to organisationally_visible + if current_user.org.funder? && params[:template_visibility].nil? + @template.visibility = Template.visibilities[:publicly_visible] + else + @template.visibility = Template.visibilities[:organisationally_visible] + end if @template.update_attributes(params[:template]) flash[:notice] = success_message(_('template'), _('saved')) diff --git a/app/models/template.rb b/app/models/template.rb index c191858..65a10ea 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -27,6 +27,11 @@ :is_default, :guidance_group_ids, :org, :plans, :phases, :dmptemplate_id, :migrated, :version, :visibility, :published, :as => [:default, :admin] + # A standard template should be organisationally visible. Funder templates that are + # meant for external use will be publicly visible. This allows a funder to create 'funder' as + # well as organisational templates. The default template should also always be publicly_visible + enum visibility: [:organisationally_visible, :publicly_visible] + # defines the export setting for a template object has_settings :export, class_name: 'Settings::Template' do |s| s.key :export, defaults: Settings::Template::DEFAULT_SETTINGS @@ -42,6 +47,8 @@ Template.where(templates: { is_default: is_default }).valid().published() } + scope :publicly_visible, -> { where(:visibility => Template.visibilities[:publicly_visible]).order(:title => :asc) } + # Retrieves the list of all dmptemplate_ids (template versioning families) for the specified Org def self.dmptemplate_ids Template.all.valid.distinct.pluck(:dmptemplate_id) @@ -163,6 +170,7 @@ self.visibility = 1 self.is_default = false self.version = 0 if self.version.nil? + self.visibility = Template.visibilities[:organisationally_visible] if self.visibility.nil? # Generate a unique identifier for the dmptemplate_id if necessary if self.dmptemplate_id.nil? diff --git a/app/views/templates/_edit_template.html.erb b/app/views/templates/_edit_template.html.erb index dca8915..70907af 100644 --- a/app/views/templates/_edit_template.html.erb +++ b/app/views/templates/_edit_template.html.erb @@ -13,6 +13,14 @@
<% if template_hash[:live].nil? %> diff --git a/app/views/templates/_show_template.html.erb b/app/views/templates/_show_template.html.erb index 50169f4..f61514b 100644 --- a/app/views/templates/_show_template.html.erb +++ b/app/views/templates/_show_template.html.erb @@ -18,6 +18,10 @@ <%= _('Published') %> <% end %> + <% if template.org.funder? %> +