Files
wekan/server/lib/archiveContributions.js
T
Lauri Ojansivu 1c200407a2 Show archived-card contributions in Pulse
Add a UTC annual archive grid with count shading, colored label tooltips,
year selection and keyboard/touch details. Scope counts and labels to the
board and each assigned-only viewer, and exclude restored or undated cards.

Verify calendar aggregation with unit tests and real MongoDB/DDP/Chromium
coverage for the UI, all assigned-only roles, invalid input and isolation.
Document current-archive semantics and the remaining issue-audit work.

Thanks to xet7 !

Fixes #5444,
2026-09-28 23:56:20 +03:00

24 lines
1.2 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import Boards from '/models/boards';
import Cards from '/models/cards';
const { archiveYear, archiveContributions } = require('/models/lib/archiveContributions');
const { assignedOnlyCardScope } = require('/models/lib/boardCardScope');
export async function loadArchiveContributions(userId, boardId, year) {
year = archiveYear(year);
const board = await Boards.findOneAsync(boardId);
if (!board || !board.isVisibleBy({ _id: userId })) throw new Meteor.Error('not-authorized');
const scope = assignedOnlyCardScope(board, userId);
const report = archiveContributions(year, board.labels);
// Iterate projected records instead of retaining the board's cards in memory.
await Cards.find({ boardId, archived: true,
archivedAt: { $gte: report.from, $lt: report.until }, ...(scope || {}),
}, { fields: { archived: 1, archivedAt: 1, labelIds: 1 } }).forEachAsync(card => report.add(card));
const current = await Boards.findOneAsync(boardId);
if (!current || !current.isVisibleBy({ _id: userId }) ||
JSON.stringify(assignedOnlyCardScope(current, userId)) !== JSON.stringify(scope)) {
throw new Meteor.Error('not-authorized');
}
return report.result();
}