mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: #13255, remote user-to-category migration should not move shares that are already in an existing cid
This commit is contained in:
@@ -409,9 +409,11 @@ async function _migratePersonToGroup(categoryObjs) {
|
|||||||
|
|
||||||
await Promise.all(ids.map(async (id) => {
|
await Promise.all(ids.map(async (id) => {
|
||||||
const shares = await db.getSortedSetMembers(`uid:${id}:shares`);
|
const shares = await db.getSortedSetMembers(`uid:${id}:shares`);
|
||||||
const exists = await topics.exists(shares);
|
let cids = await topics.getTopicsFields(shares, ['cid']);
|
||||||
|
cids = cids.map(o => o.cid);
|
||||||
await Promise.all(shares.map(async (share, idx) => {
|
await Promise.all(shares.map(async (share, idx) => {
|
||||||
if (exists[idx]) {
|
const cid = cids[idx];
|
||||||
|
if (cid === -1) {
|
||||||
await topics.tools.move(share, {
|
await topics.tools.move(share, {
|
||||||
cid: id,
|
cid: id,
|
||||||
uid: 'system',
|
uid: 'system',
|
||||||
|
|||||||
@@ -126,6 +126,36 @@ describe('Actor asserton', () => {
|
|||||||
assert.strictEqual(post_count, 2);
|
assert.strictEqual(post_count, 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not migrate shares by that user that already belong to a local category', async () => {
|
||||||
|
const { id } = helpers.mocks.person();
|
||||||
|
await activitypub.actors.assert([id]);
|
||||||
|
|
||||||
|
const { cid } = await categories.create({ name: utils.generateUUID() });
|
||||||
|
|
||||||
|
// Two shares, one moved to local cid
|
||||||
|
for (let x = 0; x < 2; x++) {
|
||||||
|
const { id: pid } = helpers.mocks.note();
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
const { tid } = await activitypub.notes.assert(0, pid, { skipChecks: 1 });
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
await db.sortedSetAdd(`uid:${id}:shares`, Date.now(), tid);
|
||||||
|
|
||||||
|
if (!x) {
|
||||||
|
await topics.tools.move(tid, {
|
||||||
|
cid,
|
||||||
|
uid: 'system',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
helpers.mocks.group({ id });
|
||||||
|
await activitypub.actors.assertGroup([id]);
|
||||||
|
|
||||||
|
const { topic_count, post_count } = await categories.getCategoryData(id);
|
||||||
|
assert.strictEqual(topic_count, 1);
|
||||||
|
assert.strictEqual(post_count, 1);
|
||||||
|
});
|
||||||
|
|
||||||
it('should migrate any local followers into category watches', async () => {
|
it('should migrate any local followers into category watches', async () => {
|
||||||
const { id } = helpers.mocks.person();
|
const { id } = helpers.mocks.person();
|
||||||
await activitypub.actors.assert([id]);
|
await activitypub.actors.assert([id]);
|
||||||
|
|||||||
Reference in New Issue
Block a user