-
Notifications
You must be signed in to change notification settings - Fork 2
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
handle permissions #13
Conversation
PRO-4261 As an editor, I can download a ZIP file of my exported documents
When clicking on the Two new routes This method should take the IDs of the documents the user want to export, as well as the related types that he wants to get. Only the types, not the IDs, since we decided that it would be too heavy for the export modal to get the amount of related docs when we batch a large amount of documents. Generate filesThis method will need to use the Since we need to store documents in a flat EJSON array, it might be a good idea to add an option to this method in order to get a flat array of related documents instead of filling requested documents with their related docs, see how it could potentially be used with query builders. We want one EJSON file for each db collection, for example We want, for each document to export the draft and live versions (only draft if there is no live). The draft version must appear first to avoid situation where a live exists without draft which is forbidden. Same thing for related documents, they must be written first in the EJSON file, otherwise the doc manager will yell when we'll import it. We will create an Generate ZipTo generate the ZIP file we would prefer using the native node library. Progress bar notificationThis progress bar notification is triggered by wrapping your export function with the
The Finally the ZIP file will be sent back to the client and the download triggered from the user's browser. PermissionsFor exporting documents, a user that has at least one per-type permission should be able to export anything. He won’t be able to see For Reference https://github.com/apostrophecms/tech-designs/blob/main/3.x/share-documents-across-sites/design.md Acceptance Criteria
|
if (self.options.export !== false) { | ||
self.apos.asset.iconMap['apos-import-export-download-icon'] = 'Download'; | ||
} | ||
if (self.options.import !== false) { | ||
self.apos.asset.iconMap['apos-import-export-upload-icon'] = 'Upload'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't want to check self.options.import
or self.options.export
here, because this index.js
is not the improvement of the modules that set these options.
434a51a
to
15e7708
Compare
dcbf3fd
to
ee3750f
Compare
lib/methods/export.js
Outdated
if (!self.apos.permission.can(req, 'view-draft', docType)) { | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure
lib/methods/export.js
Outdated
} | ||
}) | ||
.project(projection) | ||
// .permission('view-draft') // TODO: add this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
lib/apiRoutes.js
Outdated
// TODO: handle permission here: exclude types that the user cannot access to: | ||
return self.canExport(obj.withType) && obj.withType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will be done in a next PR soon
@@ -1,3 +1,5 @@ | |||
const _ = require('lodash'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I know... but straightforward and it does the job
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like jquery? (joke from Harouna 😄 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least just import the feature you need:
const { uniqBy } = require('lodash');
lib/methods/export.js
Outdated
if (!format) { | ||
throw self.apos.error('invalid'); | ||
} | ||
|
||
const allIds = self.getAllModesIds(ids); | ||
const docs = await self.getDocs(req, ids, manager, reporting); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the reporting is now handled by getDocs
lib/methods/export.js
Outdated
// Get docs via their manager in order to populate them | ||
// so that we can retrieve their relationships IDs later, | ||
// and to let the manager handle permissions. | ||
// TODO: get draft and live in the same call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wil tend to that in another PR
return []; | ||
} | ||
|
||
// TODO: test with `importExport: { export: false }` option in the attachment module: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To test with attachments @ValJed
lib/methods/export.js
Outdated
formatArchiveData(docs, attachments = [], urls = {}) { | ||
return { | ||
json: { | ||
// TODO: use BSON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a separate ticket for that
c7cd9c7
to
013e1bd
Compare
f5747ff
to
f9f9a8c
Compare
@@ -1,3 +1,5 @@ | |||
const _ = require('lodash'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like jquery? (joke from Harouna 😄 )
@@ -1,3 +1,5 @@ | |||
const _ = require('lodash'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least just import the feature you need:
const { uniqBy } = require('lodash');
export
andimport
options into aimportExport
oneapos.util.clonePermanent
to strip the docs from the scalar properties (except for_id
)--> We're not fetching docs directly from the mongo anymore