kopia lustrzana https://github.com/wagtail/wagtail
Prevent Draftail from crashing on links to the root page
rodzic
19c04e8e6b
commit
6c7065ef99
client/src/components/Draftail/sources
wagtail/admin
rich_text/converters
tests
|
@ -50,7 +50,11 @@ export const getChooserConfig = (entityType, entity, selectedText) => {
|
|||
const data = entity.getData();
|
||||
|
||||
if (data.id) {
|
||||
url = `${global.chooserUrls.pageChooser}${data.parentId}/`;
|
||||
if (data.parentId !== null) {
|
||||
url = `${global.chooserUrls.pageChooser}${data.parentId}/`;
|
||||
} else {
|
||||
url = global.chooserUrls.pageChooser;
|
||||
}
|
||||
} else if (data.url.startsWith('mailto:')) {
|
||||
url = global.chooserUrls.emailLinkChooser;
|
||||
urlParams.link_url = data.url.replace('mailto:', '');
|
||||
|
|
|
@ -61,7 +61,13 @@ describe('ModalWorkflowSource', () => {
|
|||
|
||||
it('page', () => {
|
||||
expect(getChooserConfig({ type: 'LINK' }, {
|
||||
getData: () => ({ id: 1, parentId: 0 })
|
||||
getData: () => ({ id: 2, parentId: 1 })
|
||||
}, '')).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('root page', () => {
|
||||
expect(getChooserConfig({ type: 'LINK' }, {
|
||||
getData: () => ({ id: 1, parentId: null })
|
||||
}, '')).toMatchSnapshot();
|
||||
});
|
||||
|
||||
|
|
|
@ -103,7 +103,22 @@ Object {
|
|||
"onload": Object {
|
||||
"type": "page",
|
||||
},
|
||||
"url": "/admin/choose-page/0/",
|
||||
"url": "/admin/choose-page/1/",
|
||||
"urlParams": Object {
|
||||
"allow_email_link": true,
|
||||
"allow_external_link": true,
|
||||
"link_text": "",
|
||||
"page_type": "wagtailcore.page",
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`ModalWorkflowSource #getChooserConfig LINK root page 1`] = `
|
||||
Object {
|
||||
"onload": Object {
|
||||
"type": "page",
|
||||
},
|
||||
"url": "/admin/choose-page/",
|
||||
"urlParams": Object {
|
||||
"allow_email_link": true,
|
||||
"allow_external_link": true,
|
||||
|
|
|
@ -208,10 +208,12 @@ class PageLinkElementHandler(LinkElementHandler):
|
|||
except Page.DoesNotExist:
|
||||
return {}
|
||||
|
||||
parent_page = page.get_parent()
|
||||
|
||||
return {
|
||||
'id': page.id,
|
||||
'url': page.url,
|
||||
'parentId': page.get_parent().id,
|
||||
'parentId': parent_page.id if parent_page else None,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -337,6 +337,28 @@ class TestHtmlToContentState(TestCase):
|
|||
]
|
||||
})
|
||||
|
||||
def test_link_to_root_page(self):
|
||||
converter = ContentstateConverter(features=['link'])
|
||||
result = json.loads(converter.from_database_format(
|
||||
'''
|
||||
<p>an <a linktype="page" id="1">internal</a> link</p>
|
||||
'''
|
||||
))
|
||||
self.assertContentStateEqual(result, {
|
||||
'entityMap': {
|
||||
'0': {
|
||||
'mutability': 'MUTABLE', 'type': 'LINK',
|
||||
'data': {'id': 1, 'url': None, 'parentId': None}
|
||||
}
|
||||
},
|
||||
'blocks': [
|
||||
{
|
||||
'inlineStyleRanges': [], 'text': 'an internal link', 'depth': 0, 'type': 'unstyled', 'key': '00000',
|
||||
'entityRanges': [{'offset': 3, 'length': 8, 'key': 0}]
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
def test_document_link(self):
|
||||
converter = ContentstateConverter(features=['document-link'])
|
||||
result = json.loads(converter.from_database_format(
|
||||
|
|
Ładowanie…
Reference in New Issue