1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

Desktop: Fixed issue where untitled notes where created after a note had been shared and synced

This commit is contained in:
Laurent Cozic 2021-07-02 18:14:49 +01:00
parent f792fbb5fc
commit 07ea79bb46
2 changed files with 24 additions and 6 deletions

View File

@ -356,6 +356,8 @@ describe('models_Folder.sharing', function() {
const resourceService = new ResourceService();
const folder1: FolderEntity = await Folder.loadByTitle('folder 1');
const folder2: FolderEntity = await Folder.loadByTitle('folder 2');
let note1: NoteEntity = await Note.loadByTitle('note 1');
let note2: NoteEntity = await Note.loadByTitle('note 2');
note1 = await shim.attachFileToNote(note1, testImagePath);
@ -369,6 +371,13 @@ describe('models_Folder.sharing', function() {
await Folder.updateNoLongerSharedItems(['1']);
// Since `updateNoLongerSharedItems` sets the parent_id too,
// double-check that it's not actually modified.
expect((await Note.loadByTitle('note 1')).parent_id).toBe(folder1.id);
expect((await Note.loadByTitle('note 2')).parent_id).toBe(folder2.id);
expect((await Folder.loadByTitle('folder 1')).parent_id).toBe(folder1.parent_id);
expect((await Folder.loadByTitle('folder 2')).parent_id).toBe(folder2.parent_id);
// At this point, all items associated with share 2 should have their
// share_id cleared, because the share no longer exists. We also
// double-check that share 1 hasn't been cleared.

View File

@ -320,12 +320,12 @@ export default class Folder extends BaseItem {
// if they've been moved out of a shared folder.
// await this.unshareItems(ModelType.Folder, sharedFolderIds);
const sql = ['SELECT id FROM folders WHERE share_id != ""'];
const sql = ['SELECT id, parent_id FROM folders WHERE share_id != ""'];
if (sharedFolderIds.length) {
sql.push(` AND id NOT IN ("${sharedFolderIds.join('","')}")`);
}
const foldersToUnshare = await this.db().selectAll(sql.join(' '));
const foldersToUnshare: FolderEntity[] = await this.db().selectAll(sql.join(' '));
report.unshareUpdateCount += foldersToUnshare.length;
@ -334,6 +334,7 @@ export default class Folder extends BaseItem {
id: item.id,
share_id: '',
updated_time: Date.now(),
parent_id: item.parent_id,
}, { autoTimestamp: false });
}
@ -407,12 +408,16 @@ export default class Folder extends BaseItem {
for (const tableName of ['folders', 'notes', 'resources']) {
const ItemClass = tableNameToClasses[tableName];
const hasParentId = tableName !== 'resources';
const fields = ['id'];
if (hasParentId) fields.push('parent_id');
const query = activeShareIds.length ? `
SELECT id FROM ${tableName}
SELECT ${this.db().escapeFields(fields)} FROM ${tableName}
WHERE share_id != "" AND share_id NOT IN ("${activeShareIds.join('","')}")
` : `
SELECT id FROM ${tableName}
SELECT ${this.db().escapeFields(fields)} FROM ${tableName}
WHERE share_id != ''
`;
@ -421,11 +426,15 @@ export default class Folder extends BaseItem {
report[tableName] = rows.length;
for (const row of rows) {
await ItemClass.save({
const toSave: any = {
id: row.id,
share_id: '',
updated_time: Date.now(),
}, { autoTimestamp: false });
};
if (hasParentId) toSave.parent_id = row.parent_id;
await ItemClass.save(toSave, { autoTimestamp: false });
}
}