Skip to content

Commit

Permalink
Merge pull request #3430 from bahuma20/2797-clone-cards
Browse files Browse the repository at this point in the history
Clone cards together with the board
  • Loading branch information
juliusknorr authored Jan 2, 2025
2 parents ea01d84 + f2c30af commit 0527743
Show file tree
Hide file tree
Showing 12 changed files with 406 additions and 108 deletions.
71 changes: 71 additions & 0 deletions cypress/e2e/boardFeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { randUser } from '../utils/index.js'
const user = randUser()
const recipient = randUser()
import { sampleBoard } from '../utils/sampleBoard'

describe('Board', function() {

Expand Down Expand Up @@ -58,3 +59,73 @@ describe('Board', function() {
.should('be.visible')
})
})

describe('Board cloning', function() {
before(function() {
cy.createUser(user)
})

it('Clones a board without cards', function() {
const boardName = 'Clone board original'
const board = sampleBoard(boardName)
cy.createExampleBoard({ user, board }).then((board) => {
const boardId = board.id
cy.visit(`/apps/deck/board/${boardId}`)
cy.get('.app-navigation__list .app-navigation-entry:contains("' + boardName + '")')
.parent()
.find('button[aria-label="Actions"]')
.click()
cy.get('button:contains("Clone board")')
.click()

cy.get('.modal-container button:contains("Clone")')
.click()

cy.get('.app-navigation__list .app-navigation-entry:contains("' + boardName + '")')
.should('be.visible')

cy.get('.app-navigation__list .app-navigation-entry:contains("' + boardName + ' (copy)")')
.should('be.visible')

cy.get('.board-title h2').contains(boardName + ' (copy)')

cy.get('h3[aria-label="TestList"]')
.should('be.visible')
})
})

it('Clones a board with cards', function() {
const boardName = 'Clone with cards'
const board = sampleBoard(boardName)
cy.createExampleBoard({ user, board }).then((board) => {
const boardId = board.id
cy.visit(`/apps/deck/board/${boardId}`)
cy.get('.app-navigation__list .app-navigation-entry:contains("' + boardName + '")')
.parent()
.find('button[aria-label="Actions"]')
.click()
cy.get('button:contains("Clone board")')
.click()

cy.get('.checkbox-content__text:contains("Clone cards")')
.click()

cy.get('.modal-container button:contains("Clone")')
.click()

cy.get('.app-navigation__list .app-navigation-entry:contains("' + boardName + '")')
.should('be.visible')

cy.get('.app-navigation__list .app-navigation-entry:contains("' + boardName + ' (copy)")')
.should('be.visible')

cy.get('.board-title h2').contains(boardName + ' (copy)')

cy.get('h3[aria-label="TestList"]')
.should('be.visible')

cy.get('.card:contains("Hello world")')
.should('be.visible')
})
})
})
19 changes: 19 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,25 @@ A 403 response might be returned if the users ability to create new boards has b

##### 200 Success

### POST /boards/{boardId}/clone - Clone a board

Creates a copy of the board.

#### Request body

| Parameter | Type | Description |
| --------- | ------ | ---------------------------------------------------- |
| withCards | Bool | Setting if the cards should be copied (Default: false) |
| withAssignments | Bool | Setting if the card assignments should be cloned (Default: false) |
| withLabels | Bool | Setting if the card labels should be cloned (Default: false) |
| withDueDate | Bool | Setting if the card due dates should be cloned (Default: false) |
| moveCardsToLeftStack | Bool | Setting if all cards should be moved to the most left column (useful for To-Do / Doing / Done boards) (Default: false) |
| restoreArchivedCards | Bool | Setting if the archived cards should be unarchived (Default: false) |

#### Response

##### 200 Success

### DELETE /boards/{boardId}/acl/{aclId} - Delete an acl rule

#### Response
Expand Down
9 changes: 9 additions & 0 deletions lib/Controller/BoardApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,13 @@ public function deleteAcl($aclId) {
$acl = $this->boardService->deleteAcl($aclId);
return new DataResponse($acl, HTTP::STATUS_OK);
}

/**
* @NoAdminRequired
*/
public function clone(int $boardId, bool $withCards = false, bool $withAssignments = false, bool $withLabels = false, bool $withDueDate = false, bool $moveCardsToLeftStack = false, bool $restoreArchivedCards = false): DataResponse {
return new DataResponse(
$this->boardService->clone($boardId, $this->userId, $withCards, $withAssignments, $withLabels, $withDueDate, $moveCardsToLeftStack, $restoreArchivedCards)
);
}
}
8 changes: 4 additions & 4 deletions lib/Controller/BoardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ public function deleteAcl($aclId) {

/**
* @NoAdminRequired
* @param $boardId
* @return Board
*/
public function clone($boardId) {
return $this->boardService->clone($boardId, $this->userId);
public function clone(int $boardId, bool $withCards = false, bool $withAssignments = false, bool $withLabels = false, bool $withDueDate = false, bool $moveCardsToLeftStack = false, bool $restoreArchivedCards = false): DataResponse {
return new DataResponse(
$this->boardService->clone($boardId, $this->userId, $withCards, $withAssignments, $withLabels, $withDueDate, $moveCardsToLeftStack, $restoreArchivedCards)
);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions lib/Db/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

namespace OCA\Deck\Db;

/**
* @method getTitle(): string
*/
class Label extends RelationalEntity {
protected $title;
protected $color;
Expand Down
2 changes: 0 additions & 2 deletions lib/Service/AssignmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ public function __construct(
$this->changeHelper = $changeHelper;
$this->activityManager = $activityManager;
$this->eventDispatcher = $eventDispatcher;

$this->assignmentServiceValidator->check(compact('userId'));
$this->currentUser = $userId;
}

Expand Down
Loading

0 comments on commit 0527743

Please sign in to comment.