Class: LesliShield::RolesController

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

Instance Method Summary collapse

Instance Method Details

#createJson

Returns Json that contains wheter the creation of the role was successful or not. If it is not successful, it returns an error message.

Examples:

# Executing this controller's action from javascript's frontend
let data = {
    role: {
        name: "Change Request"
    }
};
this.http.post('127.0.0.1/house/roles', data);

Returns:

  • (Json)

    Json that contains wheter the creation of the role was successful or not. If it is not successful, it returns an error message



86
87
88
89
90
91
92
93
94
95
# File 'app/controllers/lesli_shield/roles_controller.rb', line 86

def create

    role = RoleService.new(current_user).create(role_params)

    if role.successful?
        respond_with_successful(role.result) 
    else
        respond_with_error(role.errors_as_sentence)
    end
end

#deployObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/lesli_shield/roles_controller.rb', line 37

def deploy
    pp params[:id]
    pp params[:id]
    pp params[:id]
    pp params[:id]

    RolePrivilegeService.new.synchronize(Lesli::Role.first)

    respond_with_lesli(
        :turbo => stream_notification_success("success")
    )
end

#destroyJson

Returns Json that contains wheter the role was successfully deleted or not. If it it not successful, it returns an error message.

Returns:

  • (Json)

    Json that contains wheter the role was successfully deleted or not. If it it not successful, it returns an error message



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'app/controllers/lesli_shield/roles_controller.rb', line 124

def destroy
    return respond_with_not_found unless @role.found?

    # Validation: check if the role has still associated users
    if @role.has_users?
        return respond_with_error(I18n.t("core.roles.messages_danger_users_assigned_validation"))
    end

    @role.destroy

    # Check if the deletion went ok
    unless @role.successful?
        return respond_with_error(@role.errors)
    end

    respond_with_successful
end

#editHTML

Returns HTML view for editing the role.

Examples:

# Executing this controller's action from javascript's frontend
let role_id = 3;
this.url.go(`/roles/${role_id}/edit`)

Returns:

  • (HTML)

    HTML view for editing the role



72
73
# File 'app/controllers/lesli_shield/roles_controller.rb', line 72

def edit
end

#indexObject



50
51
52
# File 'app/controllers/lesli_shield/roles_controller.rb', line 50

def index
    @roles = respond_with_pagination(Lesli::RoleService.new(current_user, query).index)
end

#newHTML

Returns HTML view for creating a new role.

Examples:

# Executing this controller's action from javascript's frontend
this.url.go('/roles/new')

Returns:

  • (HTML)

    HTML view for creating a new role



63
64
# File 'app/controllers/lesli_shield/roles_controller.rb', line 63

def new
end

#optionsJSON

Returns:

  • (JSON)


144
145
146
# File 'app/controllers/lesli_shield/roles_controller.rb', line 144

def options
    respond_with_successful(RoleService.new(current_user).options)
end

#showObject



54
55
56
# File 'app/controllers/lesli_shield/roles_controller.rb', line 54

def show
    @role = @role.show
end

#updateJson

Returns Json that contains wheter the role was successfully updated or not. If it it not successful, it returns an error message.

Returns:

  • (Json)

    Json that contains wheter the role was successfully updated or not. If it it not successful, it returns an error message



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/controllers/lesli_shield/roles_controller.rb', line 101

def update
    # Respond with 404 if role was not found
    return respond_with_not_found unless @role.found?

    # check if current user can work with role
    # unless current_user.can_work_with_role?(@role.resource)
    #     return respond_with_error(I18n.t("core.roles.messages_danger_updating_role_object_level_permission_too_high"))
    # end

    # Update role information
    @role.update(role_params)

    # check if the update went OK
    if @role.successful?
        respond_with_lesli(:turbo => stream_notification_success("Role updated successfully!"))
    else
        respond_with_lesli(:turbo => stream_notification_danger(@role.errors_as_sentence))
    end
end