Skip to content
Open
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
3 changes: 2 additions & 1 deletion lib/Controller/CardApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ public function create($title, $type = 'plain', $order = 999, $description = '',
#[NoAdminRequired]
#[CORS]
#[NoCSRFRequired]
public function update(string $title, $type, string $owner, string $description = '', int $order = 0, $duedate = null, $startdate = null, $archived = null, ?string $color = null): DataResponse {
public function update(string $title, $type, string $owner, string $description = '', int $order = 0, $duedate = null, $startdate = null, $archived = null): DataResponse {
$done = array_key_exists('done', $this->request->getParams()) ? new OptionalNullableValue($this->request->getParam('done', null)) : null;
$color = array_key_exists('color', $this->request->getParams()) ? new OptionalNullableValue($this->request->getParam('color', null)) : null;
$card = $this->cardService->update($this->request->getParam('cardId'), $title, $this->request->getParam('stackId'), $type, $owner, $description, $order, $duedate, 0, $archived, $done, $startdate, $color);
return new DataResponse($card, HTTP::STATUS_OK);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/Controller/CardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ public function create(string $title, int $stackId, string $type = 'plain', int
* @param $duedate
*/
#[NoAdminRequired]
public function update(int $id, string $title, int $stackId, string $type, int $order, string $description, $duedate, $deletedAt, $archived = null, $startdate = null, ?string $color = null): Card {
public function update(int $id, string $title, int $stackId, string $type, int $order, string $description, $duedate, $deletedAt, $archived = null, $startdate = null): Card {
$done = array_key_exists('done', $this->request->getParams())
? new OptionalNullableValue($this->request->getParam('done', null))
: null;
$color = array_key_exists('color', $this->request->getParams())
? new OptionalNullableValue($this->request->getParam('color', null))
: null;
return $this->cardService->update($id, $title, $stackId, $type, $this->userId, $description, $order, $duedate, $deletedAt, $archived, $done, $startdate, $color);
}

Expand Down
5 changes: 4 additions & 1 deletion lib/Controller/CardOcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,13 @@ public function removeLabel(?int $boardId, int $cardId, int $labelId): DataRespo

#[NoAdminRequired]
#[PublicPage]
public function update(int $id, string $title, int $stackId, string $type, int $order, string $description, $duedate, $deletedAt, int $boardId, array|string|null $owner = null, $archived = null, $startdate = null, ?string $color = null): DataResponse {
public function update(int $id, string $title, int $stackId, string $type, int $order, string $description, $duedate, $deletedAt, int $boardId, array|string|null $owner = null, $archived = null, $startdate = null): DataResponse {
$done = array_key_exists('done', $this->request->getParams())
? new OptionalNullableValue($this->request->getParam('done', null))
: null;
$color = array_key_exists('color', $this->request->getParams())
? new OptionalNullableValue($this->request->getParam('color', null))
: null;
if (!$owner) {
$owner = $this->userId;
} else {
Expand Down
7 changes: 5 additions & 2 deletions lib/Service/CardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public function delete(int $id): Card {
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws BadRequestException
*/
public function update(int $id, string $title, int $stackId, string $type, string $owner, string $description = '', int $order = 0, ?string $duedate = null, ?int $deletedAt = null, ?bool $archived = null, ?OptionalNullableValue $done = null, ?string $startdate = null, ?string $color = null): Card {
public function update(int $id, string $title, int $stackId, string $type, string $owner, string $description = '', int $order = 0, ?string $duedate = null, ?int $deletedAt = null, ?bool $archived = null, ?OptionalNullableValue $done = null, ?string $startdate = null, ?OptionalNullableValue $color = null): Card {
$this->cardServiceValidator->check(compact('id', 'title', 'stackId', 'type', 'owner', 'order'));

$this->permissionService->checkPermission($this->cardMapper, $id, Acl::PERMISSION_EDIT, allowDeletedCard: true);
Expand Down Expand Up @@ -289,7 +289,10 @@ public function update(int $id, string $title, int $stackId, string $type, strin
$card->setOrder($order);
$card->setDuedate($duedate ? new \DateTime($duedate) : null);
$card->setStartdate($startdate ? new \DateTime($startdate) : null);
$card->setColor($color);
if ($color !== null) {
$colorValue = $color->getValue();
$card->setColor(is_string($colorValue) && $colorValue !== '' ? $colorValue : null);
}
$resetDuedateNotification = false;
if (
$card->getDuedate() === null
Expand Down
101 changes: 100 additions & 1 deletion tests/unit/Service/CardServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCA\Deck\Db\Stack;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\Model\CardDetails;
use OCA\Deck\Model\OptionalNullableValue;
use OCA\Deck\Notification\NotificationHelper;
use OCA\Deck\StatusException;
use OCA\Deck\Validators\CardServiceValidator;
Expand Down Expand Up @@ -368,7 +369,7 @@ public function testUpdate() {
->method('find')
->with(234)
->willReturn($stack);
$actual = $this->cardService->update(123, 'newtitle', 234, 'text', 'admin', 'foo', 999, '2017-01-01 00:00:00', null, null, null, null, 'ffffff');
$actual = $this->cardService->update(123, 'newtitle', 234, 'text', 'admin', 'foo', 999, '2017-01-01 00:00:00', null, null, null, null, new OptionalNullableValue('ffffff'));
$this->assertEquals('newtitle', $actual->getTitle());
$this->assertEquals(234, $actual->getStackId());
$this->assertEquals('text', $actual->getType());
Expand All @@ -378,6 +379,104 @@ public function testUpdate() {
$this->assertEquals('ffffff', $actual->getColor());
}

public function testUpdateKeepsColorWhenOmitted() {
$card = Card::fromParams([
'title' => 'Card title',
'archived' => 'false',
'stackId' => 234,
'color' => '00ff00',
]);
$card->setColor('ff0000');
$stack = Stack::fromParams([
'id' => 234,
'boardId' => 1337,
]);
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->once())->method('update')->willReturnCallback(function ($c) {
$c->setId(1);
return $c;
});
$this->stackMapper->expects($this->once())
->method('find')
->with(234)
->willReturn($stack);
$actual = $this->cardService->update(123, 'newtitle', 234, 'text', 'admin', 'foo', 999, '2017-01-01 00:00:00', null, null, null, null, null);
$this->assertSame('ff0000', $actual->getColor());
}

public function testUpdateClearsColorWhenNullProvided() {
$card = Card::fromParams([
'title' => 'Card title',
'archived' => 'false',
'stackId' => 234,
'color' => '00ff00',
]);
$card->setColor('ff0000');
$stack = Stack::fromParams([
'id' => 234,
'boardId' => 1337,
]);
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->once())->method('update')->willReturnCallback(function ($c) {
$c->setId(1);
return $c;
});
$this->stackMapper->expects($this->once())
->method('find')
->with(234)
->willReturn($stack);
$actual = $this->cardService->update(123, 'newtitle', 234, 'text', 'admin', 'foo', 999, '2017-01-01 00:00:00', null, null, null, null, new OptionalNullableValue(null));
$this->assertNull($actual->getColor());
}

public function testUpdateClearsColorWhenEmptyStringProvided() {
$card = Card::fromParams([
'title' => 'Card title',
'archived' => 'false',
'stackId' => 234,
'color' => '00ff00',
]);
$card->setColor('ff0000');
$stack = Stack::fromParams([
'id' => 234,
'boardId' => 1337,
]);
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->once())->method('update')->willReturnCallback(function ($c) {
$c->setId(1);
return $c;
});
$this->stackMapper->expects($this->once())
->method('find')
->with(234)
->willReturn($stack);
$actual = $this->cardService->update(123, 'newtitle', 234, 'text', 'admin', 'foo', 999, '2017-01-01 00:00:00', null, null, null, null, new OptionalNullableValue(''));
$this->assertNull($actual->getColor());
}

public function testUpdateSetsColor() {
$card = Card::fromParams([
'title' => 'Card title',
'archived' => 'false',
'stackId' => 234,
]);
$stack = Stack::fromParams([
'id' => 234,
'boardId' => 1337,
]);
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
$this->cardMapper->expects($this->once())->method('update')->willReturnCallback(function ($c) {
$c->setId(1);
return $c;
});
$this->stackMapper->expects($this->once())
->method('find')
->with(234)
->willReturn($stack);
$actual = $this->cardService->update(123, 'newtitle', 234, 'text', 'admin', 'foo', 999, '2017-01-01 00:00:00', null, null, null, null, new OptionalNullableValue('00ff00'));
$this->assertSame('00ff00', $actual->getColor());
}

public function testUpdateWithStartdate() {
$card = Card::fromParams([
'title' => 'Card title',
Expand Down
Loading