Skip to content

Commit 85c0384

Browse files
authored
fix(body-membership): send email to workspace admins for new members (#1043)
Co-authored-by: Rik Smale <WikiRik@users.noreply.github.com>
1 parent e50d140 commit 85c0384

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

config/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const config = {
1717
listserv_email: process.env.LISTSERV_EMAIL || 'listserv@example.com',
1818
listserv_endpoint: process.env.LISTSERV_ENDPOINT || 'https://lists.example.com/subscribe',
1919
listserv_token: process.env.LISTSERV_TOKEN || 'CHANGEME',
20+
google_workspace_notifications: [
21+
'workspace-admins@aegee.eu'
22+
],
2023
logger: {
2124
silent: false,
2225
level: process.env.LOGLEVEL || 'info'

lib/constants.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ module.exports = {
9090
MAIL_CHANGE: 'MyAEGEE: Email change',
9191
PASSWORD_RESET: 'MyAEGEE: Password reset request',
9292
NEW_JOIN_REQUEST: 'MyAEGEE: New join request for your body',
93-
NEW_MEMBER: 'MyAEGEE: Welcome to AEGEE'
93+
NEW_MEMBER: 'MyAEGEE: Welcome to AEGEE',
94+
WORKSPACE_NEW_MEMBER: 'MyAEGEE: A new member has joined their first local'
9495
},
9596
RESTRICTED_EMAILS: ['aegee.org', 'aegee.eu'],
9697
LISTSERV_LISTS: ['AEGEE-L', 'AEGEENEWS-L', 'ANNOUNCE-L', 'AEGEE-EVENT-L']

middlewares/body-memberships.js

+13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const { sequelize, Sequelize } = require('../lib/sequelize');
1010
const mailer = require('../lib/mailer');
1111
const constants = require('../lib/constants');
1212
const errors = require('../lib/errors');
13+
const config = require('../config');
1314

1415
exports.listAllMemberships = async (req, res) => {
1516
if (req.query.holds_permission) {
@@ -129,6 +130,18 @@ exports.createMembership = async (req, res) => {
129130
body_id: req.currentBody.id
130131
}
131132
});
133+
134+
await mailer.sendMail({
135+
to: config.google_workspace_notifications,
136+
subject: constants.MAIL_SUBJECTS.WORKSPACE_NEW_MEMBER,
137+
template: 'workspace_new_member.html',
138+
parameters: {
139+
member_firstname: user.first_name,
140+
member_lastname: user.last_name,
141+
user_id: user.id,
142+
member_email: user.email
143+
}
144+
});
132145
}
133146
});
134147

middlewares/join-requests.js

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const constants = require('../lib/constants');
55
const logger = require('../lib/logger');
66
const mailer = require('../lib/mailer');
77
const { Sequelize, sequelize } = require('../lib/sequelize');
8+
const config = require('../config');
89

910
exports.listAllJoinRequests = async (req, res) => {
1011
if (!req.permissions.hasPermission('view:join_request')) {
@@ -128,6 +129,18 @@ exports.changeRequestStatus = async (req, res) => {
128129
body_id: req.currentBody.id
129130
}
130131
});
132+
133+
await mailer.sendMail({
134+
to: config.google_workspace_notifications,
135+
subject: constants.MAIL_SUBJECTS.WORKSPACE_NEW_MEMBER,
136+
template: 'workspace_new_member.html',
137+
parameters: {
138+
member_firstname: user.first_name,
139+
member_lastname: user.last_name,
140+
user_id: user.id,
141+
email: user.email
142+
}
143+
});
131144
}
132145

133146
await req.currentJoinRequest.update({ status: req.body.status }, { transaction: t });

0 commit comments

Comments
 (0)