mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
ExportEtherpad: Support custom subkeys
This commit is contained in:
parent
4b2e2dd9f2
commit
88c0ab8255
4 changed files with 30 additions and 5 deletions
|
@ -100,6 +100,9 @@
|
||||||
* `newOp()`: Deprecated in favor of the new `Op` class.
|
* `newOp()`: Deprecated in favor of the new `Op` class.
|
||||||
* The `AuthorManager.getAuthor4Token()` function is deprecated; use the new
|
* The `AuthorManager.getAuthor4Token()` function is deprecated; use the new
|
||||||
`AuthorManager.getAuthorId()` function instead.
|
`AuthorManager.getAuthorId()` function instead.
|
||||||
|
* The exported database records covered by the `exportEtherpadAdditionalContent`
|
||||||
|
server-side hook now include keys like `${customPrefix}:${padId}:*`, not just
|
||||||
|
`${customPrefix}:${padId}`.
|
||||||
|
|
||||||
# 1.8.18
|
# 1.8.18
|
||||||
|
|
||||||
|
|
|
@ -952,10 +952,10 @@ Called from `src/node/utils/ExportEtherpad.js` and
|
||||||
|
|
||||||
Called when exporting to an `.etherpad` file or when importing from an
|
Called when exporting to an `.etherpad` file or when importing from an
|
||||||
`.etherpad` file. The hook function should return prefixes for pad-specific
|
`.etherpad` file. The hook function should return prefixes for pad-specific
|
||||||
records that should be included in the export/import. On export, each
|
records that should be included in the export/import. On export, all
|
||||||
`${prefix}:${padId}` record (but not `${prefix}:${padId}:*` records) are
|
`${prefix}:${padId}` and `${prefix}:${padId}:*` records are included in the
|
||||||
included in the generated `.etherpad` file. On import, all `${prefix}:${padId}`
|
generated `.etherpad` file. On import, all `${prefix}:${padId}` and
|
||||||
and `${prefix}:${padId}:*` records are loaded into the database.
|
`${prefix}:${padId}:*` records are loaded into the database.
|
||||||
|
|
||||||
Context properties: None.
|
Context properties: None.
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const assert = require('assert').strict;
|
||||||
const authorManager = require('../db/AuthorManager');
|
const authorManager = require('../db/AuthorManager');
|
||||||
const hooks = require('../../static/js/pluginfw/hooks');
|
const hooks = require('../../static/js/pluginfw/hooks');
|
||||||
const padManager = require('../db/PadManager');
|
const padManager = require('../db/PadManager');
|
||||||
|
@ -34,7 +35,14 @@ exports.getPadRaw = async (padId, readOnlyId) => {
|
||||||
for (let i = 0; i <= pad.chatHead; ++i) data[`${pfx}:chat:${i}`] = await pad.getChatMessage(i);
|
for (let i = 0; i <= pad.chatHead; ++i) data[`${pfx}:chat:${i}`] = await pad.getChatMessage(i);
|
||||||
const prefixes = await hooks.aCallAll('exportEtherpadAdditionalContent');
|
const prefixes = await hooks.aCallAll('exportEtherpadAdditionalContent');
|
||||||
await Promise.all(prefixes.map(async (prefix) => {
|
await Promise.all(prefixes.map(async (prefix) => {
|
||||||
data[`${prefix}:${readOnlyId || padId}`] = await pad.db.get(`${prefix}:${padId}`);
|
const srcPfx = `${prefix}:${padId}`;
|
||||||
|
const dstPfx = `${prefix}:${readOnlyId || padId}`;
|
||||||
|
data[dstPfx] = await pad.db.get(srcPfx);
|
||||||
|
assert(!srcPfx.includes('*'));
|
||||||
|
for (const k of await pad.db.findKeys(`${srcPfx}:*`, null)) {
|
||||||
|
assert(k.startsWith(`${srcPfx}:`));
|
||||||
|
data[`${dstPfx}:${k.slice(srcPfx.length + 1)}`] = await pad.db.get(k);
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,24 +30,38 @@ describe(__filename, function () {
|
||||||
it('exports custom records', async function () {
|
it('exports custom records', async function () {
|
||||||
const pad = await padManager.getPad(padId);
|
const pad = await padManager.getPad(padId);
|
||||||
await pad.db.set(`custom:${padId}`, 'a');
|
await pad.db.set(`custom:${padId}`, 'a');
|
||||||
|
await pad.db.set(`custom:${padId}:`, 'b');
|
||||||
|
await pad.db.set(`custom:${padId}:foo`, 'c');
|
||||||
const data = await exportEtherpad.getPadRaw(pad.id, null);
|
const data = await exportEtherpad.getPadRaw(pad.id, null);
|
||||||
assert.equal(data[`custom:${padId}`], 'a');
|
assert.equal(data[`custom:${padId}`], 'a');
|
||||||
|
assert.equal(data[`custom:${padId}:`], 'b');
|
||||||
|
assert.equal(data[`custom:${padId}:foo`], 'c');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('export from read-only pad uses read-only ID', async function () {
|
it('export from read-only pad uses read-only ID', async function () {
|
||||||
const pad = await padManager.getPad(padId);
|
const pad = await padManager.getPad(padId);
|
||||||
const readOnlyId = await readOnlyManager.getReadOnlyId(padId);
|
const readOnlyId = await readOnlyManager.getReadOnlyId(padId);
|
||||||
await pad.db.set(`custom:${padId}`, 'a');
|
await pad.db.set(`custom:${padId}`, 'a');
|
||||||
|
await pad.db.set(`custom:${padId}:`, 'b');
|
||||||
|
await pad.db.set(`custom:${padId}:foo`, 'c');
|
||||||
const data = await exportEtherpad.getPadRaw(padId, readOnlyId);
|
const data = await exportEtherpad.getPadRaw(padId, readOnlyId);
|
||||||
assert.equal(data[`custom:${readOnlyId}`], 'a');
|
assert.equal(data[`custom:${readOnlyId}`], 'a');
|
||||||
|
assert.equal(data[`custom:${readOnlyId}:`], 'b');
|
||||||
|
assert.equal(data[`custom:${readOnlyId}:foo`], 'c');
|
||||||
assert(!(`custom:${padId}` in data));
|
assert(!(`custom:${padId}` in data));
|
||||||
|
assert(!(`custom:${padId}:` in data));
|
||||||
|
assert(!(`custom:${padId}:foo` in data));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not export records from pad with similar ID', async function () {
|
it('does not export records from pad with similar ID', async function () {
|
||||||
const pad = await padManager.getPad(padId);
|
const pad = await padManager.getPad(padId);
|
||||||
await pad.db.set(`custom:${padId}x`, 'a');
|
await pad.db.set(`custom:${padId}x`, 'a');
|
||||||
|
await pad.db.set(`custom:${padId}x:`, 'b');
|
||||||
|
await pad.db.set(`custom:${padId}x:foo`, 'c');
|
||||||
const data = await exportEtherpad.getPadRaw(pad.id, null);
|
const data = await exportEtherpad.getPadRaw(pad.id, null);
|
||||||
assert(!(`custom:${padId}x` in data));
|
assert(!(`custom:${padId}x` in data));
|
||||||
|
assert(!(`custom:${padId}x:` in data));
|
||||||
|
assert(!(`custom:${padId}x:foo` in data));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue