From badb9d4235bd3ec7fc0ab1e6594f0a16905bf7fa Mon Sep 17 00:00:00 2001 From: Adam Abdelaziz Date: Mon, 4 Dec 2017 15:51:15 -0500 Subject: [PATCH 1/2] Update error handling when inviting user to organization --- .../jpi/v1/admin/organizations_controller.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/api/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb b/api/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb index 5f78fd47c..f928d4937 100644 --- a/api/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb +++ b/api/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb @@ -73,14 +73,19 @@ def invite_member user = MnoEnterprise::User.find_by(email: user_params[:email]) || create_unconfirmed_user(user_params) # Create the invitation - invite = @organization.org_invites.create( + invite = MnoEnterprise::OrgInvite.create( user_email: user.email, user_role: params[:user][:role], referrer_id: current_user.id, - status: 'staged' # Will be updated to 'accepted' for unconfirmed users + status: 'staged', # Will be updated to 'accepted' for unconfirmed users + organization_id: @organization.id ) - @user = user.confirmed? ? invite : user.reload + if invite.save + @user = user.confirmed? ? invite : user.reload + else + render json: invite.errors, status: :bad_request + end end protected From 1dc62fe49934ab2ed81a45756599b43ed71c17e3 Mon Sep 17 00:00:00 2001 From: Adam Abdelaziz Date: Mon, 4 Dec 2017 17:42:10 -0500 Subject: [PATCH 2/2] Update specs --- .../mno_enterprise/jpi/v1/admin/organizations_controller.rb | 2 +- .../jpi/v1/admin/organizations_controller_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb b/api/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb index f928d4937..070231789 100644 --- a/api/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb +++ b/api/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb @@ -81,7 +81,7 @@ def invite_member organization_id: @organization.id ) - if invite.save + if invite.persisted? @user = user.confirmed? ? invite : user.reload else render json: invite.errors, status: :bad_request diff --git a/api/spec/controllers/mno_enterprise/jpi/v1/admin/organizations_controller_spec.rb b/api/spec/controllers/mno_enterprise/jpi/v1/admin/organizations_controller_spec.rb index 882183970..50b5524dc 100644 --- a/api/spec/controllers/mno_enterprise/jpi/v1/admin/organizations_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/jpi/v1/admin/organizations_controller_spec.rb @@ -157,7 +157,7 @@ def partial_hash_for_arrears(arrear) # Track the api call @api_call = false stub = -> { @api_call = true; from_api(org_invite) } - api_stub_for(post: "/organizations/#{organization.id}/org_invites", response: stub) + api_stub_for(post: "/org_invites", response: stub) end let(:params) { FactoryGirl.attributes_for(:user) }