fix: Preserve Private Legacy Shared Links

This commit is contained in:
Danny Avila 2026-06-03 10:20:58 -04:00
parent db99016d87
commit f2bdd1645d
2 changed files with 45 additions and 26 deletions

View file

@ -146,4 +146,25 @@ describe('migrate-shared-link-permissions', () => {
expect(raw1).toHaveProperty('isPublic', true);
expect(raw2).toHaveProperty('isPublic', true);
});
test('does not grant PUBLIC VIEWER to isPublic false links when forced', async () => {
const link = await createLegacyLink(false);
const result = await migrateSharedLinkPermissions({ dryRun: false, force: true });
expect(result.aborted).toBeUndefined();
expect(result.publicViewerSkipped).toBe(1);
const publicEntry = await AclEntry.findOne({
resourceId: link._id,
principalType: 'public',
}).lean();
expect(publicEntry).toBeNull();
const ownerEntry = await AclEntry.findOne({
resourceId: link._id,
principalType: 'user',
}).lean();
expect(ownerEntry).toBeDefined();
});
});

View file

@ -189,33 +189,31 @@ async function migrateSharedLinkPermissions({
}
const hasIsPublic = link.isPublic !== undefined;
if (hasIsPublic) {
if (link.isPublic === false && !force) {
results.publicViewerSkipped++;
} else {
opIndexToLinkId.push(linkId);
bulkOps.push({
updateOne: {
filter: {
resourceType: RESOURCE_TYPE_SHARED_LINK,
resourceId: linkId,
principalType: PRINCIPAL_PUBLIC,
},
update: {
$set: {
permBits: viewerRole.permBits,
roleId: viewerRole._id,
grantedBy: userId ? new mongoose.Types.ObjectId(userId) : undefined,
grantedAt: now,
},
$setOnInsert: {
...(tenantId && { tenantId }),
},
},
upsert: true,
if (hasIsPublic && link.isPublic === false) {
results.publicViewerSkipped++;
} else if (hasIsPublic) {
opIndexToLinkId.push(linkId);
bulkOps.push({
updateOne: {
filter: {
resourceType: RESOURCE_TYPE_SHARED_LINK,
resourceId: linkId,
principalType: PRINCIPAL_PUBLIC,
},
});
}
update: {
$set: {
permBits: viewerRole.permBits,
roleId: viewerRole._id,
grantedBy: userId ? new mongoose.Types.ObjectId(userId) : undefined,
grantedAt: now,
},
$setOnInsert: {
...(tenantId && { tenantId }),
},
},
upsert: true,
},
});
}
results.migrated++;