Skip to content

Commit

Permalink
4523: Fix user info disappearing on validation failure for new org re…
Browse files Browse the repository at this point in the history
…quests (#4779)
  • Loading branch information
coalest authored Nov 16, 2024
1 parent 2877cc2 commit e8dd85d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 5 additions & 4 deletions app/controllers/admin/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ def new

def create
@organization = Organization.new(organization_params)
@user = User.new(user_params)

if @organization.save
Organization.seed_items(@organization)
@user = UserInviteService.invite(name: user_params[:name],
email: user_params[:email],
roles: [Role::ORG_USER, Role::ORG_ADMIN],
resource: @organization)
UserInviteService.invite(name: user_params[:name],
email: user_params[:email],
roles: [Role::ORG_USER, Role::ORG_ADMIN],
resource: @organization)
SnapshotEvent.publish(@organization) # need one to start with
redirect_to admin_organizations_path, notice: "Organization added!"
else
Expand Down
8 changes: 8 additions & 0 deletions spec/requests/admin/organizations_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@
expect(subject).to render_template("new")
expect(flash[:error]).to be_present
end

it "preserves user attributes" do
post admin_organizations_path({ organization: invalid_params })

expect(subject).to render_template("new")
expect(response.body).to include(invalid_params[:user][:name])
expect(response.body).to include(invalid_params[:user][:email])
end
end
end

Expand Down

0 comments on commit e8dd85d

Please sign in to comment.