Skip to content

Commit

Permalink
moves handler in lib file, only checks canEdit for singleton import (…
Browse files Browse the repository at this point in the history
…cannot be created)
  • Loading branch information
ValJed committed Aug 26, 2024
1 parent a3923c0 commit ef570f0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 54 deletions.
56 changes: 2 additions & 54 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs');
const path = require('path');
const handlers = require('./lib/handlers');
const methods = require('./lib/methods');
const apiRoutes = require('./lib/apiRoutes');
const formats = require('./lib/formats');
Expand Down Expand Up @@ -28,60 +29,7 @@ module.exports = {

self.enableBrowserData();
},
handlers(self) {
return {
'apostrophe:modulesRegistered': {
setContextOperations() {
const excludedExportTypes = [];
const excludedImportTypes = [];
for (const mod of Object.values(self.apos.modules)) {
if (!self.apos.instanceOf(mod, '@apostrophecms/doc-type')) {
continue;
}

if (mod.options.importExport?.export === false) {
excludedExportTypes.push({
type: {
$ne: mod.__meta.name
}
});
}

if (!mod.options.singleton || mod.options.importExport?.import === false) {
excludedImportTypes.push({
type: {
$ne: mod.__meta.name
}
});
}
}

const exportOperation = {
action: 'import-export-export',
context: 'update',
label: 'aposImportExport:export',
modal: 'AposExportModal',
props: {
action: 'import-export-export'
},
if: { $and: excludedExportTypes }
};
const importOperation = {
action: 'import-export-import',
context: 'update',
label: 'aposImportExport:import',
modal: 'AposImportModal',
if: { $and: excludedImportTypes },
canCreate: true,
canEdit: true
};

self.apos.doc.addContextOperation(exportOperation);
self.apos.doc.addContextOperation(importOperation);
}
}
};
},
handlers,
methods,
apiRoutes
};
Expand Down
54 changes: 54 additions & 0 deletions lib/handlers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

module.exports = (self) => {
return {
'apostrophe:modulesRegistered': {
setContextOperations() {
const excludedExportTypes = [];
const excludedImportTypes = [];
for (const mod of Object.values(self.apos.modules)) {
if (!self.apos.instanceOf(mod, '@apostrophecms/doc-type')) {
continue;
}

if (mod.options.importExport?.export === false) {
excludedExportTypes.push({
type: {
$ne: mod.__meta.name
}
});
}

if (!mod.options.singleton || mod.options.importExport?.import === false) {
excludedImportTypes.push({
type: {
$ne: mod.__meta.name
}
});
}
}

const exportOperation = {
action: 'import-export-export',
context: 'update',
label: 'aposImportExport:export',
modal: 'AposExportModal',
props: {
action: 'import-export-export'
},
if: { $and: excludedExportTypes }
};
const importOperation = {
action: 'import-export-import',
context: 'update',
label: 'aposImportExport:import',
modal: 'AposImportModal',
if: { $and: excludedImportTypes },
conditions: [ 'canEdit' ]
};

self.apos.doc.addContextOperation(exportOperation);
self.apos.doc.addContextOperation(importOperation);
}
}
};
};

0 comments on commit ef570f0

Please sign in to comment.