Skip to content

Commit 8510417

Browse files
author
John Pinto
committed
Added feature "Org admins can show/hide the ethical_issues field on plans" (#3555).
Changes: (1) Added a property Rails.configuration.x.madmp.enable_ethical_issues_per_template to configuration which works as follows: If Rails.configuration.x.madmp.enable_ethical_issues is true, this flag hide_ethical_issues_question_per_template comes into play. It will determine if the ethical_issues question is hidden/shown based on the template selected for the plan. If the template has the hide_ethical_issues attribute set to true, then the question will be hidden. If the template has the hide_ethical_issues is set to false, then the question will be shown. (2) Added to Template model attribute :hide_ethical_issues_question, :boolean, default: false with migration. (3) Added a safe param :hide_ethical_issues_question to the org admin Template controller. (4) Updated the app/views/org_admin/templates/_form.html.erb to display a checkbox for "Hide question about ethical issues". This checkbox will only appear if Rails.configuration.x.madmp.enable_ethical_issues and Rails.configuration.x.madmp.enable_ethical_issues_per_template are both set to true in config. (5) Updated the conitional for display of the ethical issues question in the Project details page as follows: <% if Rails.configuration.x.madmp.enable_ethical_issues && (!Rails.configuration.x.madmp.enable_hide_ethical_issues_per_template || (Rails.configuration.x.madmp.enable_hide_ethical_issues_per_template && plan.template.present? && plan.template.hide_ethical_issues_question.present? && !plan.template.hide_ethical_issues_question)) %>
1 parent f7bcd33 commit 8510417

7 files changed

Lines changed: 341 additions & 3 deletions

File tree

app/controllers/org_admin/templates_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def template_params
380380
# }
381381
# While this is working as-is we should consider folding these into
382382
# the template: :links context.
383-
params.require(:template).permit(:title, :description, :visibility, :links)
383+
params.require(:template).permit(:title, :description, :visibility, :links, :hide_ethical_issues_question)
384384
end
385385

386386
def parse_visibility(args, org)

app/models/template.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# updated_at :datetime
2020
# family_id :integer
2121
# org_id :integer
22+
# hide_ethical_issues_question :boolean
2223
#
2324
# Indexes
2425
#
@@ -62,6 +63,7 @@ class Template < ApplicationRecord
6263
attribute :customization_of, :integer, default: nil
6364
attribute :family_id, :integer, default: -> { Template.new_family_id }
6465
attribute :visibility, default: Template.visibilities[:organisationally_visible]
66+
attribute :hide_ethical_issues_question, :boolean, default: false
6567

6668
# ================
6769
# = Associations =

app/views/org_admin/templates/_form.html.erb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<% description_tooltip = _('Enter a description that helps you to differentiate between templates e.g. if you have ones for different audiences') %>
2+
<% hide_ethics_tooltip = _('If checked, the question about ethical issues will be hidden when creating a plan using this template. This setting only applies if the global setting to enable ethical issues is also enabled.') %>
23

34
<div class="form-control mb-3 col-xs-8">
45
<%= f.label(:title, _('Title'), class: "form-label") %>
@@ -11,6 +12,22 @@
1112
<%= f.text_area(:description, class: "template", spellcheck: true) %>
1213
</div>
1314

15+
<% if Rails.configuration.x.madmp.enable_ethical_issues && Rails.configuration.x.madmp.enable_ethical_issues_per_template %>
16+
<!-- Show the ethical issues question if the global flag is enabled and either the per-template flag is disabled
17+
or if the per-template flag is enabled and the current template does not have the hide_ethical_issues_question set to true -->
18+
<div class="form-control mb-3">
19+
<div class="col-lg-8">
20+
<div class="form-check">
21+
<%= f.label(:hide_ethical_issues_question, class: 'form-label', title: hide_ethics_tooltip) do %>
22+
<%= f.check_box(:hide_ethical_issues_question, {},
23+
true, false) %>
24+
<%= _('Hide question about ethical issues') %>
25+
<% end %>
26+
</div>
27+
</div>
28+
</div>
29+
<% end %>
30+
1431
<% if current_user.org.funder? && !current_user.org.funder_only? %>
1532
<!-- If the Org is a funder and another org type then allow then to set the visibility -->
1633
<div class="form-control mb-3 col-xs-8">

app/views/plans/_project_details.html.erb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ ethics_report_tooltip = _("Link to a protocol from a meeting with an ethics comm
102102
</div>
103103
<% end %>
104104

105-
<% if Rails.configuration.x.madmp.enable_ethical_issues %>
105+
<!-- This condition allows the existing functionality of displaying the Ethical Issues fragment with new feature proposed in
106+
https://github.com/DMPRoadmap/roadmap/issues/3555 -->
107+
<% if Rails.configuration.x.madmp.enable_ethical_issues &&
108+
(!Rails.configuration.x.madmp.enable_hide_ethical_issues_per_template ||
109+
(Rails.configuration.x.madmp.enable_hide_ethical_issues_per_template && plan.template.present? && plan.template.hide_ethical_issues_question.present? && !plan.template.hide_ethical_issues_question)) %>
106110
<conditional>
107111
<div class="form-control mb-3">
108112
<div class="col-lg-8">

config/initializers/_dmproadmap.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ class Application < Rails::Application
224224
config.x.madmp.enable_ethical_issues = true
225225
config.x.madmp.enable_research_domain = true
226226

227+
# If enable_ethical_issues is true, this flag hide_ethical_issues_question_per_template comes into play.
228+
# It will determine if the ethical_issues question is hidden/shown based on the template selected for the plan.
229+
# If the template has the hide_ethical_issues attribute set to true, then the question will be hidden.
230+
# If the template has the hide_ethical_issues is set to false, then the question will be shown.
231+
# If enable_ethical_issues is false, this flag has no effect.
232+
# config.x.madmp.enable_hide_ethical_issues_per_template = true
233+
config.x.madmp.enable_hide_ethical_issues_per_template = false
234+
227235
# This flag will enable/disable the entire Research Outputs tab. The others below will
228236
# just enable/disable specific functionality on the Research Outputs tab
229237
config.x.madmp.enable_research_outputs = true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddHideEthicalIssuesQuestionToTemplates < ActiveRecord::Migration[7.1]
2+
def change
3+
add_column :templates, :hide_ethical_issues_question, :boolean
4+
end
5+
end

0 commit comments

Comments
 (0)