mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 03:37:56 +01:00
Add users management to site settings (#126)
This commit is contained in:
committed by
GitHub
parent
bc15140512
commit
37fb99a868
36
app/controllers/users_controller.rb
Normal file
36
app/controllers/users_controller.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
class UsersController < ApplicationController
|
||||
before_action :authenticate_user!, only: [:index, :update]
|
||||
|
||||
def index
|
||||
authorize User
|
||||
|
||||
@users = User
|
||||
.all
|
||||
.order(role: :desc)
|
||||
|
||||
render json: @users
|
||||
end
|
||||
|
||||
def update
|
||||
@user = User.find(params[:id])
|
||||
authorize @user
|
||||
|
||||
@user.assign_attributes user_update_params
|
||||
|
||||
if @user.save
|
||||
render json: @user
|
||||
else
|
||||
render json: {
|
||||
error: @user.errors.full_messages
|
||||
}, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_update_params
|
||||
params
|
||||
.require(:user)
|
||||
.permit(policy(@user).permitted_attributes_for_update)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user