Class: User::RolesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/lesli_guard/user/roles_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/lesli_guard/user/roles_controller.rb', line 45

def create

    # get the role to assign to the user
    role = current_user..roles.find(user_role_params[:id])

    unless current_user.can_work_with_role?(role)
        return respond_with_error(I18n.t("core.roles.messages_danger_cannot_assign_level_of_role"))
    end

    # create new role for user if it does not exist
    user_role = @user.result.powers.with_deleted.find_or_create_by({ role: role })

    # if role was soft deleted we need to recover it instead of create a new record
    user_role.recover if user_role.deleted?

    respond_with_successful()

    #User.log_activity_create_user_role(current_user, @user, role)
end

#destroyObject

DELETE /user/:user_id/roles/:role_id



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/lesli_guard/user/roles_controller.rb', line 66

def destroy

    # get the role to assign to the user
    role = current_user..roles.find(@user_role.role.id)

    unless current_user.can_work_with_role?(role)
        return respond_with_error(I18n.t("core.roles.messages_danger_cannot_modify_role"))
    end

    @user_role.destroy

    respond_with_successful()

    #User.log_activity_destroy_user_role(current_user, @user, role)
end

#indexObject

Get the list of assigned roles of the requested user we filter the roles according to the object level permission of the current_user



41
42
43
# File 'app/controllers/lesli_guard/user/roles_controller.rb', line 41

def index 
    respond_with_successful(@user.available_roles)
end