Files
wekan/server/versionControlView.js
T
Lauri Ojansivu 326d9bbf61 Board View / Version Control, issue files and synced issue details.
Version Control shows the board as a GitHub or Gitea issue tracker in the
board's own theme: cards are issues (open, or closed when archived, in a
Closed or Done list, or closed upstream), the board's labels are labels,
labels with a due date and the importers' milestone: labels are
milestones, comments are the conversation and attachments are the files.
The issue list takes GitHub's search words (is:open, label:, milestone:,
author:, assignee:@me, no:label, sort:). New issue, Close and Reopen write
through the ordinary collections, so the History tab - the board's
history table - shows them and Restore undoes them. Import links open the
GitHub, GitLab, Gitea and Forgejo importers, and each synced list has a
Sync now button.

The GitHub, GitLab, Gitea and Forgejo importers bring each issue's files:
user-attachments and user-images links, GitLab uploads, and Gitea and
Forgejo assets, downloaded through the import's SSRF guard and stored as
card attachments in Admin Panel / Attachments / Default Storage.

List sync has a new option, Comments, labels, state and files, off by
default: comments come from one paged repository-wide list (GitHub,
Gitea) or each issue's notes (GitLab), keyed by the tracker's ids, so a
second run writes only what changed, and nothing written in WeKan is
changed. Gitea issues are fetched without pull requests, and a rate
limited answer is waited out once or ends the run with the time to retry.

A public board's Show on / Default on Public Board settings are for the
public: visitors and non-members get them, read-only, and the board's own
members get the private side, so any view - Version Control, Email, Chat
and the rest - can be the read-only public view.

The card menu has a QR code of the card's link, drawn in the browser by
WeKan's own encoder, which the tests check module for module against
qrcode-svg.

The new strings are translated in every locale.

Thanks to xet7 !

Fixes #2015.
2026-10-14 12:09:34 +03:00

94 lines
4.1 KiB
JavaScript

// Board View / Version Control: the board as a GitHub / Gitea issue tracker
// (client/components/boards/versionControlView.*,
// docs/Features/Board/Version-Control-View.md). Reading needs nothing new -
// the cards, labels, comments and attachments are the board's own, already
// published to whoever can see the board. Only two writes need the server:
//
// vcsCreateIssue New issue: a card in the board's open list
// vcsSetIssueState Close / Reopen: the card moves to the closed / open list
//
// Both write through the ordinary collections, not `.direct`, so the change
// history hooks (server/models/changeHistoryHooks.js) record them and the
// History tab - the board's history table - can undo them like any other move.
import { Meteor } from 'meteor/meteor';
import { check, Match } from 'meteor/check';
import { ReactiveCache } from '/imports/reactiveCache';
import Cards from '/models/cards';
import { cardCreation } from '/models/cards';
import Lists from '/models/lists';
import { allowIsBoardMemberWithWriteAccess } from '/server/lib/utils';
const { cleanNewIssue, stateTarget, isSyncedIssue } = require('/models/lib/versionControlView');
async function writableBoard(userId, boardId) {
const board = await ReactiveCache.getBoard(boardId);
if (!userId || !board || !allowIsBoardMemberWithWriteAccess(userId, board)) throw new Meteor.Error('not-authorized');
return board;
}
// The list a state lives in, made when the board has none (a board that was
// not imported from a tracker has no "Closed" list until an issue is closed).
async function listFor(board, state) {
const lists = await ReactiveCache.getLists({ boardId: board._id, archived: false }, { sort: { sort: 1 } });
const target = stateTarget(lists || [], state);
if (target.listId) return target.listId;
const last = (lists || []).reduce((max, l) => Math.max(max, Number(l.sort) || 0), -1);
return Lists.insertAsync({
title: target.create, boardId: board._id, sort: last + 1, archived: false, createdAt: new Date(),
});
}
Meteor.methods({
async vcsCreateIssue(boardId, input) {
check(boardId, String);
check(input, { title: String, body: Match.Optional(String), labelIds: Match.Optional([String]) });
const userId = this.userId;
const board = await writableBoard(userId, boardId);
let issue;
try {
issue = cleanNewIssue(input);
} catch (e) {
throw new Meteor.Error(e.message);
}
const known = new Set((board.labels || []).map(l => l._id));
const listId = await listFor(board, 'open');
const swimlane = await board.getDefaultSwimlineAsync();
if (!listId || !swimlane) throw new Meteor.Error('vcs-no-list');
const siblings = await ReactiveCache.getCards({ boardId: board._id, listId, archived: false });
const cardId = await Cards.insertAsync({
title: issue.title,
description: issue.body,
boardId: board._id,
listId,
swimlaneId: swimlane._id,
userId,
labelIds: issue.labelIds.filter(id => known.has(id)),
sort: (siblings || []).length,
cardNumber: await board.getNextCardNumber(),
});
const created = await ReactiveCache.getCard(cardId);
if (created) await cardCreation(userId, created);
return { cardId };
},
async vcsSetIssueState(cardId, state) {
check(cardId, String);
check(state, Match.OneOf('open', 'closed'));
const userId = this.userId;
const card = await ReactiveCache.getCard(cardId);
if (!card) throw new Meteor.Error('not-found');
const board = await writableBoard(userId, card.boardId);
// A synced issue is closed and reopened in its tracker, and the next sync
// brings the state: moving the card out of its synced list would make
// the sync see the issue as gone.
if (isSyncedIssue(card)) throw new Meteor.Error('vcs-synced-issue');
// An archived card is a closed issue; reopening it restores it.
if (state === 'open' && card.archived) await card.restore();
const listId = await listFor(board, state);
if (listId && listId !== card.listId) {
await Cards.updateAsync(card._id, { $set: { listId, dateLastActivity: new Date() } });
}
return { listId };
},
});