Files
wekan/models/org.js
T
Lauri Ojansivu 36b899b9d6 Multitenancy: one WeKan server for many domains, with Organizations as tenants.
Implements option D of docs/Design/Multitenancy/Multitenancy.md, which that
document now describes as shipped.

An Organization may claim hostnames (Admin Panel / People / Organizations ->
Edit), carry its own branding - product name, logos, help link, legal notice and
theme colour - and have its own Organization admins, appointed from the row's
"..." menu. The request's host picks the Organization; its branding replaces the
instance branding for that request, and the client bundle that host serves points
its DDP connection back at that host instead of at the one ROOT_URL.

An Organization admin administers their own Organization and nothing else: its
people, its Organizations row, its theme colour and its backups. They can never
grant the site-wide Admin flag, never manage a site admin, and never see another
Organization's people or archives.

Per-tenant backup and restore is one new control in Admin Panel / Attachments /
Backup - Scope. An Organization's archive holds its boards and everything on them
plus the attachments those boards use, and no accounts, no instance settings and
no org/team documents, because those are shared. A restore may only write to
boards that Organization owns: the board ids are the intersection of what the
archive claims with what the Organization really owns, every document is checked
against that, and "replace all" replaces that Organization's documents rather
than everyone's.

Admin Panel / Settings / Visibility gains a Change color section above Logo: the
site theme, rendered by the SAME shared picker as Board Settings and Member
Settings - one template for all three, the way one shared table page serves every
table. Its design is the new docs/Design/Page/Theme.md. The order of themes is
WeKan's default theme, then the site theme (an Organization's own value on its own
hosts), then a user's own override; a board's own colour still owns the board page.

All of it is OFF unless the server is started with MULTITENANCY=true (plus
MULTITENANCY_TRUST_PROXY_HOST=true when a trusted proxy sets X-Forwarded-Host), so
an instance that has never heard of tenants answers exactly as before. One WeKan
server per customer remains the supported topology for customers who must not
share a process, and the design says plainly what this does NOT isolate.

The decisions are three pure modules - models/lib/tenants.js, tenantAdmin.js and
tenantBackup.js - so the same rules run on the client, on the server and in the
tests. Four new suites pin the separation rather than the plumbing: forged Host
headers, cross-tenant queries, privilege escalation and cross-tenant restores.

Thanks to xet7 !
2026-07-26 07:48:18 +03:00

194 lines
4.8 KiB
JavaScript

import { Mongo } from 'meteor/mongo';
import { ReactiveCache } from '/imports/reactiveCache';
const { SimpleSchema } = require('/imports/simpleSchema');
const Org = new Mongo.Collection('org');
/**
* A Organization in Wekan. A Enterprise in Trello.
*/
Org.attachSchema(
new SimpleSchema({
orgDisplayName: {
/**
* the name to display for the organization
*/
type: String,
optional: true,
},
orgDesc: {
/**
* the description the organization
*/
type: String,
optional: true,
max: 190,
},
orgShortName: {
/**
* short name of the organization
*/
type: String,
optional: true,
max: 255,
},
orgAutoAddUsersWithDomainName: {
/**
* automatically add users with domain name
*/
type: String,
optional: true,
max: 255,
},
orgWebsite: {
/**
* website of the organization
*/
type: String,
optional: true,
max: 255,
},
orgIsActive: {
/**
* status of the organization
*/
type: Boolean,
optional: true,
},
orgSharedTemplates: {
/**
* #5850: members may drag personal Template Boards onto this org to share
* (per-org form of "Shared Templates for Organizations"). Off by default.
*/
type: Boolean,
optional: true,
},
orgPropagateMembersToBoards: {
/**
* #4737: add this org's members to the boards that list this org. Off by default.
*/
type: Boolean,
optional: true,
},
orgSyncMembersFromAuth: {
/**
* #4737: this org's membership is maintained by the authentication
* provider's group/membership sync (LDAP, OAuth2/OIDC, SAML, etc.). Off by default.
*/
type: Boolean,
optional: true,
},
orgDomains: {
/**
* Multitenancy option D (docs/Design/Multitenancy/Multitenancy.md): the
* hostname(s) this Organization is served on, free text separated by commas,
* semicolons or whitespace - e.g. "a.example.com, kanban.example.org". A
* request whose host matches one of these is that tenant's request, and the
* org's branding below replaces the instance branding for it. Empty (the
* default) means the org is not a tenant and nothing changes.
* Only read when the deployment sets MULTITENANCY=true.
*/
type: String,
optional: true,
max: 1000,
},
orgProductName: {
/**
* Per-tenant branding. Each of these overrides the SAME-named instance
* setting of Admin Panel / Settings / Visibility for this tenant's requests,
* and an empty one leaves the instance value alone - so a tenant overrides
* only what it sets. See models/lib/tenants.js BRANDING_FIELDS.
*/
type: String,
optional: true,
max: 255,
},
orgThemeColor: {
/**
* The site theme for this Organization's hosts - the layer between WeKan's
* default theme and a user's own override (docs/Theme/Theme.md). Set in
* Admin Panel / Settings / Visibility / Change color.
*/
type: String,
optional: true,
max: 255,
},
orgThemeCustomColors: {
/**
* The custom colours of that theme, for the flat (1 colour) and clear
* (2 colours, a gradient) categories.
*/
type: Array,
optional: true,
},
'orgThemeCustomColors.$': {
type: String,
optional: true,
},
orgCustomLoginLogoImageUrl: {
type: String,
optional: true,
max: 1000,
},
orgCustomLoginLogoLinkUrl: {
type: String,
optional: true,
max: 1000,
},
orgTextBelowCustomLoginLogo: {
type: String,
optional: true,
max: 1000,
},
orgCustomTopLeftCornerLogoImageUrl: {
type: String,
optional: true,
max: 1000,
},
orgCustomTopLeftCornerLogoLinkUrl: {
type: String,
optional: true,
max: 1000,
},
orgCustomHelpLinkUrl: {
type: String,
optional: true,
max: 1000,
},
orgLegalNotice: {
type: String,
optional: true,
max: 1000,
},
createdAt: {
/**
* creation date of the organization
*/
type: Date,
// 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,
// eslint-disable-next-line consistent-return
autoValue() {
if (this.isInsert || this.isUpsert || this.isUpdate) {
return new Date();
} else {
this.unset();
}
},
},
}),
);
export default Org;