mirror of https://github.com/docusealco/docuseal
				
				
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							63 lines
						
					
					
						
							1.6 KiB
						
					
					
				
			
		
		
	
	
							63 lines
						
					
					
						
							1.6 KiB
						
					
					
				| # frozen_string_literal: true
 | |
| 
 | |
| class UsersController < ApplicationController
 | |
|   before_action :load_user, only: %i[edit update destroy]
 | |
| 
 | |
|   def index
 | |
|     @pagy, @users = pagy(current_account.users.active.order(id: :desc))
 | |
|   end
 | |
| 
 | |
|   def new
 | |
|     @user = current_account.users.new
 | |
|   end
 | |
| 
 | |
|   def edit; end
 | |
| 
 | |
|   def create
 | |
|     @user = current_account.users.find_by(email: user_params[:email])&.tap do |user|
 | |
|       user.assign_attributes(user_params)
 | |
|       user.deleted_at = nil
 | |
|     end
 | |
| 
 | |
|     @user ||= current_account.users.new(user_params)
 | |
| 
 | |
|     if @user.save
 | |
|       UserMailer.invitation_email(@user).deliver_later!
 | |
| 
 | |
|       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'
 | |
|     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'
 | |
|   end
 | |
| 
 | |
|   private
 | |
| 
 | |
|   def load_user
 | |
|     @user = current_account.users.find(params[:id])
 | |
|   end
 | |
| 
 | |
|   def user_params
 | |
|     params.require(:user).permit(:email, :first_name, :last_name, :password)
 | |
|   end
 | |
| end
 |