mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
"Add board members only from the same Organization or Team" was one checkbox in the
Login pane - which is where neither of the two things it restricts lives. It is two
checkboxes now, each in the pane it is about:
Admin Panel / People / Organizations [_] Add board members only from the same
Organization
Admin Panel / People / Teams [_] Add board members only from the same Team
A candidate may be added to a board when they share at least one ENABLED kind with
whoever adds them: an Organization when the first is on, a Team when the second is.
With both on that is "an Organization OR a Team" - exactly the rule the single
setting had - so an install that has the old field and neither new one is migrated
to both on first start, and nobody's restriction changes by upgrading. Ticking only
one is the new, narrower choice that was not expressible before.
models/settings.js boardMembersFromSameOrgOnly, boardMembersFromSameTeamOnly
server/models/settings.js the startup migration from the old single field
server/lib/orgTeamRestriction.js
boardMemberRestriction(setting) reads the pair - and
still reads the old field, so an install behaves the
same before the migration runs; canAddUserToBoard()
takes a flag per kind (the old restrictEnabled still
means both)
models/users.js sharesOrgWith / sharesTeamWith, and
sharesRestrictedOrgOrTeamWith(user, restriction)
Enforced in the same three places as before - inviteUserToBoard, the user-search
typeahead that must not offer what the server would reject, and the imported-user
reconciliation - so the two settings cannot drift apart from what the UI says.
Thanks to xet7 !
207 lines
6.3 KiB
JavaScript
207 lines
6.3 KiB
JavaScript
/* eslint-env mocha */
|
|
import { expect } from 'chai';
|
|
import { boardMemberRestriction, canAddUserToBoard } from '../orgTeamRestriction';
|
|
|
|
describe('orgTeamRestriction (#6116)', function() {
|
|
describe(canAddUserToBoard.name, function() {
|
|
it('allows when the restriction is disabled, even with no overlap', function() {
|
|
expect(
|
|
canAddUserToBoard({
|
|
restrictEnabled: false,
|
|
adderOrgs: ['orgA'],
|
|
adderTeams: ['teamA'],
|
|
candidateOrgs: ['orgB'],
|
|
candidateTeams: ['teamB'],
|
|
}),
|
|
).to.equal(true);
|
|
});
|
|
|
|
it('allows when disabled even with all-empty arrays', function() {
|
|
expect(
|
|
canAddUserToBoard({
|
|
restrictEnabled: false,
|
|
adderOrgs: [],
|
|
adderTeams: [],
|
|
candidateOrgs: [],
|
|
candidateTeams: [],
|
|
}),
|
|
).to.equal(true);
|
|
});
|
|
|
|
it('allows when enabled and a shared Organization exists', function() {
|
|
expect(
|
|
canAddUserToBoard({
|
|
restrictEnabled: true,
|
|
adderOrgs: ['orgX', 'orgShared'],
|
|
adderTeams: ['teamA'],
|
|
candidateOrgs: ['orgShared'],
|
|
candidateTeams: ['teamB'],
|
|
}),
|
|
).to.equal(true);
|
|
});
|
|
|
|
it('allows when enabled and a shared Team exists', function() {
|
|
expect(
|
|
canAddUserToBoard({
|
|
restrictEnabled: true,
|
|
adderOrgs: ['orgX'],
|
|
adderTeams: ['teamShared', 'teamA'],
|
|
candidateOrgs: ['orgY'],
|
|
candidateTeams: ['teamShared'],
|
|
}),
|
|
).to.equal(true);
|
|
});
|
|
|
|
it('denies when enabled and there is no Org or Team overlap', function() {
|
|
expect(
|
|
canAddUserToBoard({
|
|
restrictEnabled: true,
|
|
adderOrgs: ['orgA'],
|
|
adderTeams: ['teamA'],
|
|
candidateOrgs: ['orgB'],
|
|
candidateTeams: ['teamB'],
|
|
}),
|
|
).to.equal(false);
|
|
});
|
|
|
|
it('denies when enabled and arrays are empty', function() {
|
|
expect(
|
|
canAddUserToBoard({
|
|
restrictEnabled: true,
|
|
adderOrgs: [],
|
|
adderTeams: [],
|
|
candidateOrgs: [],
|
|
candidateTeams: [],
|
|
}),
|
|
).to.equal(false);
|
|
});
|
|
|
|
it('denies when enabled and the candidate has no orgs/teams', function() {
|
|
expect(
|
|
canAddUserToBoard({
|
|
restrictEnabled: true,
|
|
adderOrgs: ['orgA'],
|
|
adderTeams: ['teamA'],
|
|
candidateOrgs: [],
|
|
candidateTeams: [],
|
|
}),
|
|
).to.equal(false);
|
|
});
|
|
|
|
it('treats null/undefined arrays as empty (denies when enabled)', function() {
|
|
expect(
|
|
canAddUserToBoard({
|
|
restrictEnabled: true,
|
|
adderOrgs: undefined,
|
|
adderTeams: null,
|
|
candidateOrgs: undefined,
|
|
candidateTeams: null,
|
|
}),
|
|
).to.equal(false);
|
|
});
|
|
|
|
it('allows with null arrays when restriction is disabled', function() {
|
|
expect(
|
|
canAddUserToBoard({
|
|
restrictEnabled: false,
|
|
}),
|
|
).to.equal(true);
|
|
});
|
|
|
|
// The restriction is one setting per kind now - Organizations and Teams each
|
|
// carry their own checkbox, in the pane they are about.
|
|
it('with only the Organization restriction, a shared Team is not enough', function() {
|
|
expect(
|
|
canAddUserToBoard({
|
|
restrictOrgEnabled: true,
|
|
adderOrgs: ['orgA'],
|
|
adderTeams: ['teamShared'],
|
|
candidateOrgs: ['orgB'],
|
|
candidateTeams: ['teamShared'],
|
|
}),
|
|
).to.equal(false);
|
|
expect(
|
|
canAddUserToBoard({
|
|
restrictOrgEnabled: true,
|
|
adderOrgs: ['orgShared'],
|
|
adderTeams: [],
|
|
candidateOrgs: ['orgShared'],
|
|
candidateTeams: [],
|
|
}),
|
|
).to.equal(true);
|
|
});
|
|
|
|
it('with only the Team restriction, a shared Organization is not enough', function() {
|
|
expect(
|
|
canAddUserToBoard({
|
|
restrictTeamEnabled: true,
|
|
adderOrgs: ['orgShared'],
|
|
adderTeams: ['teamA'],
|
|
candidateOrgs: ['orgShared'],
|
|
candidateTeams: ['teamB'],
|
|
}),
|
|
).to.equal(false);
|
|
expect(
|
|
canAddUserToBoard({
|
|
restrictTeamEnabled: true,
|
|
adderOrgs: [],
|
|
adderTeams: ['teamShared'],
|
|
candidateOrgs: [],
|
|
candidateTeams: ['teamShared'],
|
|
}),
|
|
).to.equal(true);
|
|
});
|
|
|
|
it('with both enabled, either a shared Org or a shared Team is enough', function() {
|
|
const both = {
|
|
restrictOrgEnabled: true,
|
|
restrictTeamEnabled: true,
|
|
adderOrgs: ['orgA'],
|
|
adderTeams: ['teamShared'],
|
|
candidateOrgs: ['orgB'],
|
|
candidateTeams: ['teamShared'],
|
|
};
|
|
expect(canAddUserToBoard(both)).to.equal(true);
|
|
// ...which is exactly what the single setting it replaces did.
|
|
expect(
|
|
canAddUserToBoard({ ...both, restrictOrgEnabled: false, restrictTeamEnabled: false,
|
|
restrictEnabled: true }),
|
|
).to.equal(true);
|
|
});
|
|
|
|
it('neither enabled is unrestricted', function() {
|
|
expect(
|
|
canAddUserToBoard({
|
|
restrictOrgEnabled: false,
|
|
restrictTeamEnabled: false,
|
|
adderOrgs: ['orgA'],
|
|
adderTeams: ['teamA'],
|
|
candidateOrgs: ['orgB'],
|
|
candidateTeams: ['teamB'],
|
|
}),
|
|
).to.equal(true);
|
|
});
|
|
});
|
|
|
|
describe(boardMemberRestriction.name, function() {
|
|
it('reads the two settings', function() {
|
|
expect(boardMemberRestriction({ boardMembersFromSameOrgOnly: true }))
|
|
.to.deep.equal({ org: true, team: false });
|
|
expect(boardMemberRestriction({ boardMembersFromSameTeamOnly: true }))
|
|
.to.deep.equal({ org: false, team: true });
|
|
});
|
|
|
|
it('an install still on the old single setting keeps its rule', function() {
|
|
// Both kinds allowed, which is what "same Organization OR Team" meant - so an
|
|
// upgrade that has not run the migration yet behaves identically.
|
|
expect(boardMemberRestriction({ boardMembersFromSameOrgOrTeamOnly: true }))
|
|
.to.deep.equal({ org: true, team: true });
|
|
});
|
|
|
|
it('no setting document, or none of the fields, is unrestricted', function() {
|
|
expect(boardMemberRestriction(undefined)).to.deep.equal({ org: false, team: false });
|
|
expect(boardMemberRestriction({})).to.deep.equal({ org: false, team: false });
|
|
});
|
|
});
|
|
});
|