Add GlobalAdmin REST API + OpenAPI + api.py for Domains, attachment/avatar settings and org/team feature toggles (#5850, #4740, #4737).

Adds admin-only REST endpoints modelled on the existing /api/settings ones
(WebApp.handlers + Authentication.checkUserId gate + @operation JSDoc that
feeds the OpenAPI generator): GET /api/admin/domains; GET/PUT
/api/admin/attachment-settings (cloud secrets stay masked, update reuses the
updateAttachmentStorageSettings method path); and GET + per-id/all feature
toggles under /api/admin/orgs and /api/admin/teams. api.py gains matching
admindomains/attachmentsettings/editattachmentsetting/adminorgs/adminteams
and the org/team feature commands. Human REST-API.md docs left to the docs agent.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lauri OjansivuandClaude Opus 4.8 committed 2026-06-19 11:37:44 +03:00
1 parent 84678d3492
commit dbaa27dd67
5 files changed
+479

No files matched your search

+133
View File
@@ -131,6 +131,19 @@ If *nix: chmod +x api.py => ./api.py users
Admin API:
python3 api.py newuser USERNAME EMAIL PASSWORD
GlobalAdmin REST API (admin token required):
python3 api.py getsettings # Get the global Admin Panel settings
python3 api.py editsettings FIELD VALUE # Set one global settings field, e.g. productName "My WeKan", disableRegistration true
python3 api.py admindomains # List email domains with user counts (#5850)
python3 api.py attachmentsettings # Get attachment storage / upload-block settings (secrets masked)
python3 api.py editattachmentsetting DOTTED.FIELD VALUE # Set one attachment setting, e.g. limitSettings.avatarsUploadBlocked true (#4740)
python3 api.py adminorgs # List organizations with feature toggles (#4737)
python3 api.py editorgfeature ORGID FIELD true|false # Set one org feature: orgSharedTemplates, orgPropagateMembersToBoards, orgSyncMembersFromAuth
python3 api.py editallorgfeature FIELD true|false # Set one org feature on ALL orgs
python3 api.py adminteams # List teams with feature toggles (#4737)
python3 api.py editteamfeature TEAMID FIELD true|false # Set one team feature: teamSharedTemplates, teamPropagateMembersToBoards, teamSyncMembersFromAuth
python3 api.py editallteamfeature FIELD true|false # Set one team feature on ALL teams
"""
if arguments == 0:
@@ -832,6 +845,126 @@ if arguments >= 1:
print(body.text)
# ------- EDIT GLOBAL ADMIN SETTINGS END -----------
if arguments == 1 and sys.argv[1] == 'admindomains':
# ------- LIST ADMIN DOMAINS START -----------
# GlobalAdmin REST API: email domains with user counts (#5850).
admindomainsurl = wekanurl + 'api/admin/domains'
headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
print("=== ADMIN DOMAINS ===\n")
body = requests.get(admindomainsurl, headers=headers)
print(body.text)
# ------- LIST ADMIN DOMAINS END -----------
if arguments == 1 and sys.argv[1] == 'attachmentsettings':
# ------- GET ATTACHMENT SETTINGS START -----------
# GlobalAdmin REST API: attachment storage / upload-block settings.
# Secrets (S3/Azure/GCS) are masked; a <field>Set marker shows existence.
attachmentsettingsurl = wekanurl + 'api/admin/attachment-settings'
headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
print("=== ATTACHMENT SETTINGS ===\n")
body = requests.get(attachmentsettingsurl, headers=headers)
print(body.text)
# ------- GET ATTACHMENT SETTINGS END -----------
if arguments >= 3 and sys.argv[1] == 'editattachmentsetting':
# ------- EDIT ATTACHMENT SETTING START -----------
# GlobalAdmin REST API: set one attachment setting by dotted path.
# Usage: python3 api.py editattachmentsetting <dotted.field> <value>
# e.g. python3 api.py editattachmentsetting limitSettings.avatarsUploadBlocked true
attachmentsettingsurl = wekanurl + 'api/admin/attachment-settings'
headers = {'Accept': 'application/json', 'Content-type': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
field = sys.argv[2]
raw = sys.argv[3]
# Convert true/false to booleans; leave everything else as a string.
if raw in ('true', 'false'):
value = (raw == 'true')
else:
value = raw
# Expand a dotted path (e.g. limitSettings.avatarsUploadBlocked) into
# the nested object the partial-update endpoint expects.
body_obj = {}
cursor = body_obj
parts = field.split('.')
for part in parts[:-1]:
cursor[part] = {}
cursor = cursor[part]
cursor[parts[-1]] = value
body = requests.put(attachmentsettingsurl, json=body_obj, headers=headers)
print(body.text)
# ------- EDIT ATTACHMENT SETTING END -----------
if arguments == 1 and sys.argv[1] == 'adminorgs':
# ------- LIST ADMIN ORGS START -----------
# GlobalAdmin REST API: orgs with feature toggles (#4737).
adminorgsurl = wekanurl + 'api/admin/orgs'
headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
print("=== ADMIN ORGS ===\n")
body = requests.get(adminorgsurl, headers=headers)
print(body.text)
# ------- LIST ADMIN ORGS END -----------
if arguments >= 3 and sys.argv[1] == 'editorgfeature':
# ------- EDIT ORG FEATURE START -----------
# Usage: python3 api.py editorgfeature <orgId> <field> <true|false>
# field: orgSharedTemplates, orgPropagateMembersToBoards, orgSyncMembersFromAuth
orgid = sys.argv[2]
field = sys.argv[3]
raw = sys.argv[4]
value = (raw == 'true')
editorgfeatureurl = wekanurl + 'api/admin/orgs/' + orgid + '/features'
headers = {'Accept': 'application/json', 'Content-type': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
body = requests.put(editorgfeatureurl, json={field: value}, headers=headers)
print(body.text)
# ------- EDIT ORG FEATURE END -----------
if arguments >= 2 and sys.argv[1] == 'editallorgfeature':
# ------- EDIT ALL ORG FEATURE START -----------
# Usage: python3 api.py editallorgfeature <field> <true|false>
field = sys.argv[2]
raw = sys.argv[3]
value = (raw == 'true')
editallorgfeatureurl = wekanurl + 'api/admin/orgs/features'
headers = {'Accept': 'application/json', 'Content-type': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
body = requests.put(editallorgfeatureurl, json={'field': field, 'value': value}, headers=headers)
print(body.text)
# ------- EDIT ALL ORG FEATURE END -----------
if arguments == 1 and sys.argv[1] == 'adminteams':
# ------- LIST ADMIN TEAMS START -----------
# GlobalAdmin REST API: teams with feature toggles (#4737).
adminteamsurl = wekanurl + 'api/admin/teams'
headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
print("=== ADMIN TEAMS ===\n")
body = requests.get(adminteamsurl, headers=headers)
print(body.text)
# ------- LIST ADMIN TEAMS END -----------
if arguments >= 3 and sys.argv[1] == 'editteamfeature':
# ------- EDIT TEAM FEATURE START -----------
# Usage: python3 api.py editteamfeature <teamId> <field> <true|false>
# field: teamSharedTemplates, teamPropagateMembersToBoards, teamSyncMembersFromAuth
teamid = sys.argv[2]
field = sys.argv[3]
raw = sys.argv[4]
value = (raw == 'true')
editteamfeatureurl = wekanurl + 'api/admin/teams/' + teamid + '/features'
headers = {'Accept': 'application/json', 'Content-type': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
body = requests.put(editteamfeatureurl, json={field: value}, headers=headers)
print(body.text)
# ------- EDIT TEAM FEATURE END -----------
if arguments >= 2 and sys.argv[1] == 'editallteamfeature':
# ------- EDIT ALL TEAM FEATURE START -----------
# Usage: python3 api.py editallteamfeature <field> <true|false>
field = sys.argv[2]
raw = sys.argv[3]
value = (raw == 'true')
editallteamfeatureurl = wekanurl + 'api/admin/teams/features'
headers = {'Accept': 'application/json', 'Content-type': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
body = requests.put(editallteamfeatureurl, json={'field': field, 'value': value}, headers=headers)
print(body.text)
# ------- EDIT ALL TEAM FEATURE END -----------
if arguments == 1 and sys.argv[1] == 'user':
# ------- LIST OF ALL USERS START -----------
headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
@@ -11,6 +11,9 @@ import {
CLOUD_STORAGE_NAMES,
} from '/models/lib/fileStoreConstants';
import { check } from 'meteor/check';
import { WebApp } from 'meteor/webapp';
import { Authentication } from '/server/authentication';
import { sendJsonResult } from '/server/apiMiddleware';
import { refreshCloudStorageFromSettings, testCloudConnection } from '/models/lib/cloudStorage';
// Secret fields per cloud provider — never published to the client and only
@@ -678,3 +681,63 @@ Meteor.publish('attachmentStorageSettings', async function() {
return AttachmentStorageSettings.find({}, { fields: CLOUD_SECRET_PROJECTION });
});
/**
* @operation get_attachment_settings
* @tag Settings
*
* @summary Get the attachment storage / upload-block settings (GlobalAdmin)
*
* @description Only the global admin can call this. Returns the Admin Panel >
* Attachments settings document, including `limitSettings.attachmentsUploadBlocked`
* and `limitSettings.avatarsUploadBlocked` plus the size limits. Cloud-storage
* secret keys (S3 secretAccessKey, Azure accountKey/connectionString, GCS
* credentials) are masked and never returned; a boolean `<field>Set` marker
* shows whether a value exists.
*
* @return_type Object
*/
WebApp.handlers.get('/api/admin/attachment-settings', async function(req, res) {
try {
await Authentication.checkUserId(req.userId);
const settings = await Meteor.server.method_handlers[
'getAttachmentStorageSettings'
].call({ userId: req.userId });
sendJsonResult(res, { code: 200, data: settings });
} catch (error) {
sendJsonResult(res, { code: 200, data: error });
}
});
/**
* @operation update_attachment_settings
* @tag Settings
*
* @summary Update the attachment storage / upload-block settings (GlobalAdmin)
*
* @description Only the global admin can call this. The request body is a
* partial settings object (for example
* `{"limitSettings": {"avatarsUploadBlocked": true}}`). It is applied through
* the same update path as the `updateAttachmentStorageSettings` Meteor method,
* so validation and `$set` semantics are identical: cloud-storage secrets left
* blank are preserved. The masked, updated settings document is returned.
*
* @param {Object} settings the partial attachment settings to set
* @return_type Object
*/
WebApp.handlers.put('/api/admin/attachment-settings', async function(req, res) {
try {
await Authentication.checkUserId(req.userId);
const body = req.body || {};
await Meteor.server.method_handlers['updateAttachmentStorageSettings'].call(
{ userId: req.userId },
body,
);
const updated = await Meteor.server.method_handlers[
'getAttachmentStorageSettings'
].call({ userId: req.userId });
sendJsonResult(res, { code: 200, data: updated });
} catch (error) {
sendJsonResult(res, { code: 200, data: error });
}
});
+124
View File
@@ -1,7 +1,10 @@
import { Meteor } from 'meteor/meteor';
import { WebApp } from 'meteor/webapp';
import { ReactiveCache } from '/imports/reactiveCache';
import Org from '/models/org';
import { ensureIndex } from '/server/lib/mongoStartup';
import { Authentication } from '/server/authentication';
import { sendJsonResult } from '/server/apiMiddleware';
Meteor.methods({
async setCreateOrg(
@@ -253,3 +256,124 @@ Meteor.methods({
Meteor.startup(async () => {
await ensureIndex(Org, { orgDisplayName: 1 });
});
// #4737/#5850: per-org feature toggles exposed over the GlobalAdmin REST API.
const ORG_FEATURE_FIELDS = [
'orgSharedTemplates',
'orgPropagateMembersToBoards',
'orgSyncMembersFromAuth',
];
/**
* @operation get_admin_orgs
* @tag Organizations
*
* @summary List organizations with their feature toggles (GlobalAdmin)
*
* @description Only the global admin can call this. Returns every organization
* with its identifying fields and the per-org feature toggles shown as columns
* in Admin Panel > People > Organizations.
*
* @return_type [{_id: string, orgDisplayName: string, orgShortName: string, orgSharedTemplates: boolean, orgPropagateMembersToBoards: boolean, orgSyncMembersFromAuth: boolean}]
*/
WebApp.handlers.get('/api/admin/orgs', async function(req, res) {
try {
await Authentication.checkUserId(req.userId);
const orgs = await Org.find(
{},
{
fields: {
orgDisplayName: 1,
orgShortName: 1,
orgSharedTemplates: 1,
orgPropagateMembersToBoards: 1,
orgSyncMembersFromAuth: 1,
},
},
).fetchAsync();
const data = orgs.map(org => ({
_id: org._id,
orgDisplayName: org.orgDisplayName,
orgShortName: org.orgShortName,
orgSharedTemplates: !!org.orgSharedTemplates,
orgPropagateMembersToBoards: !!org.orgPropagateMembersToBoards,
orgSyncMembersFromAuth: !!org.orgSyncMembersFromAuth,
}));
sendJsonResult(res, { code: 200, data });
} catch (error) {
sendJsonResult(res, { code: 200, data: error });
}
});
/**
* @operation update_admin_org_features
* @tag Organizations
*
* @summary Set feature toggles on one organization (GlobalAdmin)
*
* @description Only the global admin can call this. The request body may
* contain any of `orgSharedTemplates`, `orgPropagateMembersToBoards` and
* `orgSyncMembersFromAuth` (booleans); only those whitelisted fields are
* `$set` on the organization. Returns the updated organization.
*
* @param {string} orgId the ID of the organization
* @param {Object} features the feature toggles to set
* @return_type Object
*/
WebApp.handlers.put('/api/admin/orgs/:orgId/features', async function(req, res) {
try {
await Authentication.checkUserId(req.userId);
const orgId = req.params.orgId;
const body = req.body || {};
const $set = {};
ORG_FEATURE_FIELDS.forEach(field => {
if (body[field] !== undefined) {
$set[field] = !!body[field];
}
});
if (Object.keys($set).length > 0) {
await Org.updateAsync(orgId, { $set });
}
const updated = await Org.findOneAsync(orgId);
sendJsonResult(res, { code: 200, data: updated });
} catch (error) {
sendJsonResult(res, { code: 200, data: error });
}
});
/**
* @operation update_all_admin_org_features
* @tag Organizations
*
* @summary Set one feature toggle on all organizations (GlobalAdmin)
*
* @description Only the global admin can call this. The request body is
* `{ field, value }` where `field` is one of `orgSharedTemplates`,
* `orgPropagateMembersToBoards` or `orgSyncMembersFromAuth` and `value` is a
* boolean. The field is `$set` on ALL organizations. Returns the number of
* organizations updated.
*
* @param {string} field the feature field to set
* @param {boolean} value the value to set
* @return_type {updated: number}
*/
WebApp.handlers.put('/api/admin/orgs/features', async function(req, res) {
try {
await Authentication.checkUserId(req.userId);
const body = req.body || {};
const field = body.field;
if (!ORG_FEATURE_FIELDS.includes(field)) {
sendJsonResult(res, { code: 200, data: { error: 'invalid-field' } });
return;
}
const value = !!body.value;
const updated = await Org.updateAsync(
{},
{ $set: { [field]: value } },
{ multi: true },
);
sendJsonResult(res, { code: 200, data: { updated } });
} catch (error) {
sendJsonResult(res, { code: 200, data: error });
}
});
+124
View File
@@ -1,7 +1,10 @@
import { Meteor } from 'meteor/meteor';
import { WebApp } from 'meteor/webapp';
import { ReactiveCache } from '/imports/reactiveCache';
import Team from '/models/team';
import { ensureIndex } from '/server/lib/mongoStartup';
import { Authentication } from '/server/authentication';
import { sendJsonResult } from '/server/apiMiddleware';
Meteor.methods({
async setCreateTeam(
@@ -231,3 +234,124 @@ Meteor.methods({
Meteor.startup(async () => {
await ensureIndex(Team, { teamDisplayName: 1 });
});
// #4737/#5850: per-team feature toggles exposed over the GlobalAdmin REST API.
const TEAM_FEATURE_FIELDS = [
'teamSharedTemplates',
'teamPropagateMembersToBoards',
'teamSyncMembersFromAuth',
];
/**
* @operation get_admin_teams
* @tag Teams
*
* @summary List teams with their feature toggles (GlobalAdmin)
*
* @description Only the global admin can call this. Returns every team with
* its identifying fields and the per-team feature toggles shown as columns in
* Admin Panel > People > Teams.
*
* @return_type [{_id: string, teamDisplayName: string, teamShortName: string, teamSharedTemplates: boolean, teamPropagateMembersToBoards: boolean, teamSyncMembersFromAuth: boolean}]
*/
WebApp.handlers.get('/api/admin/teams', async function(req, res) {
try {
await Authentication.checkUserId(req.userId);
const teams = await Team.find(
{},
{
fields: {
teamDisplayName: 1,
teamShortName: 1,
teamSharedTemplates: 1,
teamPropagateMembersToBoards: 1,
teamSyncMembersFromAuth: 1,
},
},
).fetchAsync();
const data = teams.map(team => ({
_id: team._id,
teamDisplayName: team.teamDisplayName,
teamShortName: team.teamShortName,
teamSharedTemplates: !!team.teamSharedTemplates,
teamPropagateMembersToBoards: !!team.teamPropagateMembersToBoards,
teamSyncMembersFromAuth: !!team.teamSyncMembersFromAuth,
}));
sendJsonResult(res, { code: 200, data });
} catch (error) {
sendJsonResult(res, { code: 200, data: error });
}
});
/**
* @operation update_admin_team_features
* @tag Teams
*
* @summary Set feature toggles on one team (GlobalAdmin)
*
* @description Only the global admin can call this. The request body may
* contain any of `teamSharedTemplates`, `teamPropagateMembersToBoards` and
* `teamSyncMembersFromAuth` (booleans); only those whitelisted fields are
* `$set` on the team. Returns the updated team.
*
* @param {string} teamId the ID of the team
* @param {Object} features the feature toggles to set
* @return_type Object
*/
WebApp.handlers.put('/api/admin/teams/:teamId/features', async function(req, res) {
try {
await Authentication.checkUserId(req.userId);
const teamId = req.params.teamId;
const body = req.body || {};
const $set = {};
TEAM_FEATURE_FIELDS.forEach(field => {
if (body[field] !== undefined) {
$set[field] = !!body[field];
}
});
if (Object.keys($set).length > 0) {
await Team.updateAsync(teamId, { $set });
}
const updated = await Team.findOneAsync(teamId);
sendJsonResult(res, { code: 200, data: updated });
} catch (error) {
sendJsonResult(res, { code: 200, data: error });
}
});
/**
* @operation update_all_admin_team_features
* @tag Teams
*
* @summary Set one feature toggle on all teams (GlobalAdmin)
*
* @description Only the global admin can call this. The request body is
* `{ field, value }` where `field` is one of `teamSharedTemplates`,
* `teamPropagateMembersToBoards` or `teamSyncMembersFromAuth` and `value` is a
* boolean. The field is `$set` on ALL teams. Returns the number of teams
* updated.
*
* @param {string} field the feature field to set
* @param {boolean} value the value to set
* @return_type {updated: number}
*/
WebApp.handlers.put('/api/admin/teams/features', async function(req, res) {
try {
await Authentication.checkUserId(req.userId);
const body = req.body || {};
const field = body.field;
if (!TEAM_FEATURE_FIELDS.includes(field)) {
sendJsonResult(res, { code: 200, data: { error: 'invalid-field' } });
return;
}
const value = !!body.value;
const updated = await Team.updateAsync(
{},
{ $set: { [field]: value } },
{ multi: true },
);
sendJsonResult(res, { code: 200, data: { updated } });
} catch (error) {
sendJsonResult(res, { code: 200, data: error });
}
});
+35
View File
@@ -1892,3 +1892,38 @@ Meteor.methods({
return users.map(user => sanitizeUserForSearch(user));
},
});
/**
* @operation get_admin_domains
* @tag Users
*
* @summary List email domains with their user counts (GlobalAdmin)
*
* @description Only the global admin can call this. Counts every user by the
* domain part of their primary email address (the first address in `emails`),
* mirroring the Admin Panel > People domain grouping. Domains are returned
* sorted by descending count, then alphabetically.
*
* @return_type [{domain: string, count: number}]
*/
WebApp.handlers.get('/api/admin/domains', async function(req, res) {
try {
await Authentication.checkUserId(req.userId);
const users = await Users.find({}, { fields: { emails: 1 } }).fetchAsync();
const counts = {};
for (const u of users) {
const addr = (u.emails && u.emails[0] && u.emails[0].address) || '';
const at = addr.lastIndexOf('@');
if (at === -1) continue;
const domain = addr.slice(at + 1).toLowerCase().trim();
if (!domain) continue;
counts[domain] = (counts[domain] || 0) + 1;
}
const data = Object.keys(counts)
.map(domain => ({ domain, count: counts[domain] }))
.sort((a, b) => b.count - a.count || a.domain.localeCompare(b.domain));
sendJsonResult(res, { code: 200, data });
} catch (error) {
sendJsonResult(res, { code: 200, data: error });
}
});