Class: UsersController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- UsersController
- Includes:
- Pagy::Backend
- Defined in:
- app/controllers/users_controller.rb
Overview
This controller manage the views refering to Risk model
-
before_action :ApplicationController#powered_in!
-
before_action :set_user, except: [:index, :list, :new, :create]
Instance Method Summary collapse
-
#create ⇒ Object
POST /users.
-
#destroy ⇒ Object
DELETE /users/:id.
-
#edit_external_user ⇒ Object
GET /user/:id/edit_external.
-
#external_user ⇒ Object
GET.
-
#index ⇒ Object
GET /users.
-
#list ⇒ Object
GET /users/list.
-
#new ⇒ Object
GET /users/new.
-
#notify ⇒ Nil
PUT /user/:id/notify.
-
#remove_attachment ⇒ Object
DELETE /user/remove_attachment.
-
#show ⇒ Object
GET /users/:id.
-
#unlock ⇒ Object
PATCH /users/:id/unlock.
-
#update ⇒ Object
PATCH /users/:id.
-
#user ⇒ Object
render a single user.
Methods inherited from ApplicationController
#admin_in!, #doctor_in!, #powered_in!, #secretary_in!, #translate_errors
Instance Method Details
#create ⇒ Object
POST /users
Add a new user manually
146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/controllers/users_controller.rb', line 146 def create @user = User.new(external_user_params) @user.label = "#{external_user_params[:lastname]} #{external_user_params[:name]}" if @user.save @users = User.where('label ilike ?', "%#{@user.label}%").order('label asc') @pagy, @users = pagy(@users, link_extra: "data-turbo-frame='users'") redirect_to users_url else render :new end end |
#destroy ⇒ Object
DELETE /users/:id
set an User as locked
-
set @user with #set_user method
-
use User#disable! method for lock the User
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/users_controller.rb', line 52 def destroy current_user = @user @user. = current_user.label if @user.disable! flash.now[:success] = 'Disattivazione avvenuta con successo' render turbo_stream: [ turbo_stream.replace("user_#{@user.id}", partial: 'users/user', locals: {user: @user, current_user: current_user}), turbo_stream.replace(:flashes, partial: "flashes") ] else flash.now[:error] = write_errors(@user) render turbo_stream: turbo_stream.replace(:flashes, partial: "flashes") end end |
#edit_external_user ⇒ Object
GET /user/:id/edit_external
render the form for make an external user
125 126 127 |
# File 'app/controllers/users_controller.rb', line 125 def edit_external_user render partial: 'form' end |
#external_user ⇒ Object
GET
130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/controllers/users_controller.rb', line 130 def external_user if request.post? create elsif request.put? @user.label = "#{external_user_params[:lastname]} #{external_user_params[:name]}" if @user.update(external_user_params) redirect_to users_url else render :edit_external_user end end end |
#index ⇒ Object
GET /users
render the list the all User
-
set @users_filtered with #users
-
set @pagy, @user for the @users pagination
18 19 20 |
# File 'app/controllers/users_controller.rb', line 18 def index # index end |
#list ⇒ Object
GET /users/list
render the list the all User
-
set @users_filtered with #users
-
set @pagy, @user for the @users pagination
28 29 30 |
# File 'app/controllers/users_controller.rb', line 28 def list @pagy, @users = pagy(users, link_extra: "data-turbo-frame='users'") end |
#new ⇒ Object
117 118 119 |
# File 'app/controllers/users_controller.rb', line 117 def new @user = User.new end |
#notify ⇒ Nil
PUT /user/:id/notify
Send notify for the user’s analisy events and user’s vitis events
105 106 107 108 109 110 |
# File 'app/controllers/users_controller.rb', line 105 def notify return if @user.email.blank? Notifier.user_event_analisys(@user, @user.events.future.analisys.first).deliver_now if @user.events.future.analisys.present? Notifier.user_event_visit(@user, @user.events.future.visits.first).deliver_now if @user.events.future.visits.present? end |
#remove_attachment ⇒ Object
DELETE /user/remove_attachment
delete the assegnazione file from user
167 168 169 170 |
# File 'app/controllers/users_controller.rb', line 167 def @user.assegnazione.purge if @user.assegnazione.attached? render :show end |
#show ⇒ Object
40 41 42 43 44 |
# File 'app/controllers/users_controller.rb', line 40 def show @analisys = @user.events.analisys.future.to_a.uniq(&:id) @visits = @user.events.visit.future.to_a.uniq(&:id) @audits = @user.audits end |
#unlock ⇒ Object
PATCH /users/:id/unlock
Set an User as unlock
-
set @user with #set_user method
-
use User#enable! method for unlock the User
render /users/show
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/users_controller.rb', line 73 def unlock if @user.enable! flash.now[:success] = 'Attivazione avvenuta con successo' render turbo_stream: [ turbo_stream.replace("user_#{@user.id}", partial: 'users/user', locals: {user: @user, current_user: current_user}), turbo_stream.replace("user_#{@user.id}_show", partial: 'users/show', locals: {user: @user, analisys: @user.events.analisys.future.to_a.uniq(&:id), visits: @user.events.visit.future.to_a.uniq(&:id), view: @view}), turbo_stream.replace(:flashes, partial: "flashes") ] else flash.now[:error] = write_errors(@user) render turbo_stream: turbo_stream.replace(:flashes, partial: "flashes") end end |
#update ⇒ Object
PATCH /users/:id
try to update an User
-
set @user with #set_user method
-
set @response true if @user is updated
93 94 95 96 97 98 99 |
# File 'app/controllers/users_controller.rb', line 93 def update if @user.update(user_params) render :show, status: :ok else render json: { error: translate_errors(@user.errors, scope: 'user').join(', '), status: :unprocessable_entity }, status: 500 end end |
#user ⇒ Object
render a single user
159 160 161 |
# File 'app/controllers/users_controller.rb', line 159 def user render @user end |