Skip to content

Commit 2d224ee

Browse files
committed
Revert(create): restore explicit insertAtPosition opt-in
Inferring the reorder-on-insert behavior from `$order !== 999` broke cloneCard() and DefaultBoardService, which call create() with real, already-correct order values (e.g. 0) that must not trigger a shift of other cards in the stack. Restore the explicit $insertAtPosition flag, opted into only by the OCS controller used by the new add-card UI. Signed-off-by: Theo <36564257+theoholl@users.noreply.github.com>
1 parent 7e5bc4c commit 2d224ee

3 files changed

Lines changed: 5 additions & 6 deletions

File tree

lib/Controller/CardOcsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function create(string $title, int $stackId, ?int $boardId = null, ?strin
4848
if (!$owner) {
4949
$owner = $this->userId;
5050
}
51-
$card = $this->cardService->create($title, $stackId, $type, $order, $owner, $description, $duedate, $startdate, $color);
51+
$card = $this->cardService->create($title, $stackId, $type, $order, $owner, $description, $duedate, $startdate, $color, insertAtPosition: $order !== 999);
5252

5353
// foreach ($labels as $label) {
5454
// $this->assignLabel($card->getId(), $label);

lib/Service/CardService.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function findCalendarEntries(int $boardId): array {
189189
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
190190
* @throws BadrequestException
191191
*/
192-
public function create(string $title, int $stackId, string $type, int $order, string $owner, string $description = '', $duedate = null, $startdate = null, ?string $color = null): Card {
192+
public function create(string $title, int $stackId, string $type, int $order, string $owner, string $description = '', $duedate = null, $startdate = null, ?string $color = null, bool $insertAtPosition = false): Card {
193193
$this->cardServiceValidator->check(compact('title', 'stackId', 'type', 'order', 'owner'));
194194

195195
$this->permissionService->checkPermission($this->stackMapper, $stackId, Acl::PERMISSION_EDIT);
@@ -207,8 +207,7 @@ public function create(string $title, int $stackId, string $type, int $order, st
207207
$card->setStartdate($startdate);
208208
$card->setColor($color);
209209

210-
if ($order === 999) {
211-
// Append to the end of the stack
210+
if (!$insertAtPosition) {
212211
$card = $this->cardMapper->insert($card);
213212
} else {
214213
// Insert at the requested position and shift the surrounding cards

tests/unit/Service/CardServiceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public function testCreateAtTopReordersCardsInTransaction(): void {
284284
->with(123)
285285
->willReturn($stack);
286286

287-
$createdCard = $this->cardService->create('New card', 123, 'plain', 0, 'admin');
287+
$createdCard = $this->cardService->create('New card', 123, 'plain', 0, 'admin', insertAtPosition: true);
288288

289289
$this->assertSame(0, $createdCard->getOrder());
290290
$this->assertSame(1, $firstCard->getOrder());
@@ -313,7 +313,7 @@ public function testCreateAtTopRollsBackWhenReorderingFails(): void {
313313
->willThrowException(new \RuntimeException('Could not reorder cards'));
314314

315315
$this->expectException(\RuntimeException::class);
316-
$this->cardService->create('New card', 123, 'plain', 0, 'admin');
316+
$this->cardService->create('New card', 123, 'plain', 0, 'admin', insertAtPosition: true);
317317
}
318318

319319
public function testClone() {

0 commit comments

Comments
 (0)