Skip to content

Commit 00389d1

Browse files
authored
Merge branch 'master' into roleBasedValidator
2 parents e4d276e + 16b4aad commit 00389d1

File tree

5 files changed

+112
-30
lines changed

5 files changed

+112
-30
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ___
99
- IMPROVE: Optimize queries on classes with pointer permissions. [#7061](https://github.com/parse-community/parse-server/pull/7061). Thanks to [Pedro Diaz](https://github.com/pdiaz)
1010
- FIX: request.context for afterFind triggers. [#7078](https://github.com/parse-community/parse-server/pull/7078). Thanks to [dblythy](https://github.com/dblythy)
1111
- NEW: requireUserRoles for Parse Cloud validator. [#7097](https://github.com/parse-community/parse-server/pull/7097). Thanks to [dblythy](https://github.com/dblythy)
12+
- NEW: Added convenience method Parse.Cloud.sendEmail(...) to send email via email adapter in Cloud Code. [#7089](https://github.com/parse-community/parse-server/pull/7089). Thanks to [dblythy](https://github.com/dblythy)
1213

1314
### 4.5.0
1415
[Full Changelog](https://github.com/parse-community/parse-server/compare/4.4.0...4.5.0)

package-lock.json

Lines changed: 47 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@
3434
"cors": "2.8.5",
3535
"deepcopy": "2.1.0",
3636
"express": "4.17.1",
37-
"follow-redirects": "1.13.0",
37+
"follow-redirects": "1.13.1",
3838
"graphql": "15.4.0",
3939
"graphql-list-fields": "2.0.2",
4040
"graphql-relay": "0.6.0",
4141
"graphql-upload": "11.0.0",
4242
"intersect": "1.0.1",
4343
"jsonwebtoken": "8.5.1",
44-
"jwks-rsa": "1.11.0",
45-
"ldapjs": "2.2.2",
44+
"jwks-rsa": "1.12.0",
45+
"ldapjs": "2.2.3",
4646
"lodash": "4.17.20",
4747
"lru-cache": "5.1.1",
4848
"mime": "2.4.6",
@@ -51,13 +51,13 @@
5151
"pg-promise": "10.8.1",
5252
"pluralize": "8.0.0",
5353
"redis": "3.0.2",
54-
"semver": "7.3.2",
54+
"semver": "7.3.4",
5555
"subscriptions-transport-ws": "0.9.18",
5656
"tv4": "1.3.0",
57-
"uuid": "8.3.1",
57+
"uuid": "8.3.2",
5858
"winston": "3.3.3",
5959
"winston-daily-rotate-file": "4.5.0",
60-
"ws": "7.4.0"
60+
"ws": "7.4.1"
6161
},
6262
"devDependencies": {
6363
"@babel/cli": "7.10.0",

spec/CloudCode.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3168,3 +3168,29 @@ describe('afterLogin hook', () => {
31683168
await query.find({ context: { a: 'a' } });
31693169
});
31703170
});
3171+
3172+
describe('sendEmail', () => {
3173+
it('can send email via Parse.Cloud', async done => {
3174+
const emailAdapter = {
3175+
sendMail: mailData => {
3176+
expect(mailData).toBeDefined();
3177+
expect(mailData.to).toBe('test');
3178+
done();
3179+
},
3180+
};
3181+
await reconfigureServer({
3182+
emailAdapter: emailAdapter,
3183+
});
3184+
const mailData = { to: 'test' };
3185+
await Parse.Cloud.sendEmail(mailData);
3186+
});
3187+
3188+
it('cannot send email without adapter', async () => {
3189+
const logger = require('../lib/logger').logger;
3190+
spyOn(logger, 'error').and.callFake(() => {});
3191+
await Parse.Cloud.sendEmail({});
3192+
expect(logger.error).toHaveBeenCalledWith(
3193+
'Failed to send email because no mail adapter is configured for Parse Server.'
3194+
);
3195+
});
3196+
});

src/cloud-code/Parse.Cloud.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Parse } from 'parse/node';
22
import * as triggers from '../triggers';
3+
const Config = require('../Config');
34

45
function isParseObjectConstructor(object) {
56
return typeof object === 'function' && Object.prototype.hasOwnProperty.call(object, 'className');
@@ -528,6 +529,37 @@ ParseCloud.beforeConnect = function (handler, validationHandler) {
528529
);
529530
};
530531

532+
/**
533+
* Sends an email through the Parse Server mail adapter.
534+
*
535+
* **Available in Cloud Code only.**
536+
* **Requires a mail adapter to be configured for Parse Server.**
537+
*
538+
* ```
539+
* Parse.Cloud.sendEmail({
540+
* from: 'Example <test@example.com>',
541+
542+
* subject: 'Test email',
543+
* text: 'This email is a test.'
544+
* });
545+
*```
546+
*
547+
* @method sendEmail
548+
* @name Parse.Cloud.sendEmail
549+
* @param {Object} data The object of the mail data to send.
550+
*/
551+
ParseCloud.sendEmail = function (data) {
552+
const config = Config.get(Parse.applicationId);
553+
const emailAdapter = config.userController.adapter;
554+
if (!emailAdapter) {
555+
config.loggerController.error(
556+
'Failed to send email because no mail adapter is configured for Parse Server.'
557+
);
558+
return;
559+
}
560+
return emailAdapter.sendMail(data);
561+
};
562+
531563
/**
532564
* Registers a before live query subscription function.
533565
*

0 commit comments

Comments
 (0)