mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-07 05:34:55 +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
|
||||
@org = Organization.new
|
||||
@org.name = params[:organization][:name]
|
||||
super do |user|
|
||||
if user.errors.empty?
|
||||
@org.created_by = user
|
||||
@org.save
|
||||
|
||||
super do |user|
|
||||
if user.errors.empty?
|
||||
@org.created_by = user
|
||||
@org.save
|
||||
|
||||
UserOrganization.create(
|
||||
user: user,
|
||||
organization: @org,
|
||||
role: 'admin'
|
||||
)
|
||||
UserOrganization.create(
|
||||
user: user,
|
||||
organization: @org,
|
||||
role: 'admin'
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def accept_resource
|
||||
resource = super
|
||||
def accept_resource
|
||||
unless @org.valid?
|
||||
# Find the user being invited
|
||||
resource = User.find_by_invitation_token(
|
||||
update_resource_params[:invitation_token],
|
||||
false
|
||||
)
|
||||
|
||||
if not @org.valid?
|
||||
resource.errors.add(:base, @org.errors.to_a.first)
|
||||
# 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
|
||||
|
||||
resource
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue