Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/lib/models/BaseItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ export default class BaseItem extends BaseModel {

const isNew = this.isNew(o, options);

if (needsShareReadOnlyChecks(this.modelType(), options.changeSource, this.syncShareCache)) {
if (needsShareReadOnlyChecks(this.modelType(), options.changeSource, this.syncShareCache, options.disableReadOnlyCheck)) {
if (!isNew) {
const previousItem = await this.loadItemByTypeAndId(this.modelType(), o.id, { fields: ['id', 'share_id'] });
checkIfItemCanBeChanged(this.modelType(), options.changeSource, previousItem, this.syncShareCache);
Expand Down
17 changes: 16 additions & 1 deletion packages/lib/models/Folder.sharing.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setupDatabaseAndSynchronizer, switchClient, createFolderTree, supportDir, msleep, resourceService } from '../testing/test-utils';
import { setupDatabaseAndSynchronizer, switchClient, createFolderTree, supportDir, msleep, resourceService, simulateReadOnlyShareEnv } from '../testing/test-utils';
import Folder from '../models/Folder';
import { allNotesFolders } from '../testing/test-utils-synchronizer';
import Note from '../models/Note';
Expand Down Expand Up @@ -181,6 +181,21 @@ describe('models/Folder.sharing', () => {
}
}));

it('should not fail to update share IDs when an outdated share ID is contained in a read-only folder', async () => {
const shareId = 'abcd1234';
const root = await Folder.save({ title: 'read-only', share_id: shareId });
// Save a child with a different share ID
const child = await Note.save({ title: 'Test', parent_id: root.id, share_id: `${shareId}-different` });

const reset = simulateReadOnlyShareEnv([shareId]);
try {
await Folder.updateAllShareIds(resourceService(), []);
expect(await Note.load(child.id)).toMatchObject({ share_id: shareId });
} finally {
reset();
}
});

it('should unshare a subfolder of a shared folder when it is moved to the root', (async () => {
let folder1 = await createFolderTree('', [
{
Expand Down
5 changes: 4 additions & 1 deletion packages/lib/models/Folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,10 @@ export default class Folder extends BaseItem {
share_id: row.share_id || '',
parent_id: row.parent_id,
updated_time: Date.now(),
}, { autoTimestamp: false });
}, {
autoTimestamp: false,
disableReadOnlyCheck: true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This may lead to conflicts:

- If a local read-only item has been modified, and the synchroniser tries to upload it, Joplin Cloud responds with a read-only error. The synchroniser local item is copied to the conflict folder and the remote item overwrites the local one.

});
}
}

Expand Down