diff --git a/packages/component-invite/src/controllers/inviteGlobalRole.js b/packages/component-invite/src/controllers/inviteGlobalRole.js index 3858f0c87159f85ed95bacbde32b3a158565b3cb..82558319506f30622daa03130ead2ee25f2cb92a 100644 --- a/packages/component-invite/src/controllers/inviteGlobalRole.js +++ b/packages/component-invite/src/controllers/inviteGlobalRole.js @@ -36,6 +36,7 @@ module.exports = async (body, models, res, url) => { models.User, role, ) + try { await mailService.setupInviteEmail( newUser.email, @@ -46,8 +47,7 @@ module.exports = async (body, models, res, url) => { return res.status(200).json(newUser) } catch (e) { - logger.error(e) - return res.status(500).json({ error: 'Mailing could not be sent.' }) + return res.status(500).json({ error: e.message }) } } } diff --git a/packages/component-invite/src/routes/getCollectionUsers.js b/packages/component-invite/src/routes/getCollectionUsers.js index 3644aa4c50f9f48d965cbeb8f752d955f55a87e2..16903452e5d2a81805b118dd5f3886dbe549d987 100644 --- a/packages/component-invite/src/routes/getCollectionUsers.js +++ b/packages/component-invite/src/routes/getCollectionUsers.js @@ -30,6 +30,13 @@ module.exports = models => async (req, res) => { models.Team, ) + if (members === undefined) { + res.status(400).json({ + error: `The requested collection does not have a ${role} Team`, + }) + return + } + const membersData = members.map(async member => { const user = await models.User.find(member) const { timestamp, status } = teamHelper.getInviteData( diff --git a/packages/component-invite/src/tests/fixtures/collections.js b/packages/component-invite/src/tests/fixtures/collections.js index 91eaf3b200444735abaac4e29d4561527829b84d..210aa318228faea749cc790593ec29bb8a5088d4 100644 --- a/packages/component-invite/src/tests/fixtures/collections.js +++ b/packages/component-invite/src/tests/fixtures/collections.js @@ -1,10 +1,21 @@ +const Chance = require('chance') + +const chance = new Chance() module.exports = { standardCollection: { - id: '2c4fb766-a798-4c32-b857-c5d21a2ab331', + id: chance.guid(), title: 'Standard Collection', type: 'collection', fragments: [], owners: [], save: jest.fn(), }, + noTeamCollection: { + id: chance.guid(), + title: 'No Team Collection', + type: 'collection', + fragments: [], + owners: [], + save: jest.fn(), + }, } diff --git a/packages/component-invite/src/tests/getCollectionUsers.test.js b/packages/component-invite/src/tests/getCollectionUsers.test.js index 1599ea3c1ee57da7e8b38e25efd7d93d3ef668dd..af4c1ce303148364a3ac8e196e8a36e32de847ec 100644 --- a/packages/component-invite/src/tests/getCollectionUsers.test.js +++ b/packages/component-invite/src/tests/getCollectionUsers.test.js @@ -5,7 +5,7 @@ const httpMocks = require('node-mocks-http') const fixtures = require('./fixtures/fixtures') const Model = require('./helpers/Model') -const { standardCollection } = fixtures.collections +const { standardCollection, noTeamCollection } = fixtures.collections const { editorInChief, admin } = fixtures.users const query = { role: 'handlingEditor', @@ -76,4 +76,18 @@ describe('Get collection users route handler', () => { const data = JSON.parse(res._getData()) expect(data.error).toEqual('The request user must be Editor in Chief') }) + it('should return an error when the collection does not have a the requested role team', async () => { + const req = httpMocks.createRequest() + req.query = query + req.params.collectionId = noTeamCollection.id + req.user = editorInChief.id + const res = httpMocks.createResponse() + const models = Model.build() + await require(getCollectionUsersPath)(models)(req, res) + expect(res.statusCode).toBe(400) + const data = JSON.parse(res._getData()) + expect(data.error).toEqual( + `The requested collection does not have a ${query.role} Team`, + ) + }) }) diff --git a/packages/component-mail-service/src/Mail.js b/packages/component-mail-service/src/Mail.js index 1678944123bf67eb9e6f2379dcba1043010a85cf..df5e75ba50eb06507cae43596d20af68a18e8f76 100644 --- a/packages/component-mail-service/src/Mail.js +++ b/packages/component-mail-service/src/Mail.js @@ -26,8 +26,15 @@ module.exports = { } const { htmlBody, textBody } = getEmailBody(emailType, replacements) + const mailData = { + from: config.get('mailer.from'), + to: email, + subject, + text: textBody, + html: htmlBody, + } - return Email.send(email, subject, textBody, htmlBody) + return Email.send(mailData) }, setupAssignEmail: async (email, emailType, dashBoardUrl) => { let subject @@ -45,8 +52,14 @@ module.exports = { } const { htmlBody, textBody } = getEmailBody(emailType, replacements) - - return Email.send(email, subject, textBody, htmlBody) + const mailData = { + from: config.get('mailer.from'), + to: email, + subject, + text: textBody, + html: htmlBody, + } + return Email.send(mailData) }, } diff --git a/packages/component-send-email/src/SendEmail.js b/packages/component-send-email/src/SendEmail.js index 00d1d04922e8c61e3b941c7e72c8bfd2d960d55b..fa16450219d8b3b8cd29d8987f92afd3859f7b42 100644 --- a/packages/component-send-email/src/SendEmail.js +++ b/packages/component-send-email/src/SendEmail.js @@ -1,28 +1,10 @@ const nodemailer = require('nodemailer') const config = require('config') -const logger = require('@pubsweet/logger') const mailerConfig = require(config.mailer.path) module.exports = { - send: (toEmail, subject, textBody, htmlBody) => - new Promise((resolve, reject) => { - const transporter = nodemailer.createTransport(mailerConfig.transport) - transporter.sendMail( - { - from: mailerConfig.from, - to: toEmail, - subject, - text: textBody, - html: htmlBody, - }, - (err, info) => { - if (err) { - logger.error(err) - return reject(err) - } - logger.info(`success message id: ${info.response}`) - return resolve(info.response) - }, - ) - }), + send: mailData => { + const transporter = nodemailer.createTransport(mailerConfig.transport) + return transporter.sendMail(mailData) + }, } diff --git a/packages/components-faraday/src/components/Files/FileSection.js b/packages/components-faraday/src/components/Files/FileSection.js index 453006fd28b79946f691ea5b8ef8140537731d9d..88459761fc6e566bb217373fd84d176ff2153c0b 100644 --- a/packages/components-faraday/src/components/Files/FileSection.js +++ b/packages/components-faraday/src/components/Files/FileSection.js @@ -65,7 +65,10 @@ const FileSection = ({ disabled={disabledFilepicker()} onUpload={addFile} > - <UploadButton disabled={disabledFilepicker()}> + <UploadButton + data-test={`button-upload-${listId}`} + disabled={disabledFilepicker()} + > <Icon color={ disabledFilepicker() diff --git a/packages/xpub-faraday/config/custom-environment-variables.json b/packages/xpub-faraday/config/custom-environment-variables.json new file mode 100644 index 0000000000000000000000000000000000000000..0e0699befef530d2f906e2077c50c5f1a7b6517b --- /dev/null +++ b/packages/xpub-faraday/config/custom-environment-variables.json @@ -0,0 +1,7 @@ +{ + "SES": { + "accessKey": "AWS_SES_ACCESS_KEY", + "secretKey": "AWS_SES_SECRET_KEY", + "region": "AWS_SES_REGION" + } +} \ No newline at end of file diff --git a/packages/xpub-faraday/config/default.js b/packages/xpub-faraday/config/default.js index daf7cd9c23b834d96c4c0dc29b710e717c1ed078..62642c007485dc6db4f1d7f4805f96ebd512eb7b 100644 --- a/packages/xpub-faraday/config/default.js +++ b/packages/xpub-faraday/config/default.js @@ -1,5 +1,4 @@ require('dotenv').config() - const path = require('path') const components = require('./components.json') const logger = require('winston') @@ -66,7 +65,7 @@ module.exports = { }, }, mailer: { - from: process.env.EMAIL_SENDER || 'test_sender@domain.com', + from: 'sebastian.mihalache@thinslices.com', path: `${__dirname}/mailer`, }, publicKeys: [ diff --git a/packages/xpub-faraday/config/mailer.js b/packages/xpub-faraday/config/mailer.js index 61822e96e26af7b59b961d290431d1e67c9bc713..6867d67528bde09b7377109c2a45f771ebd3507f 100644 --- a/packages/xpub-faraday/config/mailer.js +++ b/packages/xpub-faraday/config/mailer.js @@ -1,12 +1,12 @@ const AWS = require('aws-sdk') +const config = require('config') module.exports = { - from: process.env.EMAIL_SENDER, transport: { SES: new AWS.SES({ - accessKeyId: process.env.AWS_SES_ACCESS_KEY, - secretAccessKey: process.env.AWS_SES_SECRET_KEY, - region: process.env.AWS_SES_REGION, + accessKeyId: config.SES.accessKey, + secretAccessKey: config.SES.secretKey, + region: config.SES.region, }), }, } diff --git a/packages/xpub-faraday/package.json b/packages/xpub-faraday/package.json index 84bcffe1ebda407d2399808effe8c1e920bacae4..365407d9373fac7980c27e0f9773f0b71db7bc16 100644 --- a/packages/xpub-faraday/package.json +++ b/packages/xpub-faraday/package.json @@ -78,7 +78,7 @@ "setupdb": "pubsweet setupdb ./", "reset": "pubsweet setupdb --clobber ./", "start": "pubsweet start", - "start-now": "echo $secret > config/local-development.json && npm run reset --username admin --email admin@mailinator.com --password admin123 && npm run start", + "start-now": "echo $secret > config/local-development.json && npm run start", "build": "NODE_ENV=production pubsweet build" } }