Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNOE-819] Update error handling when inviting user to organization #595

Open
wants to merge 2 commits into
base: 3.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

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.persisted?
@user = user.confirmed? ? invite : user.reload
else
render json: invite.errors, status: :bad_request
end
end

protected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a spec for when the invitation is not saved.
I think persisted? is just checking the id so you can have a stub without id for this case.

end

let(:params) { FactoryGirl.attributes_for(:user) }
Expand Down