Files
wekan/models/customBoardRoles.js
T
Lauri Ojansivu 50bb989eb8 Custom board roles, and team memberships that leave with the team.
#3022 (decided 2026-10-14): a site admin builds named roles in Admin
Panel / People / Roles from the capability matrix - sees all cards,
comments, edits, moves cards, invites - and a board admin gives one to a
member in the same popup as the built-in roles. Board admin stays
built-in. Every permission check asks boardRoleCapabilities, which
answers a custom role from the role; the member's built-in flags carry
the strongest built-in role that grants nothing more (fallbackRoleFor,
checked for every combination), so code reading a flag never grants
more, and a deleted role leaves exactly that. Where a role is asked by
name (hasWorker, isCommentOnly, ...) a custom role reads as the built-in
role that does what it does; commenting is asked as a capability
everywhere. Invites, REST whole-board reads, imports (a foreign custom
role is dropped) and member mapping (all eight flags now, not four)
follow it. The six new strings are translated in all 234 locales.

#4178 (decided 2026-10-14): a team or organization that gives board
memberships takes them away again when the user leaves it - only those:
each records where it came from (grantedBy), a direct membership is
never touched, a board admin is kept, and a board admin's own add or
removal is final. Teams through user edits, LDAP, OIDC and the board
sidebar; organizations where they propagate members.

Also: the Roles Status table gets a Move cards column; the comment form,
reactions and chat ask the comment capability (a No comments member was
offered reactions the server refused).

Tests: customBoardRoles and groupBoardMembership node suites, and the
runtime suites (9 passing) against a real database.

Thanks to xet7 and mfnalex !

Fixes #3022,
Fixes #4178.
2026-10-14 08:20:49 +03:00

65 lines
1.8 KiB
JavaScript

import { Mongo } from 'meteor/mongo';
const { SimpleSchema } = require('/imports/simpleSchema');
// Custom board roles (#3022): named roles an administrator builds in Admin
// Panel / People / Roles from the capability matrix in
// models/lib/boardRoleCapabilities.js (CUSTOM_ROLE_CAPABILITIES). A board
// member is given one by board admin, like a built-in role, and carries its id
// in `customRoleId` - plus, in the old per-role flags, the strongest built-in
// role that grants nothing more (fallbackRoleFor), so code that still reads a
// flag never grants more than the custom role does.
//
// Only site admins write this collection, and only through the methods in
// server/customBoardRoles.js. Every signed-in user reads it: a role's name and
// what it may do are what the board shows its members.
export const CUSTOM_ROLE_NAME_MAX = 60;
const CustomBoardRoles = new Mongo.Collection('customBoardRoles');
CustomBoardRoles.attachSchema(
new SimpleSchema({
name: {
type: String,
min: 1,
max: CUSTOM_ROLE_NAME_MAX,
},
capabilities: {
type: Object,
blackbox: true,
},
sort: {
type: Number,
optional: true,
},
createdAt: {
type: Date,
optional: true,
// eslint-disable-next-line consistent-return
autoValue() {
if (this.isInsert) {
return new Date();
} else if (this.isUpsert) {
return { $setOnInsert: new Date() };
} else {
this.unset();
}
},
},
modifiedAt: {
type: Date,
optional: true,
// eslint-disable-next-line consistent-return
autoValue() {
if (this.isInsert || this.isUpsert || this.isUpdate) {
return new Date();
} else {
this.unset();
}
},
},
}),
);
export default CustomBoardRoles;