Module: Lesli::Interfaces::Controllers::Actions

Defined in:
app/controllers/lesli/interfaces/controllers/actions.rb

Instance Method Summary collapse

Instance Method Details

#createJson

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

Examples:

# Executing this controller's action from javascript's frontend
let ticket_id = 1;
let data = {
    ticket_action: {
        content: "This is a comment on a ticket!"
    }
};
this.http.post(`127.0.0.1/help/tickets/${ticket_id}/actions`, data);

Returns:

  • (Json)

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



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/controllers/lesli/interfaces/controllers/actions.rb', line 94

def create
    action_model = action_model() # If there is a custom action model, it must be returned in this method
    cloud_object_model = action_model.cloud_object_model

    set_cloud_object
    new_action_params = action_params.merge(
        user_creator: current_user
    )

    action = @cloud_object.actions.new(new_action_params)
    if action.save
        if block_given?
            yield(cloud_object, action)
        else
            respond_with_successful(action.show(current_user))
        end
    else
        respond_with_error(action.errors.full_messages)
    end
end

#destroyJson

Returns A response that contains wheter the action was deleted or not. If it is not successful, it returns an error message.

Examples:

# Executing this controller's action from javascript's frontend
let ticket_id = 1;
let action_id = 22;
this.http.delete(`127.0.0.1/help/tickets/${ticket_id}/actions/${action_id}`);

Returns:

  • (Json)

    A response that contains wheter the action was deleted or not. If it is not successful, it returns an error message



150
151
152
153
154
155
156
157
158
159
# File 'app/controllers/lesli/interfaces/controllers/actions.rb', line 150

def destroy
    set_action
    return respond_with_not_found unless @action
    
    if @action.destroy
        respond_with_successful
    else
        respond_with_error(@action.errors.full_messages.to_sentence)
    end
end

#indexJson

Returns Json that contains a list of all actions related to a cloud_object.

Examples:

# Executing this controller's action from javascript's frontend
let ticket_id = 1;
this.http.get(`127.0.0.1/help/tickets/${ticket_id}/actions`);

Returns:

  • (Json)

    Json that contains a list of all actions related to a cloud_object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/lesli/interfaces/controllers/actions.rb', line 46

def index
    set_cloud_object()
    action_model = action_model() # If there is a custom action model, it must be returned in this method
    cloud_object_model = action_model.cloud_object_model
    
    @actions = action_model.index(current_user, @cloud_object)
    if block_given?
        yield(@actions)
    else
        respond_with_successful(@actions)
    end
end

#showJSON

Returns The json information about the selected action.

Examples:

# Executing this controller's action from javascript's frontend
let ticket_id = 1;
let action_id = 5;
this.http.get(`127.0.0.1/help/tickets/${ticket_id}/actions/${action_id}`);

Returns:

  • (JSON)

    The json information about the selected action



68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/lesli/interfaces/controllers/actions.rb', line 68

def show
    set_action
    return respond_with_not_found unless @action

    if block_given?
        yield(@action)
    else
        return respond_with_successful(@action)
    end
end

#updateJson

Returns Json that contains wheter the update of the action was successful or not. If it is not successful, it returs an error message.

Examples:

# Executing this controller's action from javascript's frontend
let ticket_id = 1;
let action_id = 22;
data = {
    action: {
        content: "This is the new content of the action"
    }
};
this.http.patch(`127.0.0.1/help/tickets/${ticket_id}/actions/${action_id}`, data);

Returns:

  • (Json)

    Json that contains wheter the update of the action was successful or not. If it is not successful, it returs an error message



130
131
132
133
134
135
136
137
138
139
140
# File 'app/controllers/lesli/interfaces/controllers/actions.rb', line 130

def update
    set_action
    return respond_with_not_found unless @action
    return respond_with_unauthorized unless @action.is_editable_by?(current_user)

    if @action.update(action_params)
        respond_with_successful(@action.show(current_user))
    else
        respond_with_error(@action.errors.full_messages.to_sentence)
    end
end