Skip to content

Commit 5cd2a36

Browse files
Merge pull request #3043 from DMPRoadmap/development
Release candidate - v3.0.4
2 parents 0c281f0 + e6c8a7c commit 5cd2a36

File tree

136 files changed

+5255
-2696
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+5255
-2696
lines changed

Gemfile.lock

Lines changed: 224 additions & 187 deletions
Large diffs are not rendered by default.

app/assets/stylesheets/blocks/_clearable_field.scss

Whitespace-only changes.

app/assets/stylesheets/variables/_site_overrides.scss

Whitespace-only changes.

app/controllers/application_controller.rb

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ class ApplicationController < ActionController::Base
2020
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
2121

2222
# When we are in production reroute Record Not Found errors to the branded 404 page
23-
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found if Rails.env.production?
23+
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
24+
25+
rescue_from StandardError, with: :handle_server_error
26+
27+
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
2428

2529
private
2630

@@ -30,9 +34,13 @@ def current_org
3034

3135
def user_not_authorized
3236
if user_signed_in?
33-
redirect_to plans_url, alert: _("You are not authorized to perform this action.")
37+
# redirect_to plans_url, alert: _("You are not authorized to perform this action.")
38+
msg = _("You are not authorized to perform this action.")
39+
render_respond_to_format_with_error_message(msg, plans_url, 403, nil)
3440
else
35-
redirect_to root_url, alert: _("You need to sign in or sign up before continuing.")
41+
# redirect_to root_url, alert: _("You need to sign in or sign up before continuing.")
42+
msg = _("You need to sign in or sign up before continuing.")
43+
render_respond_to_format_with_error_message(msg, root_url, 401, nil)
3644
end
3745
end
3846

@@ -172,4 +180,29 @@ def configure_permitted_parameters
172180
devise_parameter_sanitizer.permit(:accept_invitation, keys: %i[firstname surname org_id])
173181
end
174182

183+
def render_not_found(exception)
184+
msg = _("Record Not Found") + ": #{exception.message}"
185+
render_respond_to_format_with_error_message(msg, root_url, 404, exception)
186+
end
187+
188+
def handle_server_error(exception)
189+
msg = exception.message.to_s if exception.present?
190+
render_respond_to_format_with_error_message(msg, root_url, 500, exception)
191+
end
192+
193+
def render_respond_to_format_with_error_message(msg, url_or_path, http_status, exception)
194+
Rails.logger.error msg
195+
Rails.logger.error exception&.backtrace if exception.present?
196+
197+
respond_to do |format|
198+
# Redirect use to the path and display the error message
199+
format.html { redirect_to url_or_path, alert: msg }
200+
# Render the JSON error message (using API V1)
201+
format.json do
202+
@payload = { errors: [msg] }
203+
render "/api/v1/error", status: http_status
204+
end
205+
end
206+
end
207+
175208
end

app/controllers/feedback_requests_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def create
3131
def request_feedback_flash_notice
3232
# Use the generic feedback confirmation message unless the Org has
3333
# specified one
34-
text = current_user.org.feedback_email_msg || feedback_confirmation_default_message
34+
text = current_user.org.feedback_msg || feedback_confirmation_default_message
3535
feedback_constant_to_text(text, current_user, @plan, current_user.org)
3636
end
3737

app/controllers/orgs_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def org_params
215215
.permit(:name, :abbreviation, :logo, :contact_email, :contact_name,
216216
:remove_logo, :managed, :feedback_enabled, :org_links,
217217
:funder, :institution, :organisation,
218-
:feedback_email_msg, :org_id, :org_name, :org_crosswalk,
218+
:feedback_msg, :org_id, :org_name, :org_crosswalk,
219219
identifiers_attributes: %i[identifier_scheme_id value],
220220
tracker_attributes: %i[code id])
221221
end

