Skip to content

Commit 77c0dbc

Browse files
committed
add user/group info in the group newsletter
1 parent 301fa4b commit 77c0dbc

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

handlers/courses/models/courseGroup.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ schema.methods.getMaterialUrl = function(material) {
9797
return `/courses/download/${this.slug}/${material.filename}`;
9898
};
9999

100+
schema.methods.getFeedbackUrl = function(material) {
101+
return `/courses/groups/${this.slug}/feedback`;
102+
};
103+
100104
schema.methods.getMaterialFileRelativePath = function(material) {
101105
return `courses/${this.slug}/${material.filename}`;
102106
};

handlers/courses/tasks/groupSend.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var gutil = require('gulp-util');
88
const path = require('path');
99
const CourseGroup = require('../models/courseGroup');
1010
const CourseParticipant = require('../models/courseParticipant');
11+
const User = require('users').User;
1112
const mailer = require('mailer');
1213
const config = require('config');
1314

@@ -38,7 +39,7 @@ module.exports = function() {
3839

3940
var participants = yield CourseParticipant.find({
4041
isActive: true,
41-
group: group._id
42+
group: group._id
4243
}).populate('user').exec();
4344

4445
var recipients = participants
@@ -66,21 +67,33 @@ module.exports = function() {
6667
recipientsToSend = [{email: args.test}];
6768
}
6869

69-
if (recipientsToSend.length) {
70+
var usersByEmail = {};
71+
for (var i = 0; i < recipientsToSend.length; i++) {
72+
var recipient = recipientsToSend[i];
73+
var user = yield User.findOne({email: recipient.email}).exec();
74+
if (!user) {
75+
throw new Error("No user for email: " + recipient.email);
76+
}
77+
usersByEmail[recipient.email] = user;
78+
}
79+
80+
for (var i = 0; i < recipientsToSend.length; i++) {
81+
82+
var recipient = recipientsToSend[i];
7083
yield* mailer.send({
7184
from: 'informer',
7285
templatePath: args.templatePath,
73-
to: recipientsToSend,
86+
to: [recipient],
87+
user: usersByEmail[recipient.email],
88+
group: group,
7489
subject: args.subject,
75-
label: args.test ? undefined : label,
76-
headers: {
77-
Precedence: 'bulk',
78-
'List-ID': `<${group.slug}.group.list-id.javascript.ru>`
79-
}
90+
label: args.test ? undefined : label
8091
});
8192

8293
gutil.log("Sent letter to " + JSON.stringify(recipientsToSend));
83-
} else {
94+
}
95+
96+
if (!recipients.length) {
8497
gutil.log(`No recipients (was ${recipients.length} before label exclusion)`);
8598
}
8699

0 commit comments

Comments
 (0)