diff --git a/app/controllers/orgs_controller.rb b/app/controllers/orgs_controller.rb index b5183b4..c64931b 100644 --- a/app/controllers/orgs_controller.rb +++ b/app/controllers/orgs_controller.rb @@ -17,7 +17,7 @@ @org = Org.find(params[:id]) authorize @org @org.logo = attrs[:logo] if attrs[:logo] - + failure = '' tab = (attrs[:feedback_enabled].present? ? 'feedback' : 'profile') if attrs[:links].present? @@ -27,24 +27,20 @@ if json.all?{ |o| o['link'].present? && o['text'].present? } @org.links = json else - redirect_to "#{admin_edit_org_path(@org)}\##{tab}", alert: _('Unable to save your changes. Invalid URLs.') + failure = _('Unable to save your changes. Invalid URLs.') end else - redirect_to "#{admin_edit_org_path(@org)}\##{tab}", alert: _('Unable to save your changes. Invalid URLs.') + failure = _('Unable to save your changes. Invalid URLs.') end attrs.delete('links') end begin - if @org.update_attributes(attrs) + if failure.blank? && @org.update_attributes(attrs) redirect_to "#{admin_edit_org_path(@org)}\##{tab}", notice: success_message(_('organisation'), _('saved')) else - # For some reason our custom validator returns as a string and not a hash like normal activerecord - # errors. We followed the example provided in the Rails guides when building the validator so - # its unclear why its doing this. Placing a check here for the data type. We should reasses though - # when doing a broader eval of the look/feel of the site and we come up with a standardized way of - # displaying errors - redirect_to "#{admin_edit_org_path(@org)}\##{tab}", alert: failed_update_error(@org, _('organisation')) + failure = failed_update_error(@org, _('organisation')) if failure.blank? + redirect_to "#{admin_edit_org_path(@org)}\##{tab}", alert: failure end rescue Dragonfly::Job::Fetch::NotFound => dflye redirect_to "#{admin_edit_org_path(@org)}\##{tab}", alert: _('There seems to be a problem with your logo. Please upload it again.') diff --git a/app/models/plan.rb b/app/models/plan.rb index 9c7765f..1396aff 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -213,7 +213,7 @@ UserMailer.feedback_confirmation(r, self, user).deliver_now end # Send an email to all of the org admins as well as the Org's administrator email - if user.org.contact_email.present? + if user.org.contact_email.present? && !admins.collect{ |u| u.email }.include?(user.org.contact_email) admins << User.new(email: user.org.contact_email, firstname: user.org.contact_name) end deliver_if(recipients: admins, key: 'admins.feedback_requested') do |r|