app/controllers/plans_controller.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ def show
171171
else
172172
Rails.configuration.x.plans.default_visibility
173173
end
174-
174+
# Get all of the available funders
175+
@funders = Org.funder
176+
.includes(identifiers: :identifier_scheme)
177+
.joins(:templates)
178+
.where(templates: { published: true }).uniq.sort_by(&:name)
175179
# TODO: Seems strange to do this. Why are we just not using an `edit` route?
176180
@editing = (!params[:editing].nil? && @plan.administerable_by?(current_user.id))
177181

@@ -188,7 +192,7 @@ def show
188192
@important_ggs << [current_user.org, @all_ggs_grouped_by_org[current_user.org]]
189193
end
190194
@all_ggs_grouped_by_org.each do |org, ggs|
191-
@important_ggs << [org, ggs] if org.organisation?
195+
@important_ggs << [org, ggs] if Org.default_orgs.include?(org)
192196

193197
# If this is one of the already selected guidance groups its important!
194198
unless (ggs & @selected_guidance_groups).empty?
@@ -209,6 +213,8 @@ def show
209213
Template.where(family_id: @plan.template.customization_of).first
210214
end
211215

216+
@research_domains = ResearchDomain.all.order(:label)
217+
212218
respond_to :html
213219
end
214220
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
@@ -259,8 +265,12 @@ def update
259265

260266
# TODO: For some reason the `fields_for` isn't adding the
261267
# appropriate namespace, so org_id represents our funder
262-
funder = org_from_params(params_in: attrs, allow_create: true)
263-
@plan.funder_id = funder.id if funder.present?
268+
funder_attrs = plan_params[:funder]
269+
funder_attrs[:org_id] = plan_params[:funder][:id]
270+
funder = org_from_params(params_in: funder_attrs, allow_create: true)
271+
@plan.funder_id = funder&.id
272+
attrs.delete(:funder)
273+
264274
process_grant(grant_params: plan_params[:grant])
265275
attrs.delete(:grant)
266276
attrs = remove_org_selection_params(params_in: attrs)
@@ -467,6 +477,8 @@ def plan_params
467477
params.require(:plan)
468478
.permit(:template_id, :title, :visibility, :description, :identifier,
469479
:start_date, :end_date, :org_id, :org_name, :org_crosswalk,
480+
:ethical_issues, :ethical_issues_description, :ethical_issues_report,
481+
:research_domain_id, :funding_status,
470482
grant: %i[name value],
471483
org: %i[id org_id org_name org_sources org_crosswalk],
472484
funder: %i[id org_id org_name org_sources org_crosswalk])

app/controllers/super_admin/orgs_controller.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ def merge_commit
149149
def org_params
150150
params.require(:org).permit(:name, :abbreviation, :logo, :managed,
151151
:contact_email, :contact_name,
152-
:remove_logo, :feedback_enabled,
153-
:feedback_email_subject,
154-
:feedback_email_msg,
152+
:remove_logo, :feedback_enabled, :feedback_msg,
155153
:org_id, :org_name, :org_crosswalk)
156154
end
157155

app/controllers/template_options_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def plan_params
7979
end
8080

8181
def org_params
82-
%i[id name sort_name url language abbreviation ror fundref weight score]
82+
%i[id name url language abbreviation ror fundref weight score]
8383
end
8484

8585
end

app/javascript/src/orgs/adminEdit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { initAutocomplete, scrubOrgSelectionParamsOnSubmit } from '../utils/auto
77

88
$(() => {
99
const toggleFeedback = () => {
10-
const editor = Tinymce.findEditorById('org_feedback_email_msg');
10+
const editor = Tinymce.findEditorById('org_feedback_msg');
1111
if (isObject(editor)) {
1212
if ($('#org_feedback_enabled_true').is(':checked')) {
1313
editor.setMode('code');
@@ -22,7 +22,7 @@ $(() => {
2222
});
2323

2424
// Initialises tinymce for any target element with class tinymce_answer
25-
Tinymce.init({ selector: '#org_feedback_email_msg' });
25+
Tinymce.init({ selector: '#org_feedback_msg' });
2626
toggleFeedback();
2727

2828
if ($('#org-details-org-controls').length > 0) {

0 commit comments

Comments
 (0)