Skip to content

✨(frontend) Interlinking doc #904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 17 commits into
base: feature/doc-dnd
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .github/workflows/docker-hub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
push:
branches:
- 'main'
- 'feature/doc-dnd'
tags:
- 'v*'
pull_request:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to

- 🚸(backend) make document search on title accent-insensitive #874
- 🚩 add homepage feature flag #861
- ✨(frontend) multi-pages #701

## Changed

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
- "1081:1080"

minio:
user: ${DOCKER_USER:-1000}
# user: ${DOCKER_USER:-1000}
image: minio/minio
environment:
- MINIO_ROOT_USER=impress
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.1.7 on 2025-03-14 14:03

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("core", "0021_activate_unaccent_extension"),
]

operations = [
migrations.AddField(
model_name="document",
name="has_deleted_children",
field=models.BooleanField(default=False),
),
]
11 changes: 10 additions & 1 deletion src/backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ def get_queryset(self):
return self._queryset_class(self.model).order_by("path")


# pylint: disable=too-many-public-methods
class Document(MP_Node, BaseModel):
"""Pad document carrying the content."""

Expand All @@ -486,6 +487,7 @@ class Document(MP_Node, BaseModel):
)
deleted_at = models.DateTimeField(null=True, blank=True)
ancestors_deleted_at = models.DateTimeField(null=True, blank=True)
has_deleted_children = models.BooleanField(default=False)
duplicated_from = models.ForeignKey(
"self",
on_delete=models.SET_NULL,
Expand Down Expand Up @@ -561,6 +563,12 @@ def save(self, *args, **kwargs):
content_file = ContentFile(bytes_content)
default_storage.save(file_key, content_file)

def is_leaf(self):
"""
:returns: True if the node is has no children
"""
return not self.has_deleted_children and self.numchild == 0

@property
def key_base(self):
"""Key base of the location where the document is stored in object storage."""
Expand Down Expand Up @@ -945,7 +953,8 @@ def soft_delete(self):

if self.depth > 1:
self._meta.model.objects.filter(pk=self.get_parent().pk).update(
numchild=models.F("numchild") - 1
numchild=models.F("numchild") - 1,
has_deleted_children=True,
)

# Mark all descendants as soft deleted
Expand Down
44 changes: 44 additions & 0 deletions src/backend/core/tests/test_models_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,50 @@ def test_models_documents_get_select_options(ancestors_links, select_options):
assert models.LinkReachChoices.get_select_options(ancestors_links) == select_options


def test_models_documents_children_create_after_sibling_deletion():
"""
It should be possible to create a new child after all children have been deleted.
"""

root = factories.DocumentFactory()
assert root.numchild == 0
assert root.has_deleted_children is False
assert root.is_leaf() is True
child1 = factories.DocumentFactory(parent=root)
child2 = factories.DocumentFactory(parent=root)

root.refresh_from_db()
assert root.numchild == 2
assert root.has_deleted_children is False
assert root.is_leaf() is False

child1.soft_delete()
child2.soft_delete()
root.refresh_from_db()
assert root.numchild == 0
assert root.has_deleted_children is True
assert root.is_leaf() is False

factories.DocumentFactory(parent=root)
root.refresh_from_db()
assert root.numchild == 1
assert root.has_deleted_children is True
assert root.is_leaf() is False


def test_models_documents_has_deleted_children():
"""
A document should have its has_deleted_children attribute set to True if one of its children
has been solf deleted no matter if numchild is 0 or not.
"""
root = factories.DocumentFactory()
child = factories.DocumentFactory(parent=root)
assert root.has_deleted_children is False
child.soft_delete()
root.refresh_from_db()
assert root.has_deleted_children is True


def test_models_documents_compute_ancestors_links_no_highest_readable():
"""Test the compute_ancestors_links method."""
document = factories.DocumentFactory(link_reach="public")
Expand Down
26 changes: 23 additions & 3 deletions src/frontend/apps/e2e/__tests__/app-impress/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,19 @@ export const createDoc = async (
docName: string,
browserName: string,
length: number = 1,
isChild: boolean = false,
) => {
const randomDocs = randomName(docName, browserName, length);

for (let i = 0; i < randomDocs.length; i++) {
const header = page.locator('header').first();
await header.locator('h2').getByText('Docs').click();
if (!isChild) {
const header = page.locator('header').first();
await header.locator('h2').getByText('Docs').click();
}

await page
.getByRole('button', {
name: 'New doc',
name: isChild ? 'New page' : 'New doc',
})
.click();

Expand Down Expand Up @@ -213,6 +216,7 @@ export const mockedDocument = async (page: Page, json: object) => {
},
link_reach: 'restricted',
created_at: '2021-09-01T09:00:00Z',
user_roles: ['owner'],
...json,
},
});
Expand All @@ -222,6 +226,22 @@ export const mockedDocument = async (page: Page, json: object) => {
});
};

export const mockedListDocs = async (page: Page, data: object[] = []) => {
await page.route('**/documents/**/', async (route) => {
const request = route.request();
if (request.method().includes('GET') && request.url().includes('page=')) {
await route.fulfill({
json: {
count: data.length,
next: null,
previous: null,
results: data,
},
});
}
});
};

export const mockedInvitations = async (page: Page, json?: object) => {
await page.route('**/invitations/**/', async (route) => {
const request = route.request();
Expand Down
44 changes: 42 additions & 2 deletions src/frontend/apps/e2e/__tests__/app-impress/doc-create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ test.beforeEach(async ({ page }) => {

test.describe('Doc Create', () => {
test('it creates a doc', async ({ page, browserName }) => {
const [docTitle] = await createDoc(page, 'My new doc', browserName, 1);
const [docTitle] = await createDoc(page, 'my-new-doc', browserName, 1);

await page.waitForFunction(
() => document.title.match(/My new doc - Docs/),
() => document.title.match(/my-new-doc - Docs/),
{ timeout: 5000 },
);

Expand All @@ -29,6 +29,46 @@ test.describe('Doc Create', () => {
await expect(page.getByTestId('grid-loader')).toBeHidden();
await expect(docsGrid.getByText(docTitle)).toBeVisible();
});

test('it creates a sub doc from slash menu editor', async ({
page,
browserName,
}) => {
const [title] = await createDoc(page, 'my-new-slash-doc', browserName, 1);

await verifyDocName(page, title);

await page.locator('.bn-block-outer').last().fill('/');
await page.getByText('Add a new page').click();

const input = page.getByRole('textbox', { name: 'doc title input' });
await expect(input).toHaveText('');
await expect(
page.locator('.c__tree-view--row-content').getByText('Untitled page'),
).toBeVisible();
});

test('it creates a sub doc from interlinking dropdown', async ({
page,
browserName,
}) => {
const [title] = await createDoc(page, 'my-new-slash-doc', browserName, 1);

await verifyDocName(page, title);

await page.locator('.bn-block-outer').last().fill('/');
await page.getByText('Link to a page').first().click();
await page
.locator('.quick-search-container')
.getByText('Add a new page')
.click();

const input = page.getByRole('textbox', { name: 'doc title input' });
await expect(input).toHaveText('');
await expect(
page.locator('.c__tree-view--row-content').getByText('Untitled page'),
).toBeVisible();
});
});

test.describe('Doc Create: Not loggued', () => {
Expand Down
68 changes: 66 additions & 2 deletions src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ test.describe('Doc Editor', () => {
await expect(editor.getByText('Hello World Doc 2')).toBeHidden();
await expect(editor.getByText('Hello World Doc 1')).toBeVisible();

await page.goto('/');
await page
.getByRole('button', {
name: 'New doc',
Expand Down Expand Up @@ -364,8 +365,6 @@ test.describe('Doc Editor', () => {
retrieve: true,
},
link_reach: 'public',
link_role: 'editor',
created_at: '2021-09-01T09:00:00Z',
title: '',
});

Expand Down Expand Up @@ -452,4 +451,69 @@ test.describe('Doc Editor', () => {
const svgBuffer = await cs.toBuffer(await download.createReadStream());
expect(svgBuffer.toString()).toContain('Hello svg');
});

test('it checks interlink feature', async ({ page, browserName }) => {
const [randomDoc] = await createDoc(page, 'doc-interlink', browserName, 1);

await verifyDocName(page, randomDoc);

const [docChild1] = await createDoc(
page,
'doc-interlink-child-1',
browserName,
1,
true,
);

await verifyDocName(page, docChild1);

const [docChild2] = await createDoc(
page,
'doc-interlink-child-2',
browserName,
1,
true,
);

await verifyDocName(page, docChild2);

await page.locator('.bn-block-outer').last().fill('/');
await page.getByText('Link to a page').first().click();

await page
.locator(
"span[data-inline-content-type='interlinkingSearchInline'] input",
)
.fill('interlink-child-1');

await page
.locator('.quick-search-container')
.getByText('interlink-child-1')
.click();

const interlink = page.getByRole('link', {
name: 'child-1',
});

await expect(interlink).toBeVisible();
await interlink.click();

await verifyDocName(page, docChild1);
});

test('it checks interlink shortcut @', async ({ page, browserName }) => {
const [randomDoc] = await createDoc(page, 'doc-interlink', browserName, 1);

await verifyDocName(page, randomDoc);

const editor = page.locator('.bn-block-outer').last();
await editor.click();
await page.keyboard.press('@');

await expect(
page.locator(
"span[data-inline-content-type='interlinkingSearchInline'] input",
),
).toBeVisible();
});
});
Loading