Skip to content

Commit f297105

Browse files
committed
server: Fix duplicating notes with relationships (closes #308)
1 parent ddc8285 commit f297105

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

integration-tests/auth.setup.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { test as setup, expect } from '@playwright/test';
22

33
const authFile = 'playwright/.auth/user.json';
44

5-
const ROOT_URL = "http://localhost:8080";
6-
const LOGIN_PASSWORD = "eliandoran";
5+
const ROOT_URL = "http://localhost:8082";
6+
const LOGIN_PASSWORD = "demo1234";
77

88
// Reference: https://playwright.dev/docs/auth#basic-shared-account-in-all-tests
99

integration-tests/duplicate.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test("Can duplicate note with broken links", async ({ page }) => {
4+
await page.goto(`http://localhost:8082/#2VammGGdG6Ie`);
5+
await page.locator('.tree-wrapper .fancytree-active').getByText('Note map').click({ button: 'right' });
6+
await page.getByText('Duplicate subtree').click();
7+
await expect(page.locator(".toast-body")).toBeHidden();
8+
await expect(page.locator('.tree-wrapper').getByText('Note map (dup)')).toBeVisible();
9+
});

src/becca/entities/abstract_becca_entity.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
3434
isSynced?: boolean;
3535
blobId?: string;
3636

37-
protected beforeSaving() {
37+
protected beforeSaving(opts?: {}) {
3838
const constructorData = (this.constructor as unknown as ConstructorData<T>);
3939
if (!(this as any)[constructorData.primaryKeyName]) {
4040
(this as any)[constructorData.primaryKeyName] = utils.newEntityId();
@@ -109,7 +109,7 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
109109

110110
const isNewEntity = !(this as any)[primaryKeyName];
111111

112-
this.beforeSaving();
112+
this.beforeSaving(opts);
113113

114114
const pojo = this.getPojoToSave();
115115

src/services/notes.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,6 @@ function undeleteBranch(branchId: string, deleteId: string, taskContext: TaskCon
817817

818818
for (const attributeRow of attributeRows) {
819819
// relation might point to a note which hasn't been undeleted yet and would thus throw up
820-
// TODO: skipValidation is not used.
821820
new BAttribute(attributeRow).save({skipValidation: true});
822821
}
823822

@@ -997,8 +996,7 @@ function duplicateSubtreeInner(origNote: BNote, origBranch: BBranch, newParentNo
997996
}
998997

999998
// the relation targets may not be created yet, the mapping is pre-generated
1000-
// TODO: This used to be `attr.save({skipValidation: true});`, but skipValidation is in beforeSaving.
1001-
attr.save();
999+
attr.save({skipValidation: true});
10021000
}
10031001

10041002
for (const childBranch of origNote.getChildBranches()) {

0 commit comments

Comments
 (0)