diff --git a/app/controllers/api/v0/plans_controller.rb b/app/controllers/api/v0/plans_controller.rb
index f81c0e7f68..374d5401d9 100644
--- a/app/controllers/api/v0/plans_controller.rb
+++ b/app/controllers/api/v0/plans_controller.rb
@@ -73,10 +73,10 @@ def index
# Get all the Org Admin plans
org_admin_plans = @user.org.org_admin_plans
- @plans = org_admin_plans.includes([{ roles: :user }, { answers: :question_options },
- template: [{ phases: {
- sections: { questions: %i[question_format themes] }
- } }, :org]])
+ @plans = org_admin_plans.preload([{ roles: :user }, { answers: :question_options },
+ template: [{ phases: {
+ sections: { questions: %i[question_format themes] }
+ } }, :org]])
# Filter on list of users
user_ids = extract_param_list(params, 'user')
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 035029620f..da8cde06da 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -105,7 +105,7 @@ def authenticate_admin!
end
def failure_message(obj, action = 'save')
- format(_('Unable to %{action} the %{object}. {errors}'),
+ format(_('Unable to %{action} the %{object}. %{errors}'),
object: obj_name_for_display(obj),
action: action || 'save', errors: errors_for_display(obj))
end
diff --git a/app/controllers/orgs_controller.rb b/app/controllers/orgs_controller.rb
index e4f2423886..e2d8129f8f 100644
--- a/app/controllers/orgs_controller.rb
+++ b/app/controllers/orgs_controller.rb
@@ -33,7 +33,11 @@ def admin_update
@org = Org.find(params[:id])
authorize @org
- @org.logo = attrs[:logo] if attrs[:logo]
+ # If a new logo was supplied then use it, otherwise retain the existing one
+ attrs[:logo] = attrs[:logo].present? ? attrs[:logo] : @org.logo
+ # Remove the logo if the user checked the box
+ attrs[:logo] = nil if attrs[:remove_logo] == '1'
+
tab = (attrs[:feedback_enabled].present? ? 'feedback' : 'profile')
@org.links = ActiveSupport::JSON.decode(params[:org_links]) if params[:org_links].present?
diff --git a/app/controllers/paginable/templates_controller.rb b/app/controllers/paginable/templates_controller.rb
index 5ea6b552e8..4456ffa00b 100644
--- a/app/controllers/paginable/templates_controller.rb
+++ b/app/controllers/paginable/templates_controller.rb
@@ -105,8 +105,9 @@ def history
paginable_renderise(
partial: 'history',
scope: @templates,
- query_params: { sort_field: 'templates.title', sort_direction: :asc },
- locals: { current: @templates.maximum(:version) }
+ query_params: { sort_field: 'templates.version', sort_direction: :desc },
+ locals: { current: @templates.maximum(:version) },
+ format: :json
)
end
end
diff --git a/app/controllers/plan_exports_controller.rb b/app/controllers/plan_exports_controller.rb
index 41edc38212..46bcbef953 100644
--- a/app/controllers/plan_exports_controller.rb
+++ b/app/controllers/plan_exports_controller.rb
@@ -85,6 +85,9 @@ def show_docx
def show_pdf
render pdf: file_name,
margin: @formatting[:margin],
+ # wkhtmltopdf behavior is based on the OS so force the zoom level
+ # See 'Gotchas' section of https://github.com/mileszs/wicked_pdf
+ zoom: 0.78125,
footer: {
center: format(_('Created using %{application_name}. Last modified %{date}'),
application_name: ApplicationService.application_name,
diff --git a/app/javascript/src/utils/accordion.js b/app/javascript/src/utils/accordion.js
index d80ee9c5ee..253893bbd9 100644
--- a/app/javascript/src/utils/accordion.js
+++ b/app/javascript/src/utils/accordion.js
@@ -31,21 +31,23 @@
*
*/
$(() => {
- $('body').on('click', '.accordion-controls', (e) => {
+ $('body').on('click', '.accordion-controls a', (e) => {
e.preventDefault();
const currentTarget = $(e.currentTarget);
const target = $(e.target);
const direction = target.attr('data-toggle-direction');
+ const parentTargetName = currentTarget.parent().attr('data-parent');
if (direction) {
// Selects all .panel elements where the parent is currentTarget.attr('data-parent') and
// after gets the immediately children whose class selector is panel-collapse
- $(`#${currentTarget.attr('data-parent')} > .panel`).children('.panel-collapse').each((i, el) => {
+ const parentTarget = $(`#${parentTargetName}`).length ? $(`#${parentTargetName}`) : $(`.${parentTargetName}`);
+ $(parentTarget).find('.panel').find('.panel-collapse').each((i, el) => {
const panelCollapse = $(el);
// Expands or collapses the panel according to the
// direction passed (e.g. show --> expands, hide --> collapses)
if (direction === 'show') {
- if (!panelCollapse.hasClass('in')) {
- panelCollapse.prev().trigger('click');
+ if (!panelCollapse.find('.panel-body').attr('data-loaded') || !panelCollapse.hasClass('in')) {
+ panelCollapse.prev()[0].click();
}
} else {
panelCollapse.collapse(direction);
diff --git a/app/javascript/src/utils/sectionUpdate.js b/app/javascript/src/utils/sectionUpdate.js
index 5e470b2de2..d31ce3331a 100644
--- a/app/javascript/src/utils/sectionUpdate.js
+++ b/app/javascript/src/utils/sectionUpdate.js
@@ -19,4 +19,4 @@ export const updateSectionProgress = (id, numSecAnswers, numSecQuestions) => {
// given a question id find the containing div
// used inconditional questions
-export const getQuestionDiv = (id) => $(`#answer-form-${id}`).closest('.row');
+export const getQuestionDiv = (id) => $(`#answer-form-${id}`).closest('.question-body');
diff --git a/app/models/concerns/exportable_plan.rb b/app/models/concerns/exportable_plan.rb
index 0e39130a5a..b106db3a7a 100644
--- a/app/models/concerns/exportable_plan.rb
+++ b/app/models/concerns/exportable_plan.rb
@@ -131,15 +131,14 @@ def prepare_coversheet
hash
end
# rubocop:enable Metrics/AbcSize
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/PerceivedComplexity
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def prepare_coversheet_for_csv(csv, _headings, hash)
- csv << [if hash[:attribution].many?
- _('Creators: ')
- else
- _('Creator:')
- end, format(_('%{authors}'), authors: hash[:attribution].join(', '))]
+ csv << if Array(hash[:attribution]).many?
+ [_('Creators: '), format(_('%{authors}'), authors: Array(hash[:attribution]).join(', '))]
+ else
+ [_('Creator:'), format(_('%{authors}'), authors: hash[:attribution])]
+ end
csv << ['Affiliation: ', format(_('%{affiliation}'), affiliation: hash[:affiliation])]
csv << if hash[:funder].present?
[_('Template: '), format(_('%{funder}'), funder: hash[:funder])]
@@ -161,10 +160,9 @@ def prepare_coversheet_for_csv(csv, _headings, hash)
csv << []
csv << []
end
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/PerceivedComplexity
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
# rubocop:disable Metrics/AbcSize, Metrics/BlockLength, Metrics/MethodLength
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:disable Metrics/ParameterLists
def show_section_for_csv(csv, phase, section, headings, unanswered, hash)
section[:questions].each do |question|
diff --git a/app/models/phase.rb b/app/models/phase.rb
index 7b466b68b0..9dfd1b11cd 100644
--- a/app/models/phase.rb
+++ b/app/models/phase.rb
@@ -139,7 +139,7 @@ def num_answers_not_removed(plan)
end
def visibility_allowed?(plan)
- value = Rational(num_answered_questions(plan), plan.num_questions) * 100
+ value = Rational(num_answered_questions(plan), plan.num_questions).to_f * 100
value >= Rails.configuration.x.plans.default_percentage_answered.to_f
end
end
diff --git a/app/policies/department_policy.rb b/app/policies/department_policy.rb
index 95018eb5cf..ed98bbf3ce 100644
--- a/app/policies/department_policy.rb
+++ b/app/policies/department_policy.rb
@@ -6,8 +6,7 @@ class DepartmentPolicy < ApplicationPolicy
# NOTE: @user is the signed_in_user and @record is an instance of Department
def index?
- (@user.can_org_admin? && @user.org.id == @department.org_id) ||
- @user.can_super_admin?
+ @user.can_org_admin? || @user.can_super_admin?
end
def new?
diff --git a/app/views/contact_us/contacts/_new_right.html.erb b/app/views/contact_us/contacts/_new_right.html.erb
index a5c85c4944..ecf4be41b4 100644
--- a/app/views/contact_us/contacts/_new_right.html.erb
+++ b/app/views/contact_us/contacts/_new_right.html.erb
@@ -7,7 +7,7 @@
Rails.configuration.x.organisation.address.fetch(:line4, ""),
Rails.configuration.x.organisation.address.fetch(:country, "")].compact.each do |addr_line| %>
<% if addr_line.present? %>
- <%= addr_line %>
+ <%= addr_line.is_a?(Array) ? addr_line.join(' ') : addr_line %>
<% end %>
<% end %>
diff --git a/app/views/org_admin/sections/_section.html.erb b/app/views/org_admin/sections/_section.html.erb
index ca7062ca7f..cb56aa07b2 100644
--- a/app/views/org_admin/sections/_section.html.erb
+++ b/app/views/org_admin/sections/_section.html.erb
@@ -46,4 +46,4 @@
<% end %>
-
+
\ No newline at end of file
diff --git a/app/views/org_admin/sections/_section_group.html.erb b/app/views/org_admin/sections/_section_group.html.erb
index 4623c019b0..37a960ab59 100644
--- a/app/views/org_admin/sections/_section_group.html.erb
+++ b/app/views/org_admin/sections/_section_group.html.erb
@@ -1,5 +1,5 @@
-
<%= sanitize(result.description) %>
- <% website = result.locations.select { |loc| loc["type"] == "website" }.first %> + <% website = result&.locations&.select { |loc| loc["type"] == "website" }&.first %> <% if website.present? %>