Skip to content

Commit

Permalink
[feature] Add deleteTenant command
Browse files Browse the repository at this point in the history
  • Loading branch information
konovalovsergey committed Oct 14, 2024
1 parent ca476d3 commit 66680b5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Common/sources/commondefines.js
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,8 @@ const c_oPublishType = {
closeConnection: 13,
changesNotify: 14,
changeConnecitonInfo: 15,
rpc: 16
rpc: 16,
dropTenantConnections: 17
};
const c_oAscCsvDelimiter = {
None: 0,
Expand Down
14 changes: 14 additions & 0 deletions Common/sources/tenantManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

'use strict';

const { rm } = require('fs/promises');
const config = require('config');
const co = require('co');
const NodeCache = require( "node-cache" );
Expand Down Expand Up @@ -406,6 +407,18 @@ async function readLicenseTenant(ctx, licenseFile, baseVerifiedLicense) {
return [res, oLicense];
}


async function deleteTenant(ctx) {
try {
if (isMultitenantMode(ctx) && !isDefaultTenant(ctx)) {
let tenantPath = utils.removeIllegalCharacters(ctx.tenant);
await rm(path.join(cfgTenantsBaseDir, tenantPath), {force: true, recursive: true, maxRetries: 3});
}
} catch (error) {
ctx.logger.error('deleteTenants error: ', error.stack);
}
}

exports.getAllTenants = getAllTenants;
exports.getDefautTenant = getDefautTenant;
exports.getTenantByConnection = getTenantByConnection;
Expand All @@ -419,3 +432,4 @@ exports.setDefLicense = setDefLicense;
exports.isMultitenantMode = isMultitenantMode;
exports.setMultitenantMode = setMultitenantMode;
exports.isDefaultTenant = isDefaultTenant;
exports.deleteTenant = deleteTenant;
23 changes: 22 additions & 1 deletion DocService/sources/DocsCoServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,15 @@ function dropUserFromDocument(ctx, docId, userId, description) {
}
}
}

function dropTenantConnections(ctx, code, description) {
for (let i = 0; i < connections.length; ++i) {
let conn = connections[i];
if (conn.tenant === ctx.tenant && !(conn.user?.view || conn.isCloseCoAuthoring)) {
sendDataDrop(ctx, conn, code, description);
}
}
}
function getLocalConnectionCount(ctx, docId) {
let tenant = ctx.tenant;
return connections.reduce(function(count, conn) {
Expand Down Expand Up @@ -3568,6 +3577,9 @@ exports.install = function(server, callbackFunction) {
dropUserFromDocument(ctx, data.docId, data.users[i], data.description);
}
break;
case commonDefines.c_oPublishType.dropTenantConnections:
dropTenantConnections(ctx, constants.DROP_CODE, constants.DROP_REASON);
break;
case commonDefines.c_oPublishType.closeConnection:
closeUsersConnection(ctx, data.docId, data.usersMap, data.isOriginalId, data.code, data.description);
break;
Expand Down Expand Up @@ -4194,7 +4206,7 @@ exports.licenseInfo = function(req, res) {
});
};
function validateInputParams(ctx, authRes, command) {
const commandsWithoutKey = ['version', 'license', 'getForgottenList'];
const commandsWithoutKey = ['version', 'license', 'getForgottenList', 'deleteTenant'];
const isValidWithoutKey = commandsWithoutKey.includes(command.c);
const isDocIdString = typeof command.key === 'string';

Expand Down Expand Up @@ -4361,6 +4373,15 @@ function* commandHandle(ctx, params, req, output) {
forgottenData.keys = yield* getFilesKeys(ctx, tenForgottenFiles);
break;
}
case 'deleteTenant': {
if (tenantManager.isMultitenantMode(ctx)) {
yield publish(ctx, {type: commonDefines.c_oPublishType.dropTenantConnections, ctx: ctx});
yield tenantManager.deleteTenant(ctx);
} else {
ctx.logger.warn('commandFromServer deleteTenant works only when tenants is enabled');
}
break;
}
case 'version': {
output.version = `${commonDefines.buildVersion}.${commonDefines.buildNumber}`;
break;
Expand Down

0 comments on commit 66680b5

Please sign in to comment.