Components can now be supplied meta data
This commit is contained in:
@@ -62,6 +62,13 @@ final class AddComponentCommand
|
|||||||
*/
|
*/
|
||||||
public $enabled;
|
public $enabled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON meta data for the component.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
public $meta;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The validation rules.
|
* The validation rules.
|
||||||
*
|
*
|
||||||
@@ -75,6 +82,7 @@ final class AddComponentCommand
|
|||||||
'order' => 'nullable|int',
|
'order' => 'nullable|int',
|
||||||
'group_id' => 'nullable|int',
|
'group_id' => 'nullable|int',
|
||||||
'enabled' => 'nullable|bool',
|
'enabled' => 'nullable|bool',
|
||||||
|
'meta' => 'nullable|string',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,10 +95,11 @@ final class AddComponentCommand
|
|||||||
* @param int $order
|
* @param int $order
|
||||||
* @param int $group_id
|
* @param int $group_id
|
||||||
* @param bool $enabled
|
* @param bool $enabled
|
||||||
|
* @param string|null $meta
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct($name, $description, $status, $link, $order, $group_id, $enabled)
|
public function __construct($name, $description, $status, $link, $order, $group_id, $enabled, $meta)
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->description = $description;
|
$this->description = $description;
|
||||||
@@ -99,5 +108,6 @@ final class AddComponentCommand
|
|||||||
$this->order = $order;
|
$this->order = $order;
|
||||||
$this->group_id = $group_id;
|
$this->group_id = $group_id;
|
||||||
$this->enabled = $enabled;
|
$this->enabled = $enabled;
|
||||||
|
$this->meta = $meta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,13 @@ final class UpdateComponentCommand
|
|||||||
*/
|
*/
|
||||||
public $enabled;
|
public $enabled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON meta data for the component.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
public $meta;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The validation rules.
|
* The validation rules.
|
||||||
*
|
*
|
||||||
@@ -84,6 +91,7 @@ final class UpdateComponentCommand
|
|||||||
'order' => 'nullable|int',
|
'order' => 'nullable|int',
|
||||||
'group_id' => 'nullable|int',
|
'group_id' => 'nullable|int',
|
||||||
'enabled' => 'nullable|bool',
|
'enabled' => 'nullable|bool',
|
||||||
|
'meta' => 'nullable|string',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,10 +105,11 @@ final class UpdateComponentCommand
|
|||||||
* @param int $order
|
* @param int $order
|
||||||
* @param int $group_id
|
* @param int $group_id
|
||||||
* @param bool $enabled
|
* @param bool $enabled
|
||||||
|
* @param string|null $meta
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(Component $component, $name, $description, $status, $link, $order, $group_id, $enabled)
|
public function __construct(Component $component, $name, $description, $status, $link, $order, $group_id, $enabled, $meta)
|
||||||
{
|
{
|
||||||
$this->component = $component;
|
$this->component = $component;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
@@ -110,5 +119,6 @@ final class UpdateComponentCommand
|
|||||||
$this->order = $order;
|
$this->order = $order;
|
||||||
$this->group_id = $group_id;
|
$this->group_id = $group_id;
|
||||||
$this->enabled = $enabled;
|
$this->enabled = $enabled;
|
||||||
|
$this->meta = $meta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ class AddComponentCommandHandler
|
|||||||
'enabled' => $command->enabled,
|
'enabled' => $command->enabled,
|
||||||
'order' => $command->order,
|
'order' => $command->order,
|
||||||
'group_id' => $command->group_id,
|
'group_id' => $command->group_id,
|
||||||
|
'meta' => $command->meta,
|
||||||
];
|
];
|
||||||
|
|
||||||
return array_filter($params, function ($val) {
|
return array_filter($params, function ($val) {
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ class UpdateComponentCommandHandler
|
|||||||
'enabled' => $command->enabled,
|
'enabled' => $command->enabled,
|
||||||
'order' => $command->order,
|
'order' => $command->order,
|
||||||
'group_id' => $command->group_id,
|
'group_id' => $command->group_id,
|
||||||
|
'meta' => $command->meta,
|
||||||
];
|
];
|
||||||
|
|
||||||
return array_filter($params, function ($val) {
|
return array_filter($params, function ($val) {
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ class ReportIncidentCommandHandler
|
|||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
|
null,
|
||||||
null
|
null
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ class ComponentController extends AbstractApiController
|
|||||||
Binput::get('link'),
|
Binput::get('link'),
|
||||||
Binput::get('order'),
|
Binput::get('order'),
|
||||||
Binput::get('group_id'),
|
Binput::get('group_id'),
|
||||||
(bool) Binput::get('enabled', true)
|
(bool) Binput::get('enabled', true),
|
||||||
|
Binput::get('meta', null)
|
||||||
));
|
));
|
||||||
} catch (QueryException $e) {
|
} catch (QueryException $e) {
|
||||||
throw new BadRequestHttpException();
|
throw new BadRequestHttpException();
|
||||||
@@ -118,7 +119,8 @@ class ComponentController extends AbstractApiController
|
|||||||
Binput::get('link'),
|
Binput::get('link'),
|
||||||
Binput::get('order'),
|
Binput::get('order'),
|
||||||
Binput::get('group_id'),
|
Binput::get('group_id'),
|
||||||
(bool) Binput::get('enabled', true)
|
(bool) Binput::get('enabled', true),
|
||||||
|
Binput::get('meta', null)
|
||||||
));
|
));
|
||||||
} catch (QueryException $e) {
|
} catch (QueryException $e) {
|
||||||
throw new BadRequestHttpException();
|
throw new BadRequestHttpException();
|
||||||
|
|||||||
@@ -134,7 +134,8 @@ class ComponentController extends Controller
|
|||||||
$componentData['link'],
|
$componentData['link'],
|
||||||
$componentData['order'],
|
$componentData['order'],
|
||||||
$componentData['group_id'],
|
$componentData['group_id'],
|
||||||
$componentData['enabled']
|
$componentData['enabled'],
|
||||||
|
null // Meta data cannot be supplied through the dashboard yet.
|
||||||
));
|
));
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
return cachet_redirect('dashboard.components.edit', [$component->id])
|
return cachet_redirect('dashboard.components.edit', [$component->id])
|
||||||
@@ -187,7 +188,8 @@ class ComponentController extends Controller
|
|||||||
$componentData['link'],
|
$componentData['link'],
|
||||||
$componentData['order'],
|
$componentData['order'],
|
||||||
$componentData['group_id'],
|
$componentData['group_id'],
|
||||||
$componentData['enabled']
|
$componentData['enabled'],
|
||||||
|
null // Meta data cannot be supplied through the dashboard yet.
|
||||||
));
|
));
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
return cachet_redirect('dashboard.components.create')
|
return cachet_redirect('dashboard.components.create')
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class Component extends Model implements HasPresenter
|
|||||||
'description' => '',
|
'description' => '',
|
||||||
'link' => '',
|
'link' => '',
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
|
'meta' => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,6 +51,7 @@ class Component extends Model implements HasPresenter
|
|||||||
'link' => 'string',
|
'link' => 'string',
|
||||||
'group_id' => 'int',
|
'group_id' => 'int',
|
||||||
'enabled' => 'bool',
|
'enabled' => 'bool',
|
||||||
|
'meta' => 'json',
|
||||||
'deleted_at' => 'date',
|
'deleted_at' => 'date',
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -67,6 +69,7 @@ class Component extends Model implements HasPresenter
|
|||||||
'order',
|
'order',
|
||||||
'group_id',
|
'group_id',
|
||||||
'enabled',
|
'enabled',
|
||||||
|
'meta',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Cachet.
|
||||||
|
*
|
||||||
|
* (c) Alt Three Services Limited
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AlterTableComponentsAddMetaColumn extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('components', function (Blueprint $table) {
|
||||||
|
$table->longText('meta')->nullable()->default(null)->after('enabled');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('components', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('meta');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -84,6 +84,31 @@ class ComponentTest extends AbstractApiTestCase
|
|||||||
$this->assertResponseOk();
|
$this->assertResponseOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPostComponentWithMetaData()
|
||||||
|
{
|
||||||
|
$this->beUser();
|
||||||
|
|
||||||
|
$this->post('/api/v1/components', [
|
||||||
|
'name' => 'Foo',
|
||||||
|
'description' => 'Bar',
|
||||||
|
'status' => 1,
|
||||||
|
'link' => 'http://example.com',
|
||||||
|
'order' => 1,
|
||||||
|
'group_id' => 1,
|
||||||
|
'enabled' => true,
|
||||||
|
'meta' => [
|
||||||
|
'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->seeJson([
|
||||||
|
'meta' => [
|
||||||
|
'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
$this->assertResponseOk();
|
||||||
|
}
|
||||||
|
|
||||||
public function testPostDisabledComponent()
|
public function testPostDisabledComponent()
|
||||||
{
|
{
|
||||||
$this->beUser();
|
$this->beUser();
|
||||||
@@ -122,6 +147,31 @@ class ComponentTest extends AbstractApiTestCase
|
|||||||
$this->assertResponseOk();
|
$this->assertResponseOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPutComponentWithMetaData()
|
||||||
|
{
|
||||||
|
$this->beUser();
|
||||||
|
$component = factory('CachetHQ\Cachet\Models\Component')->create([
|
||||||
|
'meta' => [
|
||||||
|
'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->put('/api/v1/components/1', [
|
||||||
|
'meta' => [
|
||||||
|
'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0',
|
||||||
|
'foo' => 'bar',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->seeJson([
|
||||||
|
'meta' => [
|
||||||
|
'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0',
|
||||||
|
'foo' => 'bar',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
$this->assertResponseOk();
|
||||||
|
}
|
||||||
|
|
||||||
public function testDeleteComponent()
|
public function testDeleteComponent()
|
||||||
{
|
{
|
||||||
$this->beUser();
|
$this->beUser();
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class AddComponentCommandTest extends AbstractTestCase
|
|||||||
'order' => 0,
|
'order' => 0,
|
||||||
'group_id' => 0,
|
'group_id' => 0,
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
|
'meta' => null,
|
||||||
];
|
];
|
||||||
$object = new AddComponentCommand(
|
$object = new AddComponentCommand(
|
||||||
$params['name'],
|
$params['name'],
|
||||||
@@ -44,7 +45,8 @@ class AddComponentCommandTest extends AbstractTestCase
|
|||||||
$params['link'],
|
$params['link'],
|
||||||
$params['order'],
|
$params['order'],
|
||||||
$params['group_id'],
|
$params['group_id'],
|
||||||
$params['enabled']
|
$params['enabled'],
|
||||||
|
$params['meta']
|
||||||
);
|
);
|
||||||
|
|
||||||
return compact('params', 'object');
|
return compact('params', 'object');
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class UpdateComponentCommandTest extends AbstractTestCase
|
|||||||
'order' => 0,
|
'order' => 0,
|
||||||
'group_id' => 0,
|
'group_id' => 0,
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
|
'meta' => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
$object = new UpdateComponentCommand(
|
$object = new UpdateComponentCommand(
|
||||||
@@ -48,7 +49,8 @@ class UpdateComponentCommandTest extends AbstractTestCase
|
|||||||
$params['link'],
|
$params['link'],
|
||||||
$params['order'],
|
$params['order'],
|
||||||
$params['group_id'],
|
$params['group_id'],
|
||||||
$params['enabled']
|
$params['enabled'],
|
||||||
|
$params['meta']
|
||||||
);
|
);
|
||||||
|
|
||||||
return compact('params', 'object');
|
return compact('params', 'object');
|
||||||
|
|||||||
Reference in New Issue
Block a user