diff --git a/cypress/e2e/swimlanesFeatures.js b/cypress/e2e/swimlanesFeatures.js new file mode 100644 index 0000000000..305f03f588 --- /dev/null +++ b/cypress/e2e/swimlanesFeatures.js @@ -0,0 +1,555 @@ +/** + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { randUser } from '../utils/index.js' + +const user = randUser() + +// Cypress.env() throws when allowCypressEnv is false, which this project +// sets, and Cypress.expose() needs an expose entry that does not exist +// here. The configured base URL carries an /index.php suffix in CI, so +// strip it the way cypress/support/commands.js does. +const baseUrl = Cypress.config('baseUrl').replace(/\/index.php\/?$/g, '') + +/** + * Builds a board with three stacks, three labels and three cards. One card + * has two labels, so it should render in two lanes when grouped by labels. + */ +function seedSwimlaneBoard() { + const auth = { user: user.userId, password: user.password } + const api = `${baseUrl}/index.php/apps/deck/api/v1.0` + + return cy.request({ + method: 'POST', + url: `${api}/boards`, + auth, + body: { title: 'Swimlanes', color: '00ff00' }, + }).then(({ body: board }) => { + const boardId = board.id + + const stackReq = (title) => cy.request({ + method: 'POST', + url: `${api}/boards/${boardId}/stacks`, + auth, + body: { title, order: 0 }, + }) + const labelReq = (title, color) => cy.request({ + method: 'POST', + url: `${api}/boards/${boardId}/labels`, + auth, + body: { title, color }, + }).then(({ body }) => body) + + // Cypress chainables are not promises, so the requests are chained + // sequentially instead of via Promise.all + const ids = {} + return stackReq('Todo').then(({ body }) => { + ids.todo = body.id + }).then(() => stackReq('Doing')) + .then(() => stackReq('Done')) + .then(() => labelReq('Bug', 'ff0000')) + .then((label) => { + ids.bug = label.id + }) + .then(() => labelReq('Feature', '00ff00')) + .then((label) => { + ids.feature = label.id + }) + .then(() => labelReq('Backend', '0000ff')) + .then((label) => { + ids.backend = label.id + }) + .then(() => { + // CardApiController::create still carries NoCSRFRequired as a + // doc comment rather than a PHP attribute, and Nextcloud no + // longer honours the comment form. Once an earlier request has + // established a session, the server drops the user on this route + // and CardService::create receives a null owner, which surfaces + // as a 500. Clearing the cookies first leaves basic auth as the + // only credential, which the route does accept. + const mk = (title) => cy.clearCookies().then(() => cy.request({ + method: 'POST', + url: `${api}/boards/${boardId}/stacks/${ids.todo}/cards`, + auth, + body: { title, description: '' }, + })).then(({ body }) => body) + const assignLabel = (cardId, labelId) => cy.clearCookies().then(() => cy.request({ + method: 'PUT', + url: `${api}/boards/${boardId}/stacks/${ids.todo}/cards/${cardId}/assignLabel`, + auth, + body: { labelId }, + })) + return mk('Fix login bug') + .then((card) => { + // two labels on this card + return assignLabel(card.id, ids.bug).then(() => assignLabel(card.id, ids.backend)) + }) + .then(() => mk('Ship feature').then((card) => assignLabel(card.id, ids.feature))) + .then(() => mk('Unlabeled work')) + .then(() => cy.wrap({ boardId, todoId: ids.todo, featureId: ids.feature })) + }) + }) +} + +const viewer = randUser() + +describe('Swimlane grouping, editor-only restriction', function() { + const owner = randUser() + let restrictedBoardId + + before(function() { + cy.createUser(owner) + cy.createUser(viewer) + const ownerAuth = { user: owner.userId, password: owner.password } + const base = `${baseUrl}/index.php/apps/deck/api/v1.0` + cy.request({ + method: 'POST', + url: `${base}/boards`, + auth: ownerAuth, + body: { title: 'Restricted board', color: '0000ff' }, + }).then(({ body }) => { + restrictedBoardId = body.id + // Share via API with all permission flags explicitly false; the + // share dialog grants edit by default, which would invalidate this + // "read-only" suite. PERMISSION_TYPE_USER = 0. + cy.request({ + method: 'POST', + url: `${base}/boards/${restrictedBoardId}/acl`, + auth: ownerAuth, + body: { + type: 0, + participant: viewer.userId, + permissionEdit: false, + permissionShare: false, + permissionManage: false, + }, + }) + }) + }) + + it('read-only user cannot set swimlaneMode via the API (403)', function() { + // Clear cookies so the basic-auth credentials below aren't silently + // overridden by a logged-in session left over from cy.createUser + // (which authenticates as admin and would make the request succeed + // as admin, masking the permission check). The board was shared with + // the viewer via a cy.request to the ACL API in the before() hook. + cy.clearCookies() + cy.request({ + method: 'POST', + failOnStatusCode: false, + url: `${baseUrl}/ocs/v2.php/apps/deck/api/v1.0/config/board:${restrictedBoardId}:swimlaneMode?format=json`, + auth: { user: viewer.userId, password: viewer.password }, + headers: { 'OCS-APIRequest': 'true' }, + body: { value: 'labels' }, + }).then((response) => { + expect(response.status).to.equal(403) + }) + }) + + it('swimlane grouping controls are disabled in the UI for a read-only user', function() { + cy.login(viewer) + cy.visit(`/apps/deck/board/${restrictedBoardId}`) + cy.get('button[aria-label="View Modes"]', { timeout: 10000 }).first().click() + cy.get('input[name="swimlaneMode"]').each(($input) => { + cy.wrap($input).should('be.disabled') + }) + }) +}) + +describe('Swimlane grouping', function() { + let boardId + let todoId + let featureId + + before(function() { + cy.createUser(user) + // No cy.login here. A session cookie makes Nextcloud prefer the + // session over the basic auth that seedSwimlaneBoard sends, and the + // Deck API then wants a CSRF token that cy.request has no way to + // supply, so board creation would arrive without a user. beforeEach + // logs in before every test anyway. + seedSwimlaneBoard().then((ctx) => { + boardId = ctx.boardId + todoId = ctx.todoId + featureId = ctx.featureId + }) + }) + + beforeEach(function() { + // Reset the board to flat view and clear the lane order before each + // test so the tests are independent (done here rather than in + // afterEach so that a config request still in flight when the + // previous test ends cannot undo it) + cy.request({ + method: 'POST', + url: `${baseUrl}/ocs/v2.php/apps/deck/api/v1.0/config/board:${boardId}:swimlaneMode?format=json`, + auth: { user: user.userId, password: user.password }, + headers: { 'OCS-APIRequest': 'true' }, + body: { value: 'none' }, + }) + cy.request({ + method: 'POST', + url: `${baseUrl}/ocs/v2.php/apps/deck/api/v1.0/config/board:${boardId}:swimlaneLabelOrder?format=json`, + auth: { user: user.userId, password: user.password }, + headers: { 'OCS-APIRequest': 'true' }, + body: { value: '[]' }, + }) + cy.login(user) + cy.visit(`/apps/deck/board/${boardId}`) + cy.get('.stack', { timeout: 10000 }).should('have.length', 3) + }) + + // Selects a grouping mode in the View Modes menu and waits for the + // config request to be persisted, so the next test cannot race it + const setModeViaMenu = (label) => { + cy.intercept('POST', '**/apps/deck/api/v1.0/config/**').as('saveSwimlaneMode') + cy.get('button[aria-label="View Modes"]').first().click() + // {force: true} is needed because the NcActions menu has a brief + // CSS visibility:hidden phase on the action-radio span while it + // animates open, which is what an end user would see as a normal + // click target + cy.contains('.action-radio__text', label).click({ force: true }) + cy.wait('@saveSwimlaneMode') + } + + it('flat view shows no swimlanes initially', function() { + cy.get('.swimlane').should('not.exist') + cy.get('.card').should('have.length.at.least', 3) + }) + + it('groups cards by labels', function() { + setModeViaMenu('Labels') + + cy.get('.swimlane', { timeout: 8000 }).should('have.length.at.least', 4) + cy.get('.swimlane-header__title, .swimlane-header__label').should('contain.text', 'Bug') + cy.get('.swimlane-header__title, .swimlane-header__label').should('contain.text', 'Feature') + cy.get('.swimlane-header__title, .swimlane-header__label').should('contain.text', 'Backend') + cy.get('.swimlane-header__title, .swimlane-header__label').last().should('contain.text', 'No label') + }) + + it('renders a multi-label card in every matching lane', function() { + setModeViaMenu('Labels') + cy.get('.swimlane', { timeout: 8000 }).should('have.length.at.least', 4) + + // "Fix login bug" has Bug + Backend labels, so it must appear in both lanes. + // Use cy.contains() to avoid embedding lane names into a CSS selector string. + const expectCardInLane = (laneName, cardTitle) => { + cy.contains('.swimlane-header', laneName) + .parents('.swimlane') + .find('.card') + .contains(cardTitle) + .should('exist') + } + expectCardInLane('Bug', 'Fix login bug') + expectCardInLane('Backend', 'Fix login bug') + }) + + it('shows an "in N lanes" duplicate badge on multi-label cards only', function() { + setModeViaMenu('Labels') + cy.get('.swimlane', { timeout: 8000 }).should('have.length.at.least', 4) + + // "Fix login bug" (Bug + Backend) must carry the "in 2 lanes" badge so it + // reads as one card duplicated across lanes, not two separate cards. + // This guards the regression where the badge silently never rendered + // because CardItem's hasBadges gate excluded label-only cards. + cy.contains('.swimlane-header', 'Bug') + .parents('.swimlane') + .find('.card').contains('Fix login bug') + .parents('.card') + .find('.icon-badge--lanes') + .should('contain.text', '2') + + // A single-label card ("Ship feature", Feature only) must NOT show it. + cy.contains('.swimlane-header', 'Feature') + .parents('.swimlane') + .find('.card').contains('Ship feature') + .parents('.card') + .find('.icon-badge--lanes') + .should('not.exist') + }) + + it('groups cards by assignees with Unassigned catchall last', function() { + setModeViaMenu('Assignees') + + cy.get('.swimlane', { timeout: 8000 }).should('have.length.at.least', 1) + cy.get('.swimlane-header__title').last().should('contain.text', 'Unassigned') + }) + + it('returns to flat view when No grouping is selected', function() { + setModeViaMenu('Labels') + cy.get('.swimlane', { timeout: 8000 }).should('exist') + + setModeViaMenu('No grouping') + + cy.get('.swimlane').should('not.exist') + cy.get('.stack').should('have.length', 3) + }) + + it('persists the grouping mode across reload', function() { + setModeViaMenu('Labels') + cy.get('.swimlane', { timeout: 8000 }).should('exist') + + cy.reload() + cy.get('.swimlane', { timeout: 10000 }).should('have.length.at.least', 4) + + // Radio reflects the persisted mode after reload + cy.get('button[aria-label="View Modes"]').first().click() + cy.get('input[name="swimlaneMode"][value="labels"]').should('be.checked') + }) + + // Cypress has no drag command, so fire the mousedown, stepped mousemove and mouseup that smooth-dnd listens for. + const dragWithMouse = ($source, getTarget) => { + const from = $source[0].getBoundingClientRect() + const start = { clientX: from.left + from.width / 2, clientY: from.top + from.height / 2 } + const opts = { scrollBehavior: false, force: true } + cy.wrap($source).trigger('mousedown', { button: 0, ...start, ...opts }) + cy.get('body').then(() => { + const to = getTarget() + const steps = 10 + for (let i = 1; i <= steps; i++) { + const point = { + clientX: start.clientX + (to.clientX - start.clientX) * i / steps, + clientY: start.clientY + (to.clientY - start.clientY) * i / steps, + } + cy.get('body').trigger('mousemove', { ...point, ...opts }) + } + cy.get('body').trigger('mouseup', { button: 0, ...to, ...opts }) + }) + } + + // Pointer position at the horizontal middle of an element, offsetY from its top + const pointIn = (selector, offsetY) => { + const rect = Cypress.$(selector)[0].getBoundingClientRect() + return { clientX: rect.left + rect.width / 2, clientY: rect.top + offsetY } + } + + // Does not cover the ghost bug: the ghost centre lands beside the cloned card + // containers here, so the drop works regardless. The next drag test covers it. + it('reorders lanes via the drag handle and keeps the order after reload', function() { + setModeViaMenu('Labels') + cy.get('.swimlane', { timeout: 8000 }).should('have.length.at.least', 4) + // created in this order, so ids ascend: Bug, Feature, Backend + cy.get('.swimlane-header').eq(0).should('contain.text', 'Bug') + cy.get('.swimlane-header').eq(1).should('contain.text', 'Feature') + + cy.intercept('POST', /\/config\/board(:|%3A)\d+(:|%3A)swimlaneLabelOrder/).as('saveLaneOrder') + cy.get('.swimlane-header__drag-handle').eq(1).then(($handle) => { + dragWithMouse($handle, () => pointIn('.swimlane-header:eq(0)', 2)) + }) + cy.wait('@saveLaneOrder').its('response.statusCode').should('eq', 200) + + cy.get('.swimlane-header').eq(0).should('contain.text', 'Feature') + cy.get('.swimlane-header').eq(1).should('contain.text', 'Bug') + cy.get('.swimlane-header').eq(2).should('contain.text', 'Backend') + cy.get('.swimlane-header').last().should('contain.text', 'No label') + + cy.reload() + cy.get('.swimlane', { timeout: 10000 }).should('have.length.at.least', 4) + cy.get('.swimlane-header').eq(0).should('contain.text', 'Feature') + cy.get('.swimlane-header').eq(1).should('contain.text', 'Bug') + }) + + it('drops a dragged lane below another lane although the ghost centre sits over a card container', function() { + setModeViaMenu('Labels') + cy.get('.swimlane', { timeout: 8000 }).should('have.length.at.least', 4) + cy.get('.swimlane-header').eq(0).should('contain.text', 'Bug') + cy.get('.swimlane-header').eq(1).should('contain.text', 'Feature') + + cy.intercept('POST', /\/config\/board(:|%3A)\d+(:|%3A)swimlaneLabelOrder/).as('saveLaneOrder') + cy.get('.swimlane-header__drag-handle').eq(0).then(($handle) => { + const lane = Cypress.$('.swimlane')[0].getBoundingClientRect() + const handle = $handle[0].getBoundingClientRect() + const board = Cypress.$('.board--swimlanes')[0].getBoundingClientRect() + expect(lane.bottom, 'lane fully visible').to.be.at.most(board.bottom) + const handleCentre = { x: handle.left + handle.width / 2, y: handle.top + handle.height / 2 } + const laneCentre = { x: lane.left + lane.width / 2, y: lane.top + lane.height / 2 } + + // smooth-dnd picks the drop container with elementFromPoint at the + // centre of the ghost, and the ghost is a clone of the lane. The + // library CSS makes cloned card containers clickable, so the drag + // only works if that centre is over a card container of the lane. + const hit = $handle[0].ownerDocument.elementFromPoint(laneCentre.x, laneCentre.y) + const overCardContainer = Cypress.$('.swimlane').eq(0).find('.smooth-dnd-container').toArray() + .some((container) => container.contains(hit)) + expect(overCardContainer, 'lane centre is over a card container').to.eq(true) + + // The ghost centre keeps a fixed offset to the pointer, so aim the + // pointer such that the ghost centre ends in the lower half of the + // second lane, which means "drop after it" + const offset = { x: laneCentre.x - handleCentre.x, y: laneCentre.y - handleCentre.y } + dragWithMouse($handle, () => { + const second = Cypress.$('.swimlane')[1].getBoundingClientRect() + return { + clientX: second.left + second.width / 2 - offset.x, + clientY: second.top + second.height * 0.75 - offset.y, + } + }) + }) + cy.wait('@saveLaneOrder').its('response.statusCode').should('eq', 200) + + cy.get('.swimlane-header').eq(0).should('contain.text', 'Feature') + cy.get('.swimlane-header').eq(1).should('contain.text', 'Bug') + cy.get('.swimlane-header').eq(2).should('contain.text', 'Backend') + + cy.reload() + cy.get('.swimlane', { timeout: 10000 }).should('have.length.at.least', 4) + cy.get('.swimlane-header').eq(0).should('contain.text', 'Feature') + cy.get('.swimlane-header').eq(1).should('contain.text', 'Bug') + }) + + it('keeps the last column visible in a narrow viewport', function() { + cy.viewport(720, 900) + setModeViaMenu('Labels') + cy.get('.swimlane', { timeout: 8000 }).should('have.length.at.least', 4) + cy.get('.board--swimlanes').scrollTo('right', { ensureScrollable: false }) + + const headerLeft = () => { + const headers = Cypress.$('.board__stack-headers .stack-draggable-wrapper') + return headers[headers.length - 1].getBoundingClientRect().left + } + cy.get('.swimlane').each(($lane) => { + const stacks = $lane.find('.swimlane__stack') + // collapsed lanes render no columns + if (stacks.length === 0) { + return + } + const last = stacks[stacks.length - 1].getBoundingClientRect() + const wrapper = $lane.closest('.smooth-dnd-draggable-wrapper')[0].getBoundingClientRect() + // not clipped by the overflow: hidden wrapper smooth-dnd puts around each lane + expect(last.right, 'last column right edge').to.be.at.most(wrapper.right + 1) + // aligned with the header row + expect(last.left, 'last column left edge').to.be.closeTo(headerLeft(), 1) + }) + }) + + // Unbreakable titles (card or stack) must not widen header or lane columns. + // What a test creates is removed in afterEach, so the other tests keep the + // seeded data only. Cookies are cleared first, see seedSwimlaneBoard. + describe('unbreakable titles', function() { + const api = `${baseUrl}/index.php/apps/deck/api/v1.0` + const auth = () => ({ user: user.userId, password: user.password }) + let cleanupUrls = [] + + afterEach(function() { + const urls = cleanupUrls + cleanupUrls = [] + if (urls.length === 0) { + return + } + cy.clearCookies() + for (let i = 0; i < urls.length; i++) { + cy.request({ method: 'DELETE', url: urls[i], auth: auth() }) + } + }) + + const openLaneView = () => { + cy.login(user) + cy.viewport(720, 900) + cy.visit(`/apps/deck/board/${boardId}`) + cy.get('.stack', { timeout: 10000 }).should('have.length.at.least', 3) + setModeViaMenu('Labels') + cy.get('.swimlane', { timeout: 8000 }).should('have.length.at.least', 4) + cy.get('.board--swimlanes').scrollTo('right', { ensureScrollable: false }) + } + + // Header column i and lane column i start at the same x, in every lane + const expectColumnsAligned = () => { + cy.get('.swimlane').each(($lane) => { + const stacks = $lane.find('.swimlane__stack') + // collapsed lanes render no columns + if (stacks.length === 0) { + return + } + const headers = Cypress.$('.board__stack-headers .stack-draggable-wrapper') + expect(stacks.length, 'columns per lane').to.equal(headers.length) + for (let i = 0; i < stacks.length; i++) { + expect(stacks[i].getBoundingClientRect().left, 'column ' + i + ' left edge') + .to.be.closeTo(headers[i].getBoundingClientRect().left, 1) + } + const last = stacks[stacks.length - 1].getBoundingClientRect() + const wrapper = $lane.closest('.smooth-dnd-draggable-wrapper')[0].getBoundingClientRect() + expect(last.right, 'last column right edge').to.be.at.most(wrapper.right + 1) + }) + } + + it('keeps lane columns aligned with the header row when a card title is unbreakable', function() { + const title = 'W'.repeat(80) + cy.clearCookies() + cy.request({ + method: 'POST', + url: `${api}/boards/${boardId}/stacks/${todoId}/cards`, + auth: auth(), + body: { title, description: '' }, + }).then(({ body: card }) => { + cleanupUrls.push(`${api}/boards/${boardId}/stacks/${todoId}/cards/${card.id}`) + cy.clearCookies() + cy.request({ + method: 'PUT', + url: `${api}/boards/${boardId}/stacks/${todoId}/cards/${card.id}/assignLabel`, + auth: auth(), + body: { labelId: featureId }, + }) + }) + + openLaneView() + cy.contains('.swimlane .card', title).should('exist') + expectColumnsAligned() + + // The card stays inside its column and the column does not scroll sideways + cy.get('.swimlane').each(($lane) => { + $lane.find('.card').each((_, card) => { + const column = card.closest('.swimlane__stack') + expect(card.getBoundingClientRect().right, 'card right edge') + .to.be.at.most(column.getBoundingClientRect().right + 1) + }) + $lane.find('.swimlane__stack .smooth-dnd-container.vertical').each((_, container) => { + expect(container.scrollWidth, 'card container scrollWidth') + .to.be.at.most(container.clientWidth) + }) + }) + }) + + it('keeps lane columns aligned with the header row when a stack title is unbreakable', function() { + cy.clearCookies() + cy.request({ + method: 'POST', + url: `${api}/boards/${boardId}/stacks`, + auth: auth(), + body: { title: 'S'.repeat(40), order: 0 }, + }).then(({ body: stack }) => { + cleanupUrls.push(`${api}/boards/${boardId}/stacks/${stack.id}`) + }) + + openLaneView() + cy.get('.board__stack-headers .stack-draggable-wrapper').should('have.length', 4) + expectColumnsAligned() + }) + }) + + // Keep this test last, it changes the card's stack for good. + it('moves a card between stacks inside a lane', function() { + setModeViaMenu('Labels') + cy.get('.swimlane', { timeout: 8000 }).should('have.length.at.least', 4) + + const featureLane = () => cy.contains('.swimlane-header', 'Feature').parents('.swimlane') + featureLane().find('.swimlane__stack').eq(0).should('contain.text', 'Ship feature') + featureLane().find('.swimlane__stack').eq(1).should('not.contain.text', 'Ship feature') + + cy.intercept('PUT', '**/cards/*/reorder').as('reorderCard') + featureLane().find('.swimlane__stack').eq(0).contains('.card', 'Ship feature').then(($card) => { + dragWithMouse($card, () => { + const stack = $card.closest('.swimlane').find('.swimlane__stack')[1].getBoundingClientRect() + return { clientX: stack.left + stack.width / 2, clientY: stack.top + 20 } + }) + }) + cy.wait('@reorderCard').its('response.statusCode').should('eq', 200) + + featureLane().find('.swimlane__stack').eq(1).should('contain.text', 'Ship feature') + featureLane().find('.swimlane__stack').eq(0).should('not.contain.text', 'Ship feature') + + cy.reload() + cy.get('.swimlane', { timeout: 10000 }).should('have.length.at.least', 4) + featureLane().find('.swimlane__stack').eq(1).should('contain.text', 'Ship feature') + }) +}) diff --git a/docs/API.md b/docs/API.md index c3d40d265d..3e69f46cc2 100644 --- a/docs/API.md +++ b/docs/API.md @@ -170,7 +170,10 @@ Returns an array of board items "lastModified": 1586269585, "settings": { "notify-due": "off", - "calendar": true + "calendar": true, + "swimlaneMode": "none", + "swimlaneLabelOrder": "[]", + "swimlaneUserOrder": "[]" } } ] @@ -1174,6 +1177,9 @@ Deck stores user and app configuration values globally and per board. The GET en | calendar | Boolean | | cardDetailsInModal | Boolean | | cardIdBadge | Boolean | +| swimlaneMode | `none`, `labels` or `assignees`. Shared by everyone with access to the board, needs edit permission | +| swimlaneLabelOrder | JSON string holding an array of label ids in lane order. Shared, needs edit permission. May contain `"__none__"` for the lane of cards without a label. At most 8192 bytes, 1000 entries, 255 bytes per id | +| swimlaneUserOrder | JSON string holding an array of participant uids (without type) in lane order. Shared, needs edit permission. May contain `"__none__"` for the lane of unassigned cards. At most 8192 bytes, 1000 entries, 255 bytes per id | #### Example request diff --git a/docs/User_documentation_en.md b/docs/User_documentation_en.md index e0b3b56aae..37c93da5c3 100644 --- a/docs/User_documentation_en.md +++ b/docs/User_documentation_en.md @@ -203,3 +203,17 @@ Individual boards can be transferred by adding the id of the board to the comman ```bash php occ deck:transfer-ownership previousOwner newOwner 123 ``` + +### 12. Group cards into swimlanes +In the board view, open the board menu in the top bar and pick an entry under **Group by**: + +- **No grouping** shows the usual columns. +- **Labels** adds one row per label. Cards without a label land in **No label**. +- **Assignees** adds one row per assigned user, group or circle. Cards without an assignee land in **Unassigned**. + +Every row keeps all stacks as columns, so a card stays in its stack and only moves between rows. + +- A card with several labels or assignees appears in each matching row. A small badge on the card shows how many rows it appears in. It is still one card, so editing it changes every copy. +- A card can only be dragged inside its own row, between stacks or within a stack. To move it to another row, change its labels or assignees. +- Drag a row header to reorder the rows. Use the arrow on the header to collapse or expand a row. +- The grouping and the row order belong to the board. Everyone with access sees the same layout, and only users who can edit the board can change it. diff --git a/lib/Controller/ConfigController.php b/lib/Controller/ConfigController.php index baba55c542..eb6a30820c 100644 --- a/lib/Controller/ConfigController.php +++ b/lib/Controller/ConfigController.php @@ -9,6 +9,7 @@ use OCA\Deck\Db\Acl; use OCA\Deck\Db\BoardMapper; +use OCA\Deck\Service\BoardService; use OCA\Deck\Service\ConfigService; use OCA\Deck\Service\PermissionService; use OCP\AppFramework\Http\Attribute\NoAdminRequired; @@ -25,6 +26,7 @@ public function __construct( private ConfigService $configService, private PermissionService $permissionService, private BoardMapper $boardMapper, + private BoardService $boardService, ) { parent::__construct($AppName, $request); } @@ -38,14 +40,23 @@ public function get(): DataResponse { #[NoAdminRequired] #[NoCSRFRequired] public function setValue(string $key, mixed $value): DataResponse|NotFoundResponse { + $boardId = null; if (preg_match('/^board:(\d+):/', $key, $matches) === 1) { + $boardId = (int)$matches[1]; $this->permissionService->checkPermission( $this->boardMapper, - (int)$matches[1], + $boardId, Acl::PERMISSION_EDIT, ); } + // Swimlane settings are board columns. Only a key that passed the + // numeric EDIT check above may reach BoardService. + $setting = $boardId === null ? null : substr($key, strlen($matches[0])); + if ($setting !== null && in_array($setting, BoardService::SWIMLANE_SETTINGS, true)) { + return new DataResponse($this->boardService->setSwimlaneSetting($boardId, $setting, $value)); + } + $result = $this->configService->set($key, $value); if ($result === null) { return new NotFoundResponse(); diff --git a/lib/Db/Board.php b/lib/Db/Board.php index 7fc1350383..8e446c7ebc 100644 --- a/lib/Db/Board.php +++ b/lib/Db/Board.php @@ -30,6 +30,12 @@ * @method string getShareToken() * @method void setExternalId(int $externalId) * @method int | null getExternalId() + * @method string|null getSwimlaneMode() + * @method void setSwimlaneMode(?string $swimlaneMode) + * @method string|null getSwimlaneLabelOrder() + * @method void setSwimlaneLabelOrder(?string $swimlaneLabelOrder) + * @method string|null getSwimlaneUserOrder() + * @method void setSwimlaneUserOrder(?string $swimlaneUserOrder) */ class Board extends RelationalEntity { protected $title; @@ -50,6 +56,9 @@ class Board extends RelationalEntity { protected $lastModified = 0; protected $shareToken = null; protected $externalId = null; + protected $swimlaneMode = null; + protected $swimlaneLabelOrder = null; + protected $swimlaneUserOrder = null; protected $settings = []; @@ -62,6 +71,9 @@ public function __construct() { $this->addType('shareToken', 'string'); $this->addType('externalId', 'integer'); $this->addType('teamId', 'string'); + $this->addType('swimlaneMode', 'string'); + $this->addType('swimlaneLabelOrder', 'string'); + $this->addType('swimlaneUserOrder', 'string'); $this->addRelation('labels'); $this->addRelation('acl'); $this->addRelation('shared'); @@ -84,6 +96,8 @@ public function jsonSerialize(): array { // however this would be a breaking change for consumers of the API $json['acl'] = $this->acl ?? []; $json['labels'] = $this->labels ?? []; + // Served under 'settings' by BoardService::enrichWithBoardSettings, not top level. + unset($json['swimlaneMode'], $json['swimlaneLabelOrder'], $json['swimlaneUserOrder']); return $json; } diff --git a/lib/Db/BoardMapper.php b/lib/Db/BoardMapper.php index 89da7d9121..03b3bb7c47 100644 --- a/lib/Db/BoardMapper.php +++ b/lib/Db/BoardMapper.php @@ -230,7 +230,7 @@ public function findAllByUser(string $userId, ?int $limit = null, ?int $offset = // FIXME this used to be a UNION to get boards owned by $userId and the user shares in one single query // Is it possible with the query builder? $qb = $this->db->getQueryBuilder(); - $qb->select('id', 'title', 'owner', 'color', 'archived', 'deleted_at', 'last_modified', 'external_id', 'share_token') + $qb->select('id', 'title', 'owner', 'color', 'archived', 'deleted_at', 'last_modified', 'external_id', 'share_token', 'swimlane_mode', 'swimlane_label_order', 'swimlane_user_order') // this does not work in MySQL/PostgreSQL //->selectAlias('0', 'shared') ->from('deck_boards', 'b') @@ -270,7 +270,7 @@ public function findAllByUser(string $userId, ?int $limit = null, ?int $offset = // shared with user $qb = $this->db->getQueryBuilder(); - $qb->select('b.id', 'title', 'owner', 'color', 'archived', 'deleted_at', 'last_modified', 'external_id', 'share_token') + $qb->select('b.id', 'title', 'owner', 'color', 'archived', 'deleted_at', 'last_modified', 'external_id', 'share_token', 'swimlane_mode', 'swimlane_label_order', 'swimlane_user_order') //->selectAlias('1', 'shared') ->from('deck_boards', 'b') ->innerJoin('b', 'deck_board_acl', 'acl', $qb->expr()->eq('b.id', 'acl.board_id')) @@ -352,7 +352,7 @@ public function findAllByGroups(string $userId, array $groups, ?int $limit = nul return []; } $qb = $this->db->getQueryBuilder(); - $qb->select('b.id', 'title', 'owner', 'color', 'archived', 'deleted_at', 'last_modified', 'external_id', 'share_token') + $qb->select('b.id', 'title', 'owner', 'color', 'archived', 'deleted_at', 'last_modified', 'external_id', 'share_token', 'swimlane_mode', 'swimlane_label_order', 'swimlane_user_order') //->selectAlias('2', 'shared') ->from('deck_boards', 'b') ->innerJoin('b', 'deck_board_acl', 'acl', $qb->expr()->eq('b.id', 'acl.board_id')) @@ -408,7 +408,7 @@ public function findAllByCircles(string $userId, ?int $limit = null, ?int $offse } $qb = $this->db->getQueryBuilder(); - $qb->select('b.id', 'title', 'owner', 'color', 'archived', 'deleted_at', 'last_modified', 'external_id', 'share_token') + $qb->select('b.id', 'title', 'owner', 'color', 'archived', 'deleted_at', 'last_modified', 'external_id', 'share_token', 'swimlane_mode', 'swimlane_label_order', 'swimlane_user_order') //->selectAlias('2', 'shared') ->from('deck_boards', 'b') ->innerJoin('b', 'deck_board_acl', 'acl', $qb->expr()->eq('b.id', 'acl.board_id')) diff --git a/lib/Migration/Version11002Date20261004120000.php b/lib/Migration/Version11002Date20261004120000.php new file mode 100644 index 0000000000..46785eb44a --- /dev/null +++ b/lib/Migration/Version11002Date20261004120000.php @@ -0,0 +1,52 @@ +hasTable('deck_boards')) { + return null; + } + + $table = $schema->getTable('deck_boards'); + + if (!$table->hasColumn('swimlane_mode')) { + $table->addColumn('swimlane_mode', 'string', [ + 'notnull' => false, + 'length' => 16, + 'default' => null, + ]); + } + + // text, an order may hold 8192 bytes and Oracle caps varchar at 4000. + // No default, MySQL rejects one on TEXT. Null is read as '[]'. + foreach (['swimlane_label_order', 'swimlane_user_order'] as $column) { + if (!$table->hasColumn($column)) { + $table->addColumn($column, 'text', [ + 'notnull' => false, + ]); + } + } + + return $schema; + } +} diff --git a/lib/Service/BoardService.php b/lib/Service/BoardService.php index cb38c8d4b4..33bdf87589 100644 --- a/lib/Service/BoardService.php +++ b/lib/Service/BoardService.php @@ -56,6 +56,15 @@ use Psr\Container\NotFoundExceptionInterface; class BoardService { + /** Settings stored as columns on the board, shared by every member. */ + public const SWIMLANE_SETTINGS = ['swimlaneMode', 'swimlaneLabelOrder', 'swimlaneUserOrder']; + + // Every member is served the stored order, so cap it. + private const MAX_SWIMLANE_ORDER_BYTES = 8192; + private const MAX_SWIMLANE_ORDER_ENTRIES = 1000; + // Federated user ids are full cloud ids (user@host), so allow 255. + private const MAX_SWIMLANE_LANE_ID_LENGTH = 255; + private ?array $boardsCacheFull = null; private ?array $boardsCachePartial = null; @@ -426,11 +435,72 @@ private function applyPermissions(int $boardId, bool $edit, bool $share, bool $m return [$edit, $share, $manage]; } + /** + * Write one of the three swimlane settings onto the board. + * + * boardMapper->update writes only this field and fires no board events. + * boardChanged still moves the ETag. + * + * @throws BadRequestException if the key is not a swimlane setting or the value is malformed + * @throws DoesNotExistException if the board is gone + */ + public function setSwimlaneSetting(int $boardId, string $key, mixed $value): mixed { + if (!in_array($key, self::SWIMLANE_SETTINGS, true)) { + throw new BadRequestException('Not a swimlane setting: ' . $key); + } + $this->validateSwimlaneValue($key, $value); + + $board = $this->boardMapper->find($boardId); + match ($key) { + 'swimlaneMode' => $board->setSwimlaneMode((string)$value), + 'swimlaneLabelOrder' => $board->setSwimlaneLabelOrder((string)$value), + 'swimlaneUserOrder' => $board->setSwimlaneUserOrder((string)$value), + }; + $this->boardMapper->update($board); + $this->changeHelper->boardChanged($boardId); + + return $value; + } + + /** + * Every member is served these values, so reject malformed ones. + */ + private function validateSwimlaneValue(string $key, mixed $value): void { + if ($key === 'swimlaneMode') { + if (!in_array($value, ['none', 'labels', 'assignees'], true)) { + throw new BadRequestException('Swimlane mode must be one of: none, labels, assignees'); + } + return; + } + + // swimlaneLabelOrder / swimlaneUserOrder: JSON array of lane ids + // (label ids, user ids or the '__none__' catch-all lane). + if (!is_string($value) || strlen($value) > self::MAX_SWIMLANE_ORDER_BYTES) { + throw new BadRequestException('Swimlane order must be a JSON array of lane ids'); + } + $order = json_decode($value, true); + if (!is_array($order) || !array_is_list($order) || count($order) > self::MAX_SWIMLANE_ORDER_ENTRIES) { + throw new BadRequestException('Swimlane order must be a JSON array of lane ids'); + } + foreach ($order as $laneId) { + $isIntId = is_int($laneId); + $isStringId = is_string($laneId) && $laneId !== '' && strlen($laneId) <= self::MAX_SWIMLANE_LANE_ID_LENGTH; + if (!$isIntId && !$isStringId) { + throw new BadRequestException('Swimlane order entries must be label ids, user ids or "__none__"'); + } + } + } + public function enrichWithBoardSettings(Board $board): void { $globalCalendarConfig = (bool)$this->config->getUserValue($this->userId, Application::APP_ID, 'calendar', true); + $boardId = $board->getId(); $settings = [ - 'notify-due' => $this->config->getUserValue($this->userId, Application::APP_ID, 'board:' . $board->getId() . ':notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED), - 'calendar' => $this->config->getUserValue($this->userId, Application::APP_ID, 'board:' . $board->getId() . ':calendar', $globalCalendarConfig), + 'notify-due' => $this->config->getUserValue($this->userId, Application::APP_ID, 'board:' . $boardId . ':notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED), + 'calendar' => $this->config->getUserValue($this->userId, Application::APP_ID, 'board:' . $boardId . ':calendar', $globalCalendarConfig), + // Shared by every member. Null until someone changes them. + 'swimlaneMode' => $board->getSwimlaneMode() ?? 'none', + 'swimlaneLabelOrder' => $board->getSwimlaneLabelOrder() ?? '[]', + 'swimlaneUserOrder' => $board->getSwimlaneUserOrder() ?? '[]', ]; $board->setSettings($settings); } diff --git a/src/components/Controls.vue b/src/components/Controls.vue index 27768109c5..9ad3417153 100644 --- a/src/components/Controls.vue +++ b/src/components/Controls.vue @@ -299,6 +299,34 @@ {{ showCardCover ? t('deck', 'Hide card cover images') : t('deck', 'Show card cover images') }} + @@ -316,7 +344,7 @@ + + + + diff --git a/src/components/board/SwimlaneHeader.vue b/src/components/board/SwimlaneHeader.vue new file mode 100644 index 0000000000..8760a21dbd --- /dev/null +++ b/src/components/board/SwimlaneHeader.vue @@ -0,0 +1,182 @@ + + + + + + + diff --git a/src/components/cards/CardBadges.vue b/src/components/cards/CardBadges.vue index 530ee8cd7e..261e5affca 100644 --- a/src/components/cards/CardBadges.vue +++ b/src/components/cards/CardBadges.vue @@ -34,6 +34,14 @@ {{ card.attachmentCount }} + +
+ + {{ laneCount }} +
@@ -46,6 +54,7 @@