Skip to content

Commit

Permalink
do not allow to remove current user
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBTurchyn committed Jul 9, 2023
1 parent e2cda2b commit 15523d8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,30 @@ def create
if @user.save
UserMailer.invitation_email(@user).deliver_later!

redirect_to settings_users_path, notice: 'User has been invited.'
redirect_to settings_users_path, notice: 'User has been invited'
else
render turbo_stream: turbo_stream.replace(:modal, template: 'users/new'), status: :unprocessable_entity
end
end

def update
return redirect_to settings_users_path, notice: 'Unable to update user.' if Docuseal.demo?

if @user.update(user_params.compact_blank)
redirect_to settings_users_path, notice: 'User has been updated.'
redirect_to settings_users_path, notice: 'User has been updated'
else
render turbo_stream: turbo_stream.replace(:modal, template: 'users/edit'), status: :unprocessable_entity
end
end

def destroy
if Docuseal.demo? || @user.id == current_user.id
return redirect_to settings_users_path, notice: 'Unable to remove user'
end

@user.update!(deleted_at: Time.current)

redirect_to settings_users_path, notice: 'User has been removed.'
redirect_to settings_users_path, notice: 'User has been removed'
end

private
Expand Down

0 comments on commit 15523d8

Please sign in to comment.