add archived users view
This commit is contained in:
@@ -7,7 +7,14 @@ class UsersController < ApplicationController
|
|||||||
authorize_resource :user, only: :create
|
authorize_resource :user, only: :create
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@pagy, @users = pagy(@users.active.order(id: :desc))
|
@users =
|
||||||
|
if params[:status] == 'archived'
|
||||||
|
@users.archived
|
||||||
|
else
|
||||||
|
@users.active
|
||||||
|
end
|
||||||
|
|
||||||
|
@pagy, @users = pagy(@users.order(id: :desc))
|
||||||
end
|
end
|
||||||
|
|
||||||
def new; end
|
def new; end
|
||||||
@@ -15,10 +22,19 @@ class UsersController < ApplicationController
|
|||||||
def edit; end
|
def edit; end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
existing_user = User.accessible_by(current_ability).find_by(email: @user.email)
|
||||||
|
|
||||||
|
if existing_user
|
||||||
|
existing_user.archived_at = nil
|
||||||
|
existing_user.assign_attributes(user_params)
|
||||||
|
|
||||||
|
@user = existing_user
|
||||||
|
end
|
||||||
|
|
||||||
if @user.save
|
if @user.save
|
||||||
UserMailer.invitation_email(@user).deliver_later!
|
UserMailer.invitation_email(@user).deliver_later!
|
||||||
|
|
||||||
redirect_to settings_users_path, notice: 'User has been invited'
|
redirect_back fallback_location: settings_users_path, notice: 'User has been invited'
|
||||||
else
|
else
|
||||||
render turbo_stream: turbo_stream.replace(:modal, template: 'users/new'), status: :unprocessable_entity
|
render turbo_stream: turbo_stream.replace(:modal, template: 'users/new'), status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
@@ -27,11 +43,11 @@ class UsersController < ApplicationController
|
|||||||
def update
|
def update
|
||||||
return redirect_to settings_users_path, notice: 'Unable to update user.' if Docuseal.demo?
|
return redirect_to settings_users_path, notice: 'Unable to update user.' if Docuseal.demo?
|
||||||
|
|
||||||
attrs = user_params.compact_blank
|
attrs = user_params.compact_blank.merge(user_params.slice(:archived_at))
|
||||||
attrs.delete(:role) if !role_valid?(attrs[:role]) || current_user == @user
|
attrs.delete(:role) if !role_valid?(attrs[:role]) || current_user == @user
|
||||||
|
|
||||||
if @user.update(attrs)
|
if @user.update(attrs)
|
||||||
redirect_to settings_users_path, notice: 'User has been updated'
|
redirect_back fallback_location: settings_users_path, notice: 'User has been updated'
|
||||||
else
|
else
|
||||||
render turbo_stream: turbo_stream.replace(:modal, template: 'users/edit'), status: :unprocessable_entity
|
render turbo_stream: turbo_stream.replace(:modal, template: 'users/edit'), status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
@@ -44,7 +60,7 @@ class UsersController < ApplicationController
|
|||||||
|
|
||||||
@user.update!(archived_at: Time.current)
|
@user.update!(archived_at: Time.current)
|
||||||
|
|
||||||
redirect_to settings_users_path, notice: 'User has been removed'
|
redirect_back fallback_location: settings_users_path, notice: 'User has been removed'
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -65,6 +81,6 @@ class UsersController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def user_params
|
def user_params
|
||||||
params.require(:user).permit(:email, :first_name, :last_name, :password, :role)
|
params.require(:user).permit(:email, :first_name, :last_name, :password, :role, :archived_at)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ class User < ApplicationRecord
|
|||||||
attribute :uuid, :string, default: -> { SecureRandom.uuid }
|
attribute :uuid, :string, default: -> { SecureRandom.uuid }
|
||||||
|
|
||||||
scope :active, -> { where(archived_at: nil) }
|
scope :active, -> { where(archived_at: nil) }
|
||||||
|
scope :archived, -> { where.not(archived_at: nil) }
|
||||||
scope :admins, -> { where(role: ADMIN_ROLE) }
|
scope :admins, -> { where(role: ADMIN_ROLE) }
|
||||||
|
|
||||||
def access_token
|
def access_token
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<%= render 'shared/settings_nav' %>
|
<%= render 'shared/settings_nav' %>
|
||||||
<div class="md:flex-grow">
|
<div class="md:flex-grow">
|
||||||
<div class="flex justify-between mb-4">
|
<div class="flex justify-between mb-4">
|
||||||
<h1 class="text-4xl font-bold">Users</h1>
|
<h1 class="text-4xl font-bold"><%= params[:status].to_s.titleize %> Users</h1>
|
||||||
<div class="flex items-center space-x-4">
|
<div class="flex items-center space-x-4">
|
||||||
<% if can?(:create, User.new(account: current_account)) %>
|
<% if can?(:create, User.new(account: current_account)) %>
|
||||||
<%= link_to new_user_path, class: 'btn btn-primary btn-md gap-2', data: { turbo_frame: 'modal' } do %>
|
<%= link_to new_user_path, class: 'btn btn-primary btn-md gap-2', data: { turbo_frame: 'modal' } do %>
|
||||||
@@ -55,17 +55,39 @@
|
|||||||
Edit
|
Edit
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if can?(:destroy, user) && user != current_user %>
|
<% if params[:status].blank? && can?(:destroy, user) && user != current_user %>
|
||||||
<%= button_to user_path(user), method: :delete, class: 'btn btn-outline btn-error btn-xs', title: 'Delete', data: { turbo_confirm: 'Are you sure?' } do %>
|
<%= button_to user_path(user), method: :delete, class: 'btn btn-outline btn-error btn-xs', title: 'Delete', data: { turbo_confirm: 'Are you sure?' } do %>
|
||||||
Remove
|
Remove
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% if params[:status].present? && can?(:manage, user) && user != current_user %>
|
||||||
|
<%= button_to user_path(user), method: :put, params: { user: { archived_at: nil } }, class: 'btn btn-outline btn-secondary btn-xs', title: 'Unarchive', data: { turbo_confirm: 'Are you sure?' } do %>
|
||||||
|
Unarchive
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<%= render 'shared/pagination', pagy: @pagy, items_name: 'users' %>
|
<% view_archived_html = capture do %>
|
||||||
|
<% if current_account.users.archived.exists? %>
|
||||||
|
<div>
|
||||||
|
<% if params[:status] == 'archived' %>
|
||||||
|
<a href="<%= settings_users_path %>" class="link text-sm">View Active</a>
|
||||||
|
<% else %>
|
||||||
|
<a href="<%= settings_archived_users_path %>" class="link text-sm">View Archived</a>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<% if @pagy.pages > 1 %>
|
||||||
|
<%= render 'shared/pagination', pagy: @pagy, items_name: 'users', left_additional_html: view_archived_html %>
|
||||||
|
<% else %>
|
||||||
|
<div class="mt-2">
|
||||||
|
<%= view_archived_html %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -131,6 +131,8 @@ Rails.application.routes.draw do
|
|||||||
resources :notifications, only: %i[index create], controller: 'notifications_settings'
|
resources :notifications, only: %i[index create], controller: 'notifications_settings'
|
||||||
resource :esign, only: %i[show create new update destroy], controller: 'esign_settings'
|
resource :esign, only: %i[show create new update destroy], controller: 'esign_settings'
|
||||||
resources :users, only: %i[index]
|
resources :users, only: %i[index]
|
||||||
|
resources :archived_users, only: %i[index], path: 'users/:status', controller: 'users',
|
||||||
|
defaults: { status: :archived }
|
||||||
resource :personalization, only: %i[show create], controller: 'personalization_settings'
|
resource :personalization, only: %i[show create], controller: 'personalization_settings'
|
||||||
resources :api, only: %i[index create], controller: 'api_settings'
|
resources :api, only: %i[index create], controller: 'api_settings'
|
||||||
resource :webhooks, only: %i[show create update], controller: 'webhook_settings'
|
resource :webhooks, only: %i[show create update], controller: 'webhook_settings'
|
||||||
|
|||||||
Reference in New Issue
Block a user