diff --git a/packages/components-faraday/src/components/Dashboard/Dashboard.js b/packages/components-faraday/src/components/Dashboard/Dashboard.js index 671bd11d70344edd9ea05135b52b8f0dfd6cbe2a..ed359ff49f353a936beb419d806e88fd27149c79 100644 --- a/packages/components-faraday/src/components/Dashboard/Dashboard.js +++ b/packages/components-faraday/src/components/Dashboard/Dashboard.js @@ -1,4 +1,5 @@ import React from 'react' +import { get } from 'lodash' import { Button } from '@pubsweet/ui' import classes from './Dashboard.local.scss' @@ -22,8 +23,8 @@ const Dashboard = ({ </div> <DashboardFilters changeView={changeViewMode} listView={listView} /> <DashboardItems - dashboard={dashboard} deleteProject={deleteProject} + list={get(currentUser, 'admin') ? dashboard.all : dashboard.owner} listView={listView} /> </div> diff --git a/packages/components-faraday/src/components/Dashboard/DashboardItems.js b/packages/components-faraday/src/components/Dashboard/DashboardItems.js index 35c8bd3989fead665215d210f96a197231d3e5ce..a73f2346cca6bb96560fa52a7d1b0e7710418243 100644 --- a/packages/components-faraday/src/components/Dashboard/DashboardItems.js +++ b/packages/components-faraday/src/components/Dashboard/DashboardItems.js @@ -6,18 +6,17 @@ import classes from './Dashboard.local.scss' const DashboardItem = withVersion(Item) -const DashboardItems = ({ dashboard, listView = true, deleteProject }) => ( +const DashboardItems = ({ list, listView = true, deleteProject }) => ( <div> - {!dashboard.owner.length && - !dashboard.reviewer.length && ( - <div className={classes.empty}> - Nothing to do at the moment. Please upload a manuscript. - </div> - )} + {!list.length && ( + <div className={classes.empty}> + Nothing to do at the moment. Please upload a manuscript. + </div> + )} - {!!dashboard.owner.length && ( + {!!list.length && ( <div className={classes.section}> - {dashboard.owner.map(p => ( + {list.map(p => ( <DashboardItem deleteProject={deleteProject} key={p.id} diff --git a/packages/components-faraday/src/components/Dashboard/DashboardPage.js b/packages/components-faraday/src/components/Dashboard/DashboardPage.js index fa088f905e21523c3c383583cc5d95cf13b9adb2..8b9978ebaf52f1a59da8dc32ca50b22894b2002e 100644 --- a/packages/components-faraday/src/components/Dashboard/DashboardPage.js +++ b/packages/components-faraday/src/components/Dashboard/DashboardPage.js @@ -39,6 +39,7 @@ export default compose( reviewer => reviewer && reviewer.user === currentUser.id, ), ), + all: sortedCollections, } return { collections, conversion, currentUser, dashboard } diff --git a/packages/xpub-aws/README.md b/packages/xpub-aws/README.md index ad7ab8703cf1288cc4b51e96fb516a3ebe39f061..412c05e11ee67846568434822082f344dec67c42 100644 --- a/packages/xpub-aws/README.md +++ b/packages/xpub-aws/README.md @@ -1,3 +1,88 @@ -## xPub-aws +# AWS S3 File Upload + +In order to use `xpub-aws` you first need to have a `.env` file containing AWS data in the root folder of the starting point of your applications. + +The `.env` file should look like this: +```bash +AWS_ACCESS_KEY = exampleKey +AWS_SECRET_KEY = exampleKey/sads/21 +AWS_REGION = region-name +AWS_BUCKET = bucket-name +``` + +Then, as soon as possible in your app you should add the `dotenv` package: +```js +require('dotenv').config() +``` + +# `xpub-aws` API +A list of endpoints that help you upload, download and delete S3 files. + +## Upload a file [POST] +#### Request +`POST /api/aws` +#### Request body +``` +Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryWfPNVh4wuWBlyEyQ + +------WebKitFormBoundaryWfPNVh4wuWBlyEyQ +Content-Disposition: form-data; name="fileType" + +supplementary +------WebKitFormBoundaryWfPNVh4wuWBlyEyQ +Content-Disposition: form-data; name="fragmentId" + +545 +------WebKitFormBoundaryWfPNVh4wuWBlyEyQ +Content-Disposition: form-data; name="file"; filename="attachment.txt" +Content-Type: text/plain + +[file content goes there] +------WebKitFormBoundaryWfPNVh4wuWBlyEyQ +``` +#### Response +```json +{ + "id": "unique-file-id", + "name": "Document Name.doc", + "size": 452097 +} +``` + +## Retrieve file signed URL [GET] +This endpoint allows you to retrieve a file's signed URL that can be used to download the file. +#### Request +`GET /api/aws/{fragmentId}/{fileId}` + +| URI Parameter | Requiered | Requirements | Description | +| -------- | -------- | -------- | -------- | +| fragmentId | Yes | String | The ID of the fragment to which the file belongs to | +| fileId | Yes | String | The ID of the file | + +#### Response +```json +HTTP/1.1 200 +{ + "signedUrl": "aws-url" +} +``` + +## Delete file [DELETE] +#### Request +`DELETE /api/aws/{fragmentId}/{fileId}` + +| URI Parameter | Requiered | Requirements | Description | +| -------- | -------- | -------- | -------- | +| fragmentId | Yes | String | The ID of the fragment to which the file belongs to | +| fileId | Yes | String | The ID of the file | + +#### Response +```json +HTTP/1.1 204 +``` +--- + + + + -A server package that handles AWS \ No newline at end of file diff --git a/packages/xpub-aws/src/AWSBackend.js b/packages/xpub-aws/src/AWSBackend.js index 5c2dac23c361e127de6634e680f03938ffdc6a49..fe753bc83490dddd715f5b72f8f6ff73f75b3b5b 100644 --- a/packages/xpub-aws/src/AWSBackend.js +++ b/packages/xpub-aws/src/AWSBackend.js @@ -45,59 +45,46 @@ const AWSBackend = app => { return cb(null, true) }, }) - app.post( - '/api/aws-upload', - authBearer, - upload.single('file'), - async (req, res) => { - if (req.fileValidationError !== undefined) { - return res.status(400).json({ error: req.fileValidationError }) - } + app.post('/api/aws', authBearer, upload.single('file'), async (req, res) => { + if (req.fileValidationError !== undefined) { + return res.status(400).json({ error: req.fileValidationError }) + } - res.status(200).json({ - id: req.file.key, - name: req.file.originalname, - size: req.file.size, - }) - }, - ) - app.get( - '/api/aws-signed-url/:fragmentId/:fileId', - authBearer, - async (req, res) => { - const params = { - Bucket: process.env.AWS_BUCKET, - Key: `${req.params.fragmentId}${req.params.fileId}`, - } + res.status(200).json({ + id: req.file.key, + name: req.file.originalname, + size: req.file.size, + }) + }) + app.get('/api/aws/:fragmentId/:fileId', authBearer, async (req, res) => { + const params = { + Bucket: process.env.AWS_BUCKET, + Key: `${req.params.fragmentId}${req.params.fileId}`, + } - s3.getSignedUrl('getObject', params, (err, data) => { - if (err) { - res.status(err.statusCode).json({ error: err.message }) - return - } - res.status(200).json({ - signedUrl: data, - }) - }) - }, - ) - app.delete( - '/api/aws-delete/:fragmentId/:fileId', - authBearer, - async (req, res) => { - const params = { - Bucket: process.env.AWS_BUCKET, - Key: `${req.params.fragmentId}${req.params.fileId}`, + s3.getSignedUrl('getObject', params, (err, data) => { + if (err) { + res.status(err.statusCode).json({ error: err.message }) + return } - s3.deleteObject(params, (err, data) => { - if (err) { - res.status(err.statusCode).json({ error: err.message }) - return - } - res.status(204).json() + res.status(200).json({ + signedUrl: data, }) - }, - ) + }) + }) + app.delete('/api/aws/:fragmentId/:fileId', authBearer, async (req, res) => { + const params = { + Bucket: process.env.AWS_BUCKET, + Key: `${req.params.fragmentId}${req.params.fileId}`, + } + s3.deleteObject(params, (err, data) => { + if (err) { + res.status(err.statusCode).json({ error: err.message }) + return + } + res.status(204).json() + }) + }) } module.exports = AWSBackend