Skip to content

Commit

Permalink
Merge branch 'develop' into feature/vocab-query-user-parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
cofiem committed Dec 9, 2024
2 parents 9fea34e + ef149bf commit 1b01880
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 119 deletions.
1 change: 1 addition & 0 deletions angular-legacy/dmp/app/dmp-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export class DmpFormComponent extends LoadableComponent {
console.log("Saving the following values:");
console.log(this.payLoad);
this.needsSave = false;
this.failedValidationLinks = [];
if (_.isEmpty(this.oid)) {
return this.RecordsService.create(this.payLoad, this.recordType, targetStep).flatMap((res:any)=>{
this.clearSaving();
Expand Down
4 changes: 3 additions & 1 deletion core/src/RecordsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ export interface RecordsService {
hasEditAccess(brand, user, roles, record): boolean;
hasViewAccess(brand, user, roles, record): boolean;
appendToRecord(targetRecordOid: string, linkData: any, fieldName: string, fieldType: string, targetRecord: any): Promise<any>
transitionWorkflowStep(currentRec: any, recordType: any, nextStep: any, user: any, triggerPreSaveTriggers: boolean, triggerPostSaveTriggers: boolean): Promise<any>;
setWorkflowStepRelatedMetadata(currentRec:any, nextStep:any): void;
transitionWorkflowStepMetadata(currentRec:any, nextStep:any): void;
triggerPreSaveTransitionWorkflowTriggers(oid: string, record: any, recordType: object, nextStep: any, user: object): Promise<any>;
triggerPostSaveTransitionWorkflowTriggers(oid: string, record: any, recordType: any, nextStep: any, user: object, response: any): any;
getAttachments(oid: string, labelFilterStr?: string): Promise<any>;
getDeletedRecords(workflowState, recordType, start, rows, username, roles, brand, editAccessOnly, packageType, sort, fieldNames?, filterString?, filterMode?): Promise<any>;
getRecords(workflowState, recordType, start, rows, username, roles, brand, editAccessOnly, packageType, sort, fieldNames?, filterString?, filterMode?, secondarySort?): Promise<any>;
Expand Down
58 changes: 57 additions & 1 deletion test/unit/services/EmailService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ describe('The EmailService', function () {
const format = "html";
const cc = '[email protected]';
const bcc = '[email protected]';
const replyTo = '[email protected]';

const sendResponse = EmailService.sendMessage(to, body, subject, from, format, cc, bcc);
const sendResponse = EmailService.sendMessage(to, body, subject, from, format, cc, bcc, {replyTo: replyTo});

sendResponse.subscribe(sendResult => {
expect(sendResult['success']).to.eql(true);
Expand Down Expand Up @@ -192,4 +193,59 @@ describe('The EmailService', function () {
});
});

describe('send record notification', function () {
let originalEmailDisabledValue;
beforeEach(function (done) {
originalEmailDisabledValue = _.get(sails.config , 'services.email.disabled');
done();
});
afterEach(function (done) {
_.set(sails.config , 'services.email.disabled', originalEmailDisabledValue);
done();
});
it('should respect disabled setting', async function () {
_.set(sails.config, 'services.email.disabled', "true");
const oid = "test-oid";
const record = "";
const options = {triggerCondition: ""};
const user = "";
const response = "";
const result = await EmailService.sendRecordNotification(oid, record, options, user, response).toPromise();
expect(result).to.equal(null);
});

it('should fail when to address is not valid', async function () {
const oid = "test-oid";
const record = {testing: true};
const options = {triggerCondition: "<%= record.testing %>"};
const user = "";
const response = {};
const result = await EmailService.sendRecordNotification(oid, record, options, user, response).toPromise();
expect(result).to.equal(null);
});

it('should send email when trigger condition matches', async function () {
const oid = "test-oid";
const record = {
metadata: {
testing: true,
title: "Testing title",
email_address: "[email protected]",
}
};
const options = {
triggerCondition: "<%= record.metadata.testing == true %>",
to: "<%= record.metadata.email_address %>",
subject: "Testing email sending",
template: "publicationReview",
otherSendOptions: {
'replyTo': '[email protected]',
}
};
const user = "";
const response = {content: "response content"};
const result = await EmailService.sendRecordNotification(oid, record, options, user, response).toPromise();
expect(result).to.equal(response);
});
});
});
3 changes: 1 addition & 2 deletions typescript/api/controllers/webservice/RecordController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,7 @@ export module Controllers {
}
const recType = await RecordTypesService.get(brand, record.metaMetadata.type).toPromise();
const nextStep = await WorkflowStepsService.get(recType, targetStepName).toPromise();
await this.RecordsService.transitionWorkflowStep(record, recType, nextStep, req.user, true, true);
const response = await this.RecordsService.updateMeta(brand, oid, record, req.user);
const response = await this.RecordsService.updateMeta(brand, oid, record, req.user, true, true, nextStep);
this.apiRespond(req, res, response);
} catch (err) {
this.apiFailWrapper(req, res, 500, new APIErrorResponse("Failed to transition workflow, please check server logs."), err,
Expand Down
17 changes: 11 additions & 6 deletions typescript/api/services/EmailService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export module Services {
* @param msgFormat The body format, either 'html' or 'text'.
* @param cc Email address(es) of recipients for 'cc' field.
* @param bcc Email address(es) of recipients for 'bcc' field.
* @param otherSendOptions Additional sending options.
* @return A promise that evaluates to the result of sending the email.
*/
public sendMessage(
Expand All @@ -76,10 +77,11 @@ export module Services {
msgFrom: string = sails.config.emailnotification.defaults.from,
msgFormat: string = sails.config.emailnotification.defaults.format,
cc: string = _.get(sails.config.emailnotification.defaults, 'cc', ''),
bcc: string = _.get(sails.config.emailnotification.defaults, 'bcc', '')
bcc: string = _.get(sails.config.emailnotification.defaults, 'bcc', ''),
otherSendOptions: {[dict_key: string]: any} = _.get(sails.config.emailnotification.defaults, 'otherSendOptions', {}),
): Observable<any> {

return Observable.fromPromise(this.sendMessageAsync(msgTo, msgBody, msgSubject, msgFrom, msgFormat, cc, bcc));
return Observable.fromPromise(this.sendMessageAsync(msgTo, msgBody, msgSubject, msgFrom, msgFormat, cc, bcc, otherSendOptions));

}

Expand All @@ -98,6 +100,7 @@ export module Services {
* @param msgFormat The body format, either 'html' or 'text'.
* @param cc Email address(es) of recipients for 'cc' field.
* @param bcc Email address(es) of recipients for 'bcc' field.
* @param otherSendOptions Additional sending options.
* @return The result of sending the email.
* @private
*/
Expand All @@ -108,7 +111,8 @@ export module Services {
msgFrom: string,
msgFormat: string,
cc: string,
bcc: string
bcc: string,
otherSendOptions: {[dict_key: string]: any} = {},
): Promise<any> {
if (!sails.config.emailnotification.settings.enabled) {
sails.log.debug("Received email notification request, but is disabled. Ignoring.");
Expand All @@ -130,13 +134,13 @@ export module Services {
};
}

var message = {
const message = _.merge(otherSendOptions, {
"to": msgTo,
"subject": msgSubject,
"from": msgFrom,
"cc": cc,
"bcc": bcc
};
"bcc": bcc,
});

message[msgFormat] = msgBody;
let response = {
Expand Down Expand Up @@ -297,6 +301,7 @@ export module Services {
optionsEvaluated.formatRendered,
optionsEvaluated.ccRendered,
optionsEvaluated.bccRendered,
_.get(options, 'otherSendOptions', {}),
);
})
.flatMap(sendResult => {
Expand Down
Loading

0 comments on commit 1b01880

Please sign in to comment.