mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Issue #6732: the board-header "Show dependencies" button wrote one shared board field, so one user turning the lines on or off did it for everybody, and only board admins could write that field, so a member - or anyone on a public board - who could see the board could not turn them on at all. The button is gone from the header. At the top of Member Settings are now: - Show My Dependencies - Show Board Dependencies - Import - Export Both switches are off by default and saved in the user's profile, so each user decides for themselves and anyone who can view a board may show its dependencies. Board Dependencies stay on the board's cards. They may now be edited by every role that can edit OR move cards - a Worker included - and by an assigned-only member on the cards assigned to them; one rule (models/lib/dependencyAccess.js) is applied by new server methods, by the card details, the line popup, drawing on the board, Import and the REST routes. My Dependencies are a new layer in the user's profile: each user's own lines between cards they can see, drawn dashed and seen only by them. The client cannot write them directly; only the methods, which check card access, can. Import and Export work on the open board in the Board Settings / Export formats (JSON, and SVG that re-imports). Importing Board Dependencies is offered only to roles that may edit or move cards, and every import now combines: a line already there is kept exactly as it is, and only missing lines are added - also for All Boards / Import / Dependencies, which used to overwrite an existing line's type and colour. The design is written up in docs/Features/Editor/RedStrings/Board-And-My-Dependencies.md. Tests: the role table, viewing, assigned-only scope, normalizing and combining (unit), with guards that the header toggle and every reader of the old board flag are gone and every write goes through the rule; a full-app test drives the methods as admin, Worker, read-only, assigned-only and a stranger; Playwright covers the menu order and defaults, a per-user switch that leaves another member's view alone, a read-only member's My Dependencies (dashed, unseen by the owner) with import and export, and a Worker's combining board import - in Chromium and WebKit. Header, fold and mobile guards that listed the old button are updated. 567 server tests pass. Thanks to nalilord and xet7 ! Fixes #6732.
105 lines
4.3 KiB
JavaScript
105 lines
4.3 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { ReactiveVar } from 'meteor/reactive-var';
|
|
import { TAPi18n } from '/imports/i18n';
|
|
import { Utils } from '/client/lib/utils';
|
|
import { dependencyVisibility, canEditBoardDependenciesHere, myDependencyLines } from '/client/lib/dependencyLayers';
|
|
import { collectDependencyLines, collectMyDependencyLines, exportDependenciesJson, exportDependenciesSvg }
|
|
from '/client/lib/exportDependencies';
|
|
import { parseDependencyLines } from '/client/lib/importDependencies';
|
|
|
|
// #6732: Show My / Show Board Dependencies, Import and Export, at the top of
|
|
// Member Settings. Showing is each user's own choice; Board Dependencies are
|
|
// imported only by roles that may edit or move cards (the server checks again).
|
|
|
|
Template.memberDependencyMenuItems.helpers({
|
|
showMyDependencies() {
|
|
return dependencyVisibility().mine;
|
|
},
|
|
showBoardDependencies() {
|
|
return dependencyVisibility().board;
|
|
},
|
|
});
|
|
|
|
Template.memberDependencyMenuItems.events({
|
|
'click .js-toggle-my-dependencies'(event) {
|
|
event.preventDefault();
|
|
Meteor.callAsync('setDependencyVisibility', 'mine', !dependencyVisibility().mine).catch(() => {});
|
|
},
|
|
'click .js-toggle-board-dependencies'(event) {
|
|
event.preventDefault();
|
|
Meteor.callAsync('setDependencyVisibility', 'board', !dependencyVisibility().board).catch(() => {});
|
|
},
|
|
'click .js-import-member-dependencies': Popup.open('importMemberDependencies'),
|
|
'click .js-export-member-dependencies': Popup.open('exportMemberDependencies'),
|
|
});
|
|
|
|
Template.importMemberDependenciesPopup.onCreated(function () {
|
|
this.fileText = new ReactiveVar('');
|
|
this.importResult = new ReactiveVar('');
|
|
});
|
|
|
|
Template.importMemberDependenciesPopup.helpers({
|
|
canEditBoardDependencies() {
|
|
return canEditBoardDependenciesHere(Utils.getCurrentBoard());
|
|
},
|
|
importResult() {
|
|
return Template.instance().importResult.get();
|
|
},
|
|
});
|
|
|
|
Template.importMemberDependenciesPopup.events({
|
|
'change .js-import-member-dependencies-file'(event, tpl) {
|
|
const file = event.currentTarget.files && event.currentTarget.files[0];
|
|
if (!file) return;
|
|
const reader = new FileReader();
|
|
reader.onload = e => tpl.fileText.set(e.target.result || '');
|
|
reader.readAsText(file);
|
|
},
|
|
async 'submit .js-import-member-dependencies-form'(event, tpl) {
|
|
event.preventDefault();
|
|
const board = Utils.getCurrentBoard();
|
|
const chosen = tpl.find('input[name="dependency-layer"]:checked');
|
|
const layer = chosen ? chosen.value : 'mine';
|
|
const fileEl = tpl.find('.js-import-member-dependencies-file');
|
|
const filename = fileEl && fileEl.files && fileEl.files[0] ? fileEl.files[0].name : '';
|
|
const text = tpl.fileText.get() || tpl.find('.js-import-member-dependencies-text').value || '';
|
|
let lines = [];
|
|
try {
|
|
lines = parseDependencyLines(text, filename);
|
|
} catch (e) {
|
|
tpl.importResult.set(TAPi18n.__('import-dependencies-parse-error'));
|
|
return;
|
|
}
|
|
if (!board || lines.length === 0) {
|
|
tpl.importResult.set(TAPi18n.__('import-dependencies-empty'));
|
|
return;
|
|
}
|
|
try {
|
|
const res = await Meteor.callAsync(layer === 'board' ? 'importBoardDependencies' : 'importMyDependencies',
|
|
board._id, lines);
|
|
tpl.importResult.set(TAPi18n.__('import-dependencies-merged',
|
|
{ imported: res.imported, skipped: res.skipped, unmatched: res.unmatched }));
|
|
} catch (err) {
|
|
tpl.importResult.set(err.error === 'not-authorized'
|
|
? TAPi18n.__('dependencies-board-edit-required') : (err.reason || err.message || String(err)));
|
|
}
|
|
},
|
|
});
|
|
|
|
function exportLayer(layer, format) {
|
|
const board = Utils.getCurrentBoard();
|
|
if (!board) return;
|
|
const lines = layer === 'my'
|
|
? collectMyDependencyLines(board._id, myDependencyLines(board._id))
|
|
: collectDependencyLines(board._id);
|
|
(format === 'svg' ? exportDependenciesSvg : exportDependenciesJson)(board._id, lines, layer);
|
|
Popup.close();
|
|
}
|
|
|
|
Template.exportMemberDependenciesPopup.events({
|
|
'click .js-export-my-dependencies-json'(event) { event.preventDefault(); exportLayer('my', 'json'); },
|
|
'click .js-export-my-dependencies-svg'(event) { event.preventDefault(); exportLayer('my', 'svg'); },
|
|
'click .js-export-board-dependencies-json'(event) { event.preventDefault(); exportLayer('board', 'json'); },
|
|
'click .js-export-board-dependencies-svg'(event) { event.preventDefault(); exportLayer('board', 'svg'); },
|
|
});
|