Skip to content

Commit

Permalink
Pro 6419 import pages (#79)
Browse files Browse the repository at this point in the history
* Add export batch operation for pages

* when overriding page keep position info of the existing one

* add tests for import pages from a tree

* do not commit test public files

* cleanup before import

* add missing dependency

* add todos

* polish assertions

* use import-page

* remove form-data

* use apostrophe batch pages branch

* clean lint errors

* retrieve target

* test import twice and handling of parked pages

* Add computed documents types

* Ensure unique types

* Add batch label for notificaitons

* Changelog

* support parked pages

* Fix missing module action

* Fix import labels for singleton pieces

* override duplicates needs duplicated docs

* fix lint issues

* bring back doc ids

* keep slug from import file

* fix rank values

* remove branch

* Add replaces configuration for singleton import menu

* fix typo with options, remove logs from tests

* do not throw error if we can not dismiss job notification

* remove replaceDocIds

* run two separate suite for remove

* restore correct existing apos doc id

* revert mocks

* revert changes to test/index.js

* do not try to replace existing attachments, just merge crops and use recomputeAllDocReferences

* keep attachment name

---------

Co-authored-by: Miro Yovchev <[email protected]>
Co-authored-by: Jed <[email protected]>
Co-authored-by: Harouna Traoré <[email protected]>
Co-authored-by: boutell <[email protected]>
  • Loading branch information
5 people authored Sep 5, 2024
1 parent 9a841fe commit 35f4711
Show file tree
Hide file tree
Showing 10 changed files with 1,319 additions and 97 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@ node_modules

# vim swp files
.*.sw*
/test/public/uploads

# Dont commit test generated css
test/public/css/*.css
test/public/css/master-*.less

# Dont commit test uploads
/test/data
/test/public/exports
/test/public/uploads
2 changes: 1 addition & 1 deletion lib/methods/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = self => {
const ids = self.apos.launder.ids(req.body._ids);
const relatedTypes = self.apos.launder.strings(req.body.relatedTypes);
const expiration = self.options.importExport?.export?.expiration &&
self.apos.launder.integer(self.options.export.expiration);
self.apos.launder.integer(self.options.importExport.export.expiration);

const [ defaultFormatName ] = Object.keys(self.formats);
const formatName = self.apos.launder.string(req.body.formatName, defaultFormatName);
Expand Down
94 changes: 94 additions & 0 deletions lib/methods/import-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const getTargetId = async ({
manager,
doc,
req,
duplicatedDocs = []
}) => {
if (doc.archived) {
return '_archive';
}

const duplicatedDocsMapping = Object.fromEntries(
duplicatedDocs.map(duplicate => [ duplicate.aposDocId, duplicate.replaceId ])
);

const { path = '' } = doc;
const ancestorIds = path.split('/').reverse().slice(1);
for (const ancestorId of ancestorIds) {
try {
const { aposDocId } = await manager.getTarget(req, duplicatedDocsMapping[ancestorId] || ancestorId);

return aposDocId;
} catch (error) {
// continue search
}
}

return '_home';
};

const insert = async ({
manager,
doc,
req,
duplicatedDocs
}) => {
const targetId = await getTargetId({
manager,
doc,
req,
duplicatedDocs
});
const position = 'lastChild';

return manager.insert(
req,
targetId,
position,
doc,
{ setModified: false }
);
};

const update = async ({
manager,
doc,
req,
duplicatedDocs
}) => {
const {
_id,
aposDocId,
path,
rank,
level,
...patch
} = doc;

const move = doc.parkedId
? {}
: {
_targetId: await getTargetId({
manager,
doc,
req,
duplicatedDocs
}),
_position: 'lastChild'
};

return manager.patch(
req.clone({
body: {
...patch,
...move
}
}),
_id
);
};

module.exports = {
insert,
update
};
Loading

0 comments on commit 35f4711

Please sign in to comment.