Skip to content

Commit

Permalink
Merge pull request DMPRoadmap#3043 from DMPRoadmap/development
Browse files Browse the repository at this point in the history
Release candidate - v3.0.4
  • Loading branch information
raycarrick-ed committed Oct 4, 2021
2 parents ac7de1b + 3daacf5 commit b914e91
Show file tree
Hide file tree
Showing 136 changed files with 5,255 additions and 2,696 deletions.
411 changes: 224 additions & 187 deletions Gemfile.lock

Large diffs are not rendered by default.

Empty file.
Empty file.
39 changes: 36 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ class ApplicationController < ActionController::Base
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized

# When we are in production reroute Record Not Found errors to the branded 404 page
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found if Rails.env.production?
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found

rescue_from StandardError, with: :handle_server_error

rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized

private

Expand All @@ -30,9 +34,13 @@ def current_org

def user_not_authorized
if user_signed_in?
redirect_to plans_url, alert: _("You are not authorized to perform this action.")
# redirect_to plans_url, alert: _("You are not authorized to perform this action.")
msg = _("You are not authorized to perform this action.")
render_respond_to_format_with_error_message(msg, plans_url, 403, nil)
else
redirect_to root_url, alert: _("You need to sign in or sign up before continuing.")
# redirect_to root_url, alert: _("You need to sign in or sign up before continuing.")
msg = _("You need to sign in or sign up before continuing.")
render_respond_to_format_with_error_message(msg, root_url, 401, nil)
end
end

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

def render_not_found(exception)
msg = _("Record Not Found") + ": #{exception.message}"
render_respond_to_format_with_error_message(msg, root_url, 404, exception)
end

def handle_server_error(exception)
msg = exception.message.to_s if exception.present?
render_respond_to_format_with_error_message(msg, root_url, 500, exception)
end

def render_respond_to_format_with_error_message(msg, url_or_path, http_status, exception)
Rails.logger.error msg
Rails.logger.error exception&.backtrace if exception.present?

respond_to do |format|
# Redirect use to the path and display the error message
format.html { redirect_to url_or_path, alert: msg }
# Render the JSON error message (using API V1)
format.json do
@payload = { errors: [msg] }
render "/api/v1/error", status: http_status
end
end
end

end
2 changes: 1 addition & 1 deletion app/controllers/feedback_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def create
def request_feedback_flash_notice
# Use the generic feedback confirmation message unless the Org has
# specified one
text = current_user.org.feedback_email_msg || feedback_confirmation_default_message
text = current_user.org.feedback_msg || feedback_confirmation_default_message
feedback_constant_to_text(text, current_user, @plan, current_user.org)
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/orgs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def org_params
.permit(:name, :abbreviation, :logo, :contact_email, :contact_name,
:remove_logo, :managed, :feedback_enabled, :org_links,
:funder, :institution, :organisation,
:feedback_email_msg, :org_id, :org_name, :org_crosswalk,
:feedback_msg, :org_id, :org_name, :org_crosswalk,
identifiers_attributes: %i[identifier_scheme_id value],
tracker_attributes: %i[code id])
end
Expand Down
20 changes: 16 additions & 4 deletions app/controllers/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ def show
else
Rails.configuration.x.plans.default_visibility
end

# Get all of the available funders
@funders = Org.funder
.includes(identifiers: :identifier_scheme)
.joins(:templates)
.where(templates: { published: true }).uniq.sort_by(&:name)
# TODO: Seems strange to do this. Why are we just not using an `edit` route?
@editing = (!params[:editing].nil? && @plan.administerable_by?(current_user.id))

Expand All @@ -188,7 +192,7 @@ def show
@important_ggs << [current_user.org, @all_ggs_grouped_by_org[current_user.org]]
end
@all_ggs_grouped_by_org.each do |org, ggs|
@important_ggs << [org, ggs] if org.organisation?
@important_ggs << [org, ggs] if Org.default_orgs.include?(org)

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

@research_domains = ResearchDomain.all.order(:label)

respond_to :html
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
Expand Down Expand Up @@ -259,8 +265,12 @@ def update

# TODO: For some reason the `fields_for` isn't adding the
# appropriate namespace, so org_id represents our funder
funder = org_from_params(params_in: attrs, allow_create: true)
@plan.funder_id = funder.id if funder.present?
funder_attrs = plan_params[:funder]
funder_attrs[:org_id] = plan_params[:funder][:id]
funder = org_from_params(params_in: funder_attrs, allow_create: true)
@plan.funder_id = funder&.id
attrs.delete(:funder)

process_grant(grant_params: plan_params[:grant])
attrs.delete(:grant)
attrs = remove_org_selection_params(params_in: attrs)
Expand Down Expand Up @@ -467,6 +477,8 @@ def plan_params
params.require(:plan)
.permit(:template_id, :title, :visibility, :description, :identifier,
:start_date, :end_date, :org_id, :org_name, :org_crosswalk,
:ethical_issues, :ethical_issues_description, :ethical_issues_report,
:research_domain_id, :funding_status,
grant: %i[name value],
org: %i[id org_id org_name org_sources org_crosswalk],
funder: %i[id org_id org_name org_sources org_crosswalk])
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/super_admin/orgs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ def merge_commit
def org_params
params.require(:org).permit(:name, :abbreviation, :logo, :managed,
:contact_email, :contact_name,
:remove_logo, :feedback_enabled,
:feedback_email_subject,
:feedback_email_msg,
:remove_logo, :feedback_enabled, :feedback_msg,
:org_id, :org_name, :org_crosswalk)
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/template_options_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def plan_params
end

def org_params
%i[id name sort_name url language abbreviation ror fundref weight score]
%i[id name url language abbreviation ror fundref weight score]
end

end
4 changes: 2 additions & 2 deletions app/javascript/src/orgs/adminEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { initAutocomplete, scrubOrgSelectionParamsOnSubmit } from '../utils/auto

$(() => {
const toggleFeedback = () => {
const editor = Tinymce.findEditorById('org_feedback_email_msg');
const editor = Tinymce.findEditorById('org_feedback_msg');
if (isObject(editor)) {
if ($('#org_feedback_enabled_true').is(':checked')) {
editor.setMode('code');
Expand All @@ -22,7 +22,7 @@ $(() => {
});

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

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

0 comments on commit b914e91

Please sign in to comment.