From 27226dc211e6b8406b12ca3581862083757a37a6 Mon Sep 17 00:00:00 2001 From: Anton Shevchuk Date: Fri, 15 Sep 2017 17:06:10 +0300 Subject: [PATCH 1/4] Removed `ValidatorFormException` --- application/modules/options/controllers/crud/post.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/modules/options/controllers/crud/post.php b/application/modules/options/controllers/crud/post.php index 301cf03..76579ba 100644 --- a/application/modules/options/controllers/crud/post.php +++ b/application/modules/options/controllers/crud/post.php @@ -28,7 +28,7 @@ try { $crud->createOne($data); - Messages::addSuccess("Record was created"); + Messages::addSuccess('Record was created'); return [ 'row' => $data, From da1c278f00145921fac81509b2c8a708c033dfbd Mon Sep 17 00:00:00 2001 From: Anton Shevchuk Date: Tue, 26 Sep 2017 13:14:29 +0300 Subject: [PATCH 2/4] Create `api/options` endpoint Added `userId` to table --- application/models/Options/Row.php | 27 +++++- .../modules/api/controllers/options.php | 83 +++++++++++++++++++ .../modules/options/controllers/crud.php | 4 +- .../modules/options/controllers/crud/post.php | 2 +- .../modules/options/controllers/grid.php | 1 + application/modules/options/views/crud.phtml | 14 +++- application/modules/options/views/grid.phtml | 6 +- .../20170317111112_module_options.php | 5 ++ 8 files changed, 130 insertions(+), 12 deletions(-) create mode 100644 application/modules/api/controllers/options.php diff --git a/application/models/Options/Row.php b/application/models/Options/Row.php index f643f7d..f4aedd2 100644 --- a/application/models/Options/Row.php +++ b/application/models/Options/Row.php @@ -8,20 +8,34 @@ namespace Application\Options; +use Bluz\Proxy\Auth; use Bluz\Validator\Traits\Validator; +use Application\Users; /** * Options Row * + * @package Application\Options + * * @property string $namespace * @property string $key + * @property integer $userId * @property string $value * @property string $description * @property string $created * @property string $updated * - * @category Application - * @package Options + * @SWG\Definition(definition="options", title="option", required={"namespace", "key"}) + * @SWG\Property(property="namespace", type="string", description="Options namespace", example="default") + * @SWG\Property(property="key", type="string", description="Key", example="Some key") + * @SWG\Property(property="userId", type="integer", description="Author ID", example=2) + * @SWG\Property(property="value", type="string", description="Value", example="Some Value") + * @SWG\Property(property="description", type="string", description="Description", example="Some description for key") + * @SWG\Property(property="created", type="string", format="date-time", description="Created date", + * example="2017-03-17 19:06:28") + * @SWG\Property(property="updated", type="string", format="date-time", description="Last updated date", + * example="2017-03-17 19:06:28") + */ class Row extends \Bluz\Db\Row { @@ -33,7 +47,7 @@ class Row extends \Bluz\Db\Row protected function afterRead() { if ($this->value) { - $this->value = unserialize($this->value); + $this->value = unserialize($this->value, ['allowed_classes' => false]); } } @@ -65,6 +79,13 @@ function () { }, 'Key name is already exists' ); + + /* @var \Application\Users\Row $user */ + if ($user = Auth::getIdentity()) { + $this->userId = $user->id; + } else { + $this->userId = Users\Table::SYSTEM_USER; + } } /** diff --git a/application/modules/api/controllers/options.php b/application/modules/api/controllers/options.php new file mode 100644 index 0000000..56bb741 --- /dev/null +++ b/application/modules/api/controllers/options.php @@ -0,0 +1,83 @@ +get('system', 'rest/get') + ->acl('Options/Read'); + $rest->post('system', 'rest/post') + ->acl('Options/Edit'); + $rest->put('system', 'rest/put') + ->acl('Options/Edit'); + $rest->patch('system', 'rest/put') + ->acl('Options/Edit'); + $rest->delete('system', 'rest/delete') + ->acl('Options/Edit'); + + return $rest->run(); +}; diff --git a/application/modules/options/controllers/crud.php b/application/modules/options/controllers/crud.php index 5d288b4..a9cfa84 100644 --- a/application/modules/options/controllers/crud.php +++ b/application/modules/options/controllers/crud.php @@ -25,8 +25,8 @@ $crud = new Crud(Options\Crud::getInstance()); $crud->get('system', 'crud/get'); - $crud->post('options', 'crud/post'); - $crud->put('system', 'crud/put'); + $crud->post('options', 'crud/post')->fields(['namespace', 'key', 'value', 'description']); + $crud->put('system', 'crud/put')->fields(['value', 'description']); $crud->delete('system', 'crud/delete'); return $crud->run(); diff --git a/application/modules/options/controllers/crud/post.php b/application/modules/options/controllers/crud/post.php index 76579ba..4a57d25 100644 --- a/application/modules/options/controllers/crud/post.php +++ b/application/modules/options/controllers/crud/post.php @@ -28,7 +28,7 @@ try { $crud->createOne($data); - Messages::addSuccess('Record was created'); + Messages::addSuccess('The record was successfully created'); return [ 'row' => $data, diff --git a/application/modules/options/controllers/grid.php b/application/modules/options/controllers/grid.php index c20b0d3..928d91f 100644 --- a/application/modules/options/controllers/grid.php +++ b/application/modules/options/controllers/grid.php @@ -27,6 +27,7 @@ ] ); $grid = new Options\Grid(); + $grid->processSource(); $this->assign('grid', $grid); }; diff --git a/application/modules/options/views/crud.phtml b/application/modules/options/views/crud.phtml index 63040dd..f7020b3 100644 --- a/application/modules/options/views/crud.phtml +++ b/application/modules/options/views/crud.phtml @@ -11,16 +11,24 @@