1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-24 20:19:10 +02:00

Cli,Mobile,Desktop: Shared folders: Fix moving shared subfolder to toplevel briefly marks it as a toplevel share (#12964)

This commit is contained in:
Henry Heino
2025-08-19 23:39:39 -07:00
committed by GitHub
parent a414241541
commit 26012cd7d5
2 changed files with 51 additions and 4 deletions

View File

@@ -102,6 +102,40 @@ describe('models/Folder.sharing', () => {
expect(folder5.share_id).toBe('');
}));
it('should clear the share ID of a folder immediately when moved out of a shared folder', async () => {
let folder1 = await createFolderTree('', [
{
title: 'folder 1',
children: [
{
title: 'folder 2',
children: [
{
title: 'folder 3',
children: [],
},
],
},
],
},
]);
await Folder.save({ id: folder1.id, share_id: 'test123456' });
await Folder.updateAllShareIds(resourceService(), []);
folder1 = await Folder.loadByTitle('folder 1');
const folder2 = await Folder.loadByTitle('folder 2');
expect(folder1.share_id).toBe('test123456');
expect(folder2.share_id).toBe('test123456');
await Folder.moveToFolder(folder2.id, '');
// Should have updated the share_id of folder 2 during "moveToFolder":
expect(await Folder.loadByTitle('folder 2')).toMatchObject({
share_id: '',
});
});
it('should update the share ID when a folder is moved in or out of shared folder', (async () => {
let folder1 = await createFolderTree('', [
{

View File

@@ -938,15 +938,28 @@ export default class Folder extends BaseItem {
public static async moveToFolder(folderId: string, targetFolderId: string) {
if (!(await this.canNestUnder(folderId, targetFolderId))) throw new Error(_('Cannot move notebook to this location'));
// When moving a note to a different folder, the user timestamp is not updated.
// However updated_time is updated so that the note can be synced later on.
const modifiedFolder = {
const original = await this.load(folderId);
const modifiedFolder: FolderEntity = {
id: folderId,
parent_id: targetFolderId,
// When moving a note to a different folder, the user timestamp is not updated.
// However updated_time is updated so that the note can be synced later on.
updated_time: time.unixMs(),
share_id: original.share_id,
};
const wasShared = !!modifiedFolder.share_id;
const movedToTopLevel = original.parent_id !== '' && targetFolderId === '';
if (wasShared && movedToTopLevel) {
// When a shared subfolder is converted to a toplevel folder, clear its share_id
// as soon as possible. Without this, modifiedFolder would be incorrectly treated
// as a root shared folder by some logic.
// Since the folder's children aren't toplevel, they won't be considered root
// shared folders and are updated later.
modifiedFolder.share_id = '';
}
return Folder.save(modifiedFolder, { autoTimestamp: false });
}