Class: LesliShield::UsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/lesli_shield/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /users



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/lesli_shield/users_controller.rb', line 64

def create
    @user = User.new(user_params)

    if @user.save
        respond_with_stream(
            stream_notification_success('User was successfully created.')
        )
    else
        respond_with_stream(
            stream_notification_danger(@user.errors.full_messages.to_sentence)
        )
    end
end

#destroyObject

DELETE /users/1



97
98
99
100
# File 'app/controllers/lesli_shield/users_controller.rb', line 97

def destroy
    @user.destroy!
    redirect_to(users_path, notice: "User was successfully destroyed.", status: :see_other)
end

#editObject

GET /users/1/edit



60
61
# File 'app/controllers/lesli_shield/users_controller.rb', line 60

def edit
end

#indexObject

GET /users



38
39
40
# File 'app/controllers/lesli_shield/users_controller.rb', line 38

def index
    @users = respond_with_pagination(Lesli::UserService.new(current_user, query).index(params))
end

#newObject

GET /users/new



55
56
57
# File 'app/controllers/lesli_shield/users_controller.rb', line 55

def new
    @user = User.new
end

#showObject

GET /users/1



43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/lesli_shield/users_controller.rb', line 43

def show
    @user_roles = @user.result.roles
    @activities = @user.result.logs
        .order(id: :desc)
        .select(:id, :operation, :description, Date2.new.db_column('created_at', as:'date'))
        .limit(7)
        .as_json
    @sessions = @user.result.sessions
    @user = @user.show
end

#updateObject

PATCH/PUT /users/1



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/lesli_shield/users_controller.rb', line 79

def update

    # update the user information
    @user.update(user_params)

    # check saved
    if @user.successful?
        respond_with_lesli(
            :turbo => stream_notification_success("User updated successfully!")
        )
    else 
        respond_with_lesli(
            :turbo => stream_notification_danger(@user.errors_as_sentence)
        )
    end
end