feat: per-board activity log

Adds an audit trail per board, visible from a new clock-icon button on the
toolbar. Useful for review-style work where someone wants to see who
contributed which references and when.

Logged events (high-signal only — canvas-edit noise intentionally skipped):
- image / video / pdf added (whether dropped, pasted, or pulled from a URL)
- board created / renamed / deleted
- thread started, resolved, reopened
- comment posted on a thread

Backend:
- new activity_logs table (id, board_id, user_id, denormalised actor name +
  email, action, target_type/id/label, metadata JSON, created_at) with an
  index on (board_id, created_at DESC).
- logActivity helper resolves the user once at log time and stores their
  display name + email so entries survive deactivation/rename.
- recordActivity wraps logActivity + a Socket.IO emit to the board's room
  so the panel updates live without polling.
- GET /api/boards/:id/activity?limit=&before= for pagination
  (collection-membership gated, viewer+).

Frontend:
- ActivityPanel side-drawer: time-grouped feed (Today / Yesterday / older),
  per-action icons + tone colours (add/remove/edit/comment), pagination
  via "Load older", live append on Socket.IO 'activity:new'.
- Relative timestamps refresh every 30s.
- Wired into Editor + Toolbar.

README updated; roadmap entry checked off.
This commit is contained in:
Hiren Kangad
2026-04-28 21:29:48 +05:30
parent 2fb71b4ae1
commit eb0bd210ac
12 changed files with 541 additions and 3 deletions
+35
View File
@@ -0,0 +1,35 @@
const { Router } = require('express');
const { authMiddleware } = require('../auth');
const { getBoardActivity } = require('../db');
const { resolveBoard } = require('./board-access');
const { formatRow } = require('../activity');
const router = Router();
router.use(authMiddleware);
/**
* GET /api/boards/:boardId/activity
* Returns recent activity entries for a board, newest first.
*
* Query params:
* limit — max entries to return (1-200, default 50)
* before — ISO timestamp; only entries created strictly before this
*/
router.get('/:boardId/activity', (req, res) => {
try {
const result = resolveBoard(req, res, 'viewer');
if (!result) return;
const { limit, before } = req.query;
const rows = getBoardActivity(result.board.id, { limit, before });
return res.json({
activity: rows.map(formatRow),
hasMore: rows.length === Math.max(1, Math.min(parseInt(limit, 10) || 50, 200)),
});
} catch (err) {
console.error('[activity] list error:', err);
return res.status(500).json({ error: 'Internal server error' });
}
});
module.exports = router;
+29
View File
@@ -12,6 +12,7 @@ const {
getCollectionMember,
} = require('../db');
const { deleteBoardImages: deleteBoardMinioImages } = require('../minio');
const { recordActivity } = require('../activity');
const router = Router();
@@ -81,6 +82,14 @@ router.post('/', (req, res) => {
createdBy: req.user.id,
});
recordActivity(req, {
boardId: board.id,
action: 'board.created',
targetType: 'board',
targetId: board.id,
targetLabel: board.name,
});
return res.status(201).json({ board });
} catch (err) {
console.error('[boards] create error:', err);
@@ -171,8 +180,20 @@ router.put('/:boardId', (req, res) => {
if (!result) return;
const { name, description } = req.body;
const prevName = result.board.name;
const updated = updateBoard(result.board.id, { name, description });
if (typeof name === 'string' && name.trim() && name.trim() !== prevName) {
recordActivity(req, {
boardId: updated.id,
action: 'board.renamed',
targetType: 'board',
targetId: updated.id,
targetLabel: updated.name,
metadata: { from: prevName, to: updated.name },
});
}
return res.json({ board: updated });
} catch (err) {
console.error('[boards] update error:', err);
@@ -195,6 +216,14 @@ router.delete('/:boardId', async (req, res) => {
console.error('[boards] MinIO cleanup error:', e);
}
recordActivity(req, {
boardId: result.board.id,
action: 'board.deleted',
targetType: 'board',
targetId: result.board.id,
targetLabel: result.board.name,
});
deleteBoard(result.board.id);
return res.json({ message: 'Board deleted' });
+26
View File
@@ -18,6 +18,7 @@ const {
getUserById,
} = require('../db');
const { hasCollectionRole, resolveBoard } = require('./board-access');
const { recordActivity } = require('../activity');
function resolveAuthorName(reqUser) {
if (reqUser.display_name || reqUser.username) {
@@ -108,6 +109,14 @@ router.post('/:boardId/threads', (req, res) => {
});
}
recordActivity(req, {
boardId: req.params.boardId,
action: 'thread.created',
targetType: 'thread',
targetId: threadId,
targetLabel: content.trim().slice(0, 80),
});
return res.status(201).json({ thread, comment });
} catch (err) {
console.error('[threads] create error:', err);
@@ -144,6 +153,15 @@ router.patch('/:boardId/threads/:threadId', (req, res) => {
});
}
if (status === 'resolved' || status === 'open') {
recordActivity(req, {
boardId: req.params.boardId,
action: status === 'resolved' ? 'thread.resolved' : 'thread.reopened',
targetType: 'thread',
targetId: req.params.threadId,
});
}
return res.json({ thread: updated });
} catch (err) {
console.error('[threads] status error:', err);
@@ -221,6 +239,14 @@ router.post('/:boardId/threads/:threadId/comments', (req, res) => {
});
}
recordActivity(req, {
boardId: req.params.boardId,
action: 'comment.added',
targetType: 'thread',
targetId: req.params.threadId,
targetLabel: content.trim().slice(0, 80),
});
return res.status(201).json({ comment });
} catch (err) {
console.error('[threads] add comment error:', err);
+29 -1
View File
@@ -6,9 +6,10 @@ const https = require('https');
const http = require('http');
const { URL } = require('url');
const { authMiddleware } = require('../auth');
const { getBoard, getCollectionMember, createImage, createMediaJob, createPdfPage, updateImagePageCount } = require('../db');
const { getBoard, getCollectionMember, createImage, getImage, createMediaJob, createPdfPage, updateImagePageCount } = require('../db');
const { putBuffer, getImageUrl, MIME_TO_EXT, MAX_FILE_SIZE } = require('../minio');
const { pdfInfo, bufferToTempFile } = require('../pdf-utils');
const { recordActivity } = require('../activity');
const router = Router();
@@ -192,6 +193,15 @@ router.post('/boards/:boardId/images', upload.single('image'), async (req, res)
});
}
recordActivity(req, {
boardId: board.id,
action: 'pdf.added',
targetType: 'pdf',
targetId: imageId,
targetLabel: originalname,
metadata: { pageCount: info.pageCount, fileSize: size },
});
return res.status(201).json({
id: image.id,
media_type: 'pdf',
@@ -233,6 +243,15 @@ router.post('/boards/:boardId/images', upload.single('image'), async (req, res)
createMediaJob({ id: jobId, imageId, boardId: board.id, type: 'poster' });
}
recordActivity(req, {
boardId: board.id,
action: `${mediaType}.added`,
targetType: mediaType,
targetId: imageId,
targetLabel: originalname,
metadata: { fileSize: size, mimeType: mimetype, source: 'upload' },
});
return res.status(201).json({
id: image.id,
url: publicUrl,
@@ -354,6 +373,15 @@ router.post('/boards/:boardId/images/from-url', async (req, res) => {
createMediaJob({ id: jobId, imageId, boardId: board.id, type: 'poster' });
}
recordActivity(req, {
boardId: board.id,
action: `${mediaType}.added`,
targetType: mediaType,
targetId: imageId,
targetLabel: filename,
metadata: { fileSize: buffer.length, mimeType, source: 'url', sourceUrl: url },
});
return res.status(201).json({
id: image.id,
url: publicUrl,