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 @@
+ <%= f.label _('Visibility'), class: 'control-label' %> +
+ <%= f.label(:visibility, + raw("#{check_box_tag('template_visibility', '0', (template.visibility == 'organisationally_visible'))} #{_('for internal %{org_name} use only') % {org_name: @template.org.name}}")) %> +
+
+ +
<%= label_tag(:status, _('Status'), class: "control-label") %>

<% 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? %> +

<%= _('Visibility') %>
+
<%= (template.visibility == 'organisationally_visible' ? _('for internal %{org_name} use only') % {org_name: @template.org.name} : _('available to the public') + (template_hash[:live].nil? ? ' (once published)' : '')) %>
+ <% end %>
<%= _('Created at') %>
<%= l template.created_at.to_date, formats: :short %>
<%= _('Last updated') %>
diff --git a/lib/tasks/bugfix.rake b/lib/tasks/bugfix.rake index 5fc6bf1..d31d86c 100644 --- a/lib/tasks/bugfix.rake +++ b/lib/tasks/bugfix.rake @@ -1,5 +1,10 @@ namespace :bugfix do + desc "Upgrade to 1.0" + task v1_0_0: :environment do + Rake::Task['bugfix:set_template_visibility'].execute + end + desc "Bug fixes for version v0.3.3" task v0_3_3: :environment do Rake::Task['bugfix:fix_question_formats'].execute @@ -46,4 +51,11 @@ end end + desc "Set all funder templates (and the default template) to 'public' visibility and all others to 'organisational'" + task set_template_visibility: :environment do + funders = Org.funders.pluck(:id) + Template.update_all visibility: Template.visibilities[:organisationally_visible] + Template.where(org_id: funders).update_all visibility: Template.visibilities[:publicly_visible] + Template.default.update visibility: Template.visibilities[:publicly_visible] + end end \ No newline at end of file