Files
wekan/server/publications/userBoardView.js
T
Lauri Ojansivu 80fb317fda Remember the board view per board.
The view menu sits on a board, but choosing a view there changed it for
every board, so one board could not stay on Calendar while another stayed
on Swimlanes. A view chosen on a board is now that board's own
(profile.boardViews, published to its owner beside the shared value). A
board without its own choice uses the view every board shared before, then
the board's default, so nothing changes for anybody until they choose a
view on a board. A choice made off any board still sets the shared view,
and the browser's stored view follows only that one. The server accepts only
a known view under a safe board key. Label text visibility per board, the
other half of #4256, was done earlier.

The guards that pinned the single shared view now pin both; a new test runs
the stored-view logic per board, and a Playwright case checks two boards.

Thanks to DimDz, Meeques and xet7 !

Fixes #4906,
Fixes #4256.
2026-10-08 12:12:24 +03:00

36 lines
1.4 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
// #6691: this also follows this.setUserId() during admin impersonation. The
// preference belongs to the connection's user, not every board member.
Meteor.publish('userBoardView', async function() {
if (!this.userId) return this.ready();
// DDP merges only top-level fields. A narrow profile publication can win
// over the full account profile after impersonation, hiding boardView even
// when another publication supplies it. Publish this one private preference
// under its own top-level field; do not compete for the profile object.
let stopped = false;
let handle;
this.onStop(() => {
stopped = true;
if (handle) handle.stop();
});
handle = await Meteor.users.find({ _id: this.userId }, {
fields: { 'profile.boardView': 1, 'profile.boardViews': 1 },
}).observeChangesAsync({
added: (id, fields) => {
// #4906 / #4256: and the view chosen on each board.
if (!stopped) this.added('users', id, { boardViewPreference: fields.profile?.boardView,
boardViewPreferences: fields.profile?.boardViews || {} });
},
changed: (id, fields) => {
if (!stopped) this.changed('users', id, { boardViewPreference: fields.profile?.boardView,
boardViewPreferences: fields.profile?.boardViews || {} });
},
removed: id => {
if (!stopped) this.removed('users', id);
},
});
if (stopped) handle.stop();
else this.ready();
});