mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-08 16:40:16 +08:00
861e7cf72d
Closes SCI-650
44 lines
1.1 KiB
Ruby
44 lines
1.1 KiB
Ruby
module Users
|
|
class InvitationsController < Devise::InvitationsController
|
|
def update
|
|
# Instantialize a new organization with the provided name
|
|
@org = Organization.new
|
|
@org.name = params[:organization][:name]
|
|
|
|
super do |user|
|
|
if user.errors.empty?
|
|
@org.created_by = user
|
|
@org.save
|
|
|
|
UserOrganization.create(
|
|
user: user,
|
|
organization: @org,
|
|
role: 'admin'
|
|
)
|
|
end
|
|
end
|
|
end
|
|
|
|
def accept_resource
|
|
unless @org.valid?
|
|
# Find the user being invited
|
|
resource = User.find_by_invitation_token(
|
|
update_resource_params[:invitation_token],
|
|
false
|
|
)
|
|
|
|
# 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
|
|
end
|
|
end
|