Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components can now be supplied meta data #2263

Merged
merged 1 commit into from
Dec 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions app/Bus/Commands/Component/AddComponentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ final class AddComponentCommand
*/
public $enabled;

/**
* JSON meta data for the component.
*
* @var string|null
*/
public $meta;

/**
* The validation rules.
*
Expand All @@ -75,22 +82,24 @@ final class AddComponentCommand
'order' => 'nullable|int',
'group_id' => 'nullable|int',
'enabled' => 'nullable|bool',
'meta' => 'nullable|string',
];

/**
* Create a new add component command instance.
*
* @param string $name
* @param string $description
* @param int $status
* @param string $link
* @param int $order
* @param int $group_id
* @param bool $enabled
* @param string $name
* @param string $description
* @param int $status
* @param string $link
* @param int $order
* @param int $group_id
* @param bool $enabled
* @param string|null $meta
*
* @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->description = $description;
Expand All @@ -99,5 +108,6 @@ public function __construct($name, $description, $status, $link, $order, $group_
$this->order = $order;
$this->group_id = $group_id;
$this->enabled = $enabled;
$this->meta = $meta;
}
}
12 changes: 11 additions & 1 deletion app/Bus/Commands/Component/UpdateComponentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ final class UpdateComponentCommand
*/
public $enabled;

/**
* JSON meta data for the component.
*
* @var string|null
*/
public $meta;

/**
* The validation rules.
*
Expand All @@ -84,6 +91,7 @@ final class UpdateComponentCommand
'order' => 'nullable|int',
'group_id' => 'nullable|int',
'enabled' => 'nullable|bool',
'meta' => 'nullable|string',
];

/**
Expand All @@ -97,10 +105,11 @@ final class UpdateComponentCommand
* @param int $order
* @param int $group_id
* @param bool $enabled
* @param string|null $meta
*
* @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->name = $name;
Expand All @@ -110,5 +119,6 @@ public function __construct(Component $component, $name, $description, $status,
$this->order = $order;
$this->group_id = $group_id;
$this->enabled = $enabled;
$this->meta = $meta;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ protected function filter(AddComponentCommand $command)
'enabled' => $command->enabled,
'order' => $command->order,
'group_id' => $command->group_id,
'meta' => $command->meta,
];

return array_filter($params, function ($val) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ protected function filter(UpdateComponentCommand $command)
'enabled' => $command->enabled,
'order' => $command->order,
'group_id' => $command->group_id,
'meta' => $command->meta,
];

return array_filter($params, function ($val) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function handle(ReportIncidentCommand $command)
null,
null,
null,
null,
null
));
}
Expand Down
6 changes: 4 additions & 2 deletions app/Http/Controllers/Api/ComponentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public function postComponents()
Binput::get('link'),
Binput::get('order'),
Binput::get('group_id'),
(bool) Binput::get('enabled', true)
(bool) Binput::get('enabled', true),
Binput::get('meta', null)
));
} catch (QueryException $e) {
throw new BadRequestHttpException();
Expand Down Expand Up @@ -118,7 +119,8 @@ public function putComponent(Component $component)
Binput::get('link'),
Binput::get('order'),
Binput::get('group_id'),
(bool) Binput::get('enabled', true)
(bool) Binput::get('enabled', true),
Binput::get('meta', null)
));
} catch (QueryException $e) {
throw new BadRequestHttpException();
Expand Down
6 changes: 4 additions & 2 deletions app/Http/Controllers/Dashboard/ComponentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ public function updateComponentAction(Component $component)
$componentData['link'],
$componentData['order'],
$componentData['group_id'],
$componentData['enabled']
$componentData['enabled'],
null // Meta data cannot be supplied through the dashboard yet.
));
} catch (ValidationException $e) {
return cachet_redirect('dashboard.components.edit', [$component->id])
Expand Down Expand Up @@ -187,7 +188,8 @@ public function createComponentAction()
$componentData['link'],
$componentData['order'],
$componentData['group_id'],
$componentData['enabled']
$componentData['enabled'],
null // Meta data cannot be supplied through the dashboard yet.
));
} catch (ValidationException $e) {
return cachet_redirect('dashboard.components.create')
Expand Down
3 changes: 3 additions & 0 deletions app/Models/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Component extends Model implements HasPresenter
'description' => '',
'link' => '',
'enabled' => true,
'meta' => null,
];

/**
Expand All @@ -50,6 +51,7 @@ class Component extends Model implements HasPresenter
'link' => 'string',
'group_id' => 'int',
'enabled' => 'bool',
'meta' => 'json',
'deleted_at' => 'date',
];

Expand All @@ -67,6 +69,7 @@ class Component extends Model implements HasPresenter
'order',
'group_id',
'enabled',
'meta',
];

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
});
}
}
50 changes: 50 additions & 0 deletions tests/Api/ComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,31 @@ public function testPostComponentWithoutEnabledField()
$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()
{
$this->beUser();
Expand Down Expand Up @@ -122,6 +147,31 @@ public function testPutComponent()
$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()
{
$this->beUser();
Expand Down
4 changes: 3 additions & 1 deletion tests/Bus/Commands/Component/AddComponentCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected function getObjectAndParams()
'order' => 0,
'group_id' => 0,
'enabled' => true,
'meta' => null,
];
$object = new AddComponentCommand(
$params['name'],
Expand All @@ -44,7 +45,8 @@ protected function getObjectAndParams()
$params['link'],
$params['order'],
$params['group_id'],
$params['enabled']
$params['enabled'],
$params['meta']
);

return compact('params', 'object');
Expand Down
4 changes: 3 additions & 1 deletion tests/Bus/Commands/Component/UpdateComponentCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected function getObjectAndParams()
'order' => 0,
'group_id' => 0,
'enabled' => true,
'meta' => null,
];

$object = new UpdateComponentCommand(
Expand All @@ -48,7 +49,8 @@ protected function getObjectAndParams()
$params['link'],
$params['order'],
$params['group_id'],
$params['enabled']
$params['enabled'],
$params['meta']
);

return compact('params', 'object');
Expand Down