Skip to content

Implementation of User-level Actions #382

@romaninsh

Description

@romaninsh

Although on the basic level models can perform "CRUD" operations (create, read, update and delete), in reality there are many other actions.

Currently you have to create method inside a model, but it's hard for the other components to discover which methods are safe to execute.

I propose we implement hook getActions that would return array of special action objects. So your model Package could be like this:

$this->addHook('getActions', function($m) {
    return [
        'delivered' => new Action("Signed for Delivery", function($m){ 
            return $m->save('delivered', true);  
         })
   ] 
});

Second argument is optional and if not specified then $m->delivered() is called. Class Action could be initially quite simple, but then we can add all sorts of properties to it - is at a dangerous action? What arguments are required? etc.

This action would be safe to exported through UI or API frameworks as a button or a POST end-point.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions