From 3be30c0e7ad7bb06052cf8cd9f5ebc07427db146 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Fri, 18 Nov 2016 10:57:03 +0100 Subject: [PATCH] Re-introduce fix for SCI-650 that was lost during merge Closes SCI-650. --- .../users/invitations_controller.rb | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/controllers/users/invitations_controller.rb b/app/controllers/users/invitations_controller.rb index d6ca37a7c..907477c2f 100644 --- a/app/controllers/users/invitations_controller.rb +++ b/app/controllers/users/invitations_controller.rb @@ -5,6 +5,7 @@ module Users before_action :check_invite_users_permission, only: :invite_users def update + # Instantialize a new organization with the provided name @org = Organization.new @org.name = params[:organization][:name] @@ -23,9 +24,25 @@ module Users end def accept_resource - resource = super - resource.errors.add(:base, @org.errors.to_a.first) unless @org.valid? - resource + unless @org.valid? + # Find the user being invited + resource = User.find_by_invitation_token( + update_resource_params[:invitation_token], + false + ) + + # Check if user's data (passwords etc.) is valid + resource.assign_attributes( + update_resource_params.except(:invitation_token) + ) + resource.valid? # Call validation to generate errors + + # In any case, add the organization name error + resource.errors.add(:base, @org.errors.to_a.first) + return resource + end + + super end def invite_users