mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-07 21:55:20 +08:00
Update invited user form so it works if user inputs empty team name
Closes SCI-650
This commit is contained in:
parent
0793fb9f11
commit
861e7cf72d
1 changed files with 35 additions and 21 deletions
|
@ -1,30 +1,44 @@
|
||||||
class Users::InvitationsController < Devise::InvitationsController
|
module Users
|
||||||
|
class InvitationsController < Devise::InvitationsController
|
||||||
|
def update
|
||||||
|
# Instantialize a new organization with the provided name
|
||||||
|
@org = Organization.new
|
||||||
|
@org.name = params[:organization][:name]
|
||||||
|
|
||||||
def update
|
super do |user|
|
||||||
@org = Organization.new
|
if user.errors.empty?
|
||||||
@org.name = params[:organization][:name]
|
@org.created_by = user
|
||||||
|
@org.save
|
||||||
|
|
||||||
super do |user|
|
UserOrganization.create(
|
||||||
if user.errors.empty?
|
user: user,
|
||||||
@org.created_by = user
|
organization: @org,
|
||||||
@org.save
|
role: 'admin'
|
||||||
|
)
|
||||||
UserOrganization.create(
|
end
|
||||||
user: user,
|
|
||||||
organization: @org,
|
|
||||||
role: 'admin'
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def accept_resource
|
def accept_resource
|
||||||
resource = super
|
unless @org.valid?
|
||||||
|
# Find the user being invited
|
||||||
|
resource = User.find_by_invitation_token(
|
||||||
|
update_resource_params[:invitation_token],
|
||||||
|
false
|
||||||
|
)
|
||||||
|
|
||||||
if not @org.valid?
|
# Check if user's data (passwords etc.) is valid
|
||||||
resource.errors.add(:base, @org.errors.to_a.first)
|
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
|
end
|
||||||
|
|
||||||
resource
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue