ep_email_notifications 11.0.17 → 11.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/backend-tests.yml +6 -2
- package/.github/workflows/frontend-tests.yml +21 -43
- package/handleMessage.js +16 -11
- package/index.js +10 -2
- package/package.json +1 -1
- package/static/js/ep_email.js +38 -95
- package/static/tests/frontend-new/specs/email.spec.ts +95 -17
- package/templates/email_notifications_settings.ejs +18 -18
- package/update.js +1 -1
|
@@ -22,10 +22,14 @@ jobs:
|
|
|
22
22
|
version: 1.0
|
|
23
23
|
-
|
|
24
24
|
name: Install etherpad core
|
|
25
|
-
uses: actions/checkout@
|
|
25
|
+
uses: actions/checkout@v6
|
|
26
26
|
with:
|
|
27
27
|
repository: ether/etherpad-lite
|
|
28
28
|
path: etherpad-lite
|
|
29
|
+
- uses: actions/setup-node@v4
|
|
30
|
+
name: Install Node.js
|
|
31
|
+
with:
|
|
32
|
+
node-version: 22
|
|
29
33
|
- uses: pnpm/action-setup@v6
|
|
30
34
|
name: Install pnpm
|
|
31
35
|
with:
|
|
@@ -44,7 +48,7 @@ jobs:
|
|
|
44
48
|
${{ runner.os }}-pnpm-store-
|
|
45
49
|
-
|
|
46
50
|
name: Checkout plugin repository
|
|
47
|
-
uses: actions/checkout@
|
|
51
|
+
uses: actions/checkout@v6
|
|
48
52
|
with:
|
|
49
53
|
path: plugin
|
|
50
54
|
- name: Remove tests
|
|
@@ -12,9 +12,14 @@ jobs:
|
|
|
12
12
|
steps:
|
|
13
13
|
-
|
|
14
14
|
name: Check out Etherpad core
|
|
15
|
-
uses: actions/checkout@
|
|
15
|
+
uses: actions/checkout@v6
|
|
16
16
|
with:
|
|
17
17
|
repository: ether/etherpad-lite
|
|
18
|
+
path: etherpad-lite
|
|
19
|
+
- uses: actions/setup-node@v4
|
|
20
|
+
name: Install Node.js
|
|
21
|
+
with:
|
|
22
|
+
node-version: 22
|
|
18
23
|
- uses: pnpm/action-setup@v6
|
|
19
24
|
name: Install pnpm
|
|
20
25
|
with:
|
|
@@ -32,63 +37,36 @@ jobs:
|
|
|
32
37
|
restore-keys: |
|
|
33
38
|
${{ runner.os }}-pnpm-store-
|
|
34
39
|
-
|
|
35
|
-
name:
|
|
36
|
-
uses: actions/checkout@
|
|
40
|
+
name: Checkout plugin repository
|
|
41
|
+
uses: actions/checkout@v6
|
|
37
42
|
with:
|
|
38
|
-
path:
|
|
39
|
-
-
|
|
40
|
-
name: export GIT_HASH to env
|
|
41
|
-
id: environment
|
|
42
|
-
run: |
|
|
43
|
-
cd ./node_modules/__tmp
|
|
44
|
-
echo "::set-output name=sha_short::$(git rev-parse --short ${{ github.sha }})"
|
|
45
|
-
-
|
|
46
|
-
name: Determine plugin name
|
|
47
|
-
id: plugin_name
|
|
48
|
-
run: |
|
|
49
|
-
cd ./node_modules/__tmp
|
|
50
|
-
npx -c 'printf %s\\n "::set-output name=plugin_name::${npm_package_name}"'
|
|
51
|
-
-
|
|
52
|
-
name: Rename plugin directory
|
|
53
|
-
env:
|
|
54
|
-
PLUGIN_NAME: ${{ steps.plugin_name.outputs.plugin_name }}
|
|
55
|
-
run: |
|
|
56
|
-
mv ./node_modules/__tmp ./node_modules/"${PLUGIN_NAME}"
|
|
57
|
-
-
|
|
58
|
-
name: Install plugin dependencies
|
|
59
|
-
env:
|
|
60
|
-
PLUGIN_NAME: ${{ steps.plugin_name.outputs.plugin_name }}
|
|
61
|
-
run: |
|
|
62
|
-
cd ./node_modules/"${PLUGIN_NAME}"
|
|
63
|
-
pnpm i
|
|
64
|
-
# Etherpad core dependencies must be installed after installing the
|
|
65
|
-
# plugin's dependencies, otherwise npm will try to hoist common
|
|
66
|
-
# dependencies by removing them from src/node_modules and installing them
|
|
67
|
-
# in the top-level node_modules. As of v6.14.10, npm's hoist logic appears
|
|
68
|
-
# to be buggy, because it sometimes removes dependencies from
|
|
69
|
-
# src/node_modules but fails to add them to the top-level node_modules.
|
|
70
|
-
# Even if npm correctly hoists the dependencies, the hoisting seems to
|
|
71
|
-
# confuse tools such as `npm outdated`, `npm update`, and some ESLint
|
|
72
|
-
# rules.
|
|
43
|
+
path: plugin
|
|
73
44
|
-
|
|
74
45
|
name: Install Etherpad core dependencies
|
|
46
|
+
working-directory: ./etherpad-lite
|
|
75
47
|
run: bin/installDeps.sh
|
|
48
|
+
- name: Install plugin
|
|
49
|
+
working-directory: ./etherpad-lite
|
|
50
|
+
run: |
|
|
51
|
+
pnpm run plugins i --path ../../plugin
|
|
76
52
|
- name: Create settings.json
|
|
53
|
+
working-directory: ./etherpad-lite
|
|
77
54
|
run: cp ./src/tests/settings.json settings.json
|
|
78
55
|
- name: Run the frontend tests
|
|
56
|
+
working-directory: ./etherpad-lite
|
|
79
57
|
shell: bash
|
|
80
58
|
run: |
|
|
81
59
|
pnpm run dev &
|
|
82
60
|
connected=false
|
|
83
61
|
can_connect() {
|
|
84
|
-
|
|
85
|
-
|
|
62
|
+
curl -sSfo /dev/null http://localhost:9001/ || return 1
|
|
63
|
+
connected=true
|
|
86
64
|
}
|
|
87
65
|
now() { date +%s; }
|
|
88
66
|
start=$(now)
|
|
89
|
-
while [ $(($(now) - $start)) -le
|
|
90
|
-
|
|
67
|
+
while [ $(($(now) - $start)) -le 30 ] && ! can_connect; do
|
|
68
|
+
sleep 1
|
|
91
69
|
done
|
|
92
70
|
cd src
|
|
93
|
-
pnpm exec playwright install chromium
|
|
71
|
+
pnpm exec playwright install chromium --with-deps
|
|
94
72
|
pnpm run test-ui --project=chromium
|
package/handleMessage.js
CHANGED
|
@@ -33,9 +33,16 @@ const padUrl = (padId) => urlToPads + encodeURIComponent(padId);
|
|
|
33
33
|
exports.handleMessage = async (hookName, context) => {
|
|
34
34
|
if (!context.message || !context.message.data) return;
|
|
35
35
|
if (context.message.data.type === 'USERINFO_UPDATE') {
|
|
36
|
-
//
|
|
36
|
+
// USERINFO_UPDATE is also how Etherpad core ships username and color
|
|
37
|
+
// changes. Only intercept when this is actually an email
|
|
38
|
+
// subscribe/unsubscribe — otherwise let core handle it. Returning
|
|
39
|
+
// [null] (or running our own logic and stalling) on plain username
|
|
40
|
+
// updates clobbered every authoring-name change in pads where this
|
|
41
|
+
// plugin was installed without ep_email_notifications settings.
|
|
42
|
+
const userInfo = context.message.data.userInfo;
|
|
43
|
+
if (!userInfo || !userInfo.email || !userInfo.email_option) return;
|
|
37
44
|
if (!pluginSettings) {
|
|
38
|
-
context.
|
|
45
|
+
context.socket.emit("message", {
|
|
39
46
|
type: 'COLLABROOM',
|
|
40
47
|
data: {
|
|
41
48
|
type: 'emailNotificationMissingParams',
|
|
@@ -44,9 +51,7 @@ exports.handleMessage = async (hookName, context) => {
|
|
|
44
51
|
});
|
|
45
52
|
console.error('Settings for ep_email_notifications plugin are missing in settings.json file');
|
|
46
53
|
return [null];
|
|
47
|
-
// don't run onto passing colorId or anything else to the message handler
|
|
48
54
|
}
|
|
49
|
-
if (!context.message.data.userInfo || !context.message.data.userInfo.email) return;
|
|
50
55
|
console.debug(context.message);
|
|
51
56
|
|
|
52
57
|
// does email (Un)Subscription already exist for this email address?
|
|
@@ -142,7 +147,7 @@ const subscriptionEmail = async (context, email, emailFound, userInfo, padId) =>
|
|
|
142
147
|
await setAuthorEmailRegistered(userInfo, userInfo.userId, subscribeId, padId);
|
|
143
148
|
|
|
144
149
|
console.debug('emailSubSucc');
|
|
145
|
-
context.
|
|
150
|
+
context.socket.emit("message", {
|
|
146
151
|
type: 'COLLABROOM',
|
|
147
152
|
data: {
|
|
148
153
|
type: 'emailSubscriptionSuccess',
|
|
@@ -171,7 +176,7 @@ const subscriptionEmail = async (context, email, emailFound, userInfo, padId) =>
|
|
|
171
176
|
} else if (!validatesAsEmail) {
|
|
172
177
|
// Subscription -> failed coz mail malformed.. y'know in general fuck em!
|
|
173
178
|
console.debug('Dropped email subscription due to malformed email address');
|
|
174
|
-
context.
|
|
179
|
+
context.socket.emit("message", {
|
|
175
180
|
type: 'COLLABROOM',
|
|
176
181
|
data: {
|
|
177
182
|
type: 'emailSubscriptionSuccess',
|
|
@@ -187,7 +192,7 @@ const subscriptionEmail = async (context, email, emailFound, userInfo, padId) =>
|
|
|
187
192
|
console.debug('email ', context.message.data.userInfo.email,
|
|
188
193
|
'already subscribed to ', context.message.data.padId, ' so sending message to client');
|
|
189
194
|
|
|
190
|
-
context.
|
|
195
|
+
context.socket.emit("message", {
|
|
191
196
|
type: 'COLLABROOM',
|
|
192
197
|
data: {
|
|
193
198
|
type: 'emailSubscriptionSuccess',
|
|
@@ -214,7 +219,7 @@ const unsubscriptionEmail = async (context, emailFound, userInfo, padId) => {
|
|
|
214
219
|
|
|
215
220
|
await unsetAuthorEmailRegistered(userInfo, userInfo.userId, unsubscribeId, padId);
|
|
216
221
|
|
|
217
|
-
context.
|
|
222
|
+
context.socket.emit("message", {
|
|
218
223
|
type: 'COLLABROOM',
|
|
219
224
|
data: {
|
|
220
225
|
type: 'emailUnsubscriptionSuccess',
|
|
@@ -245,7 +250,7 @@ const unsubscriptionEmail = async (context, emailFound, userInfo, padId) => {
|
|
|
245
250
|
console.debug(
|
|
246
251
|
'Unsubscription: Send client a negative response ', context.message.data.userInfo.email);
|
|
247
252
|
|
|
248
|
-
context.
|
|
253
|
+
context.socket.emit("message", {
|
|
249
254
|
type: 'COLLABROOM',
|
|
250
255
|
data: {
|
|
251
256
|
type: 'emailUnsubscriptionSuccess',
|
|
@@ -265,7 +270,7 @@ const sendUserInfo = (context, emailFound, email, userInfo) => {
|
|
|
265
270
|
const {onStart = true, onEnd = false} = userInfo;
|
|
266
271
|
if (emailFound) {
|
|
267
272
|
// We send back the options associated to this userId
|
|
268
|
-
context.
|
|
273
|
+
context.socket.emit("message", {
|
|
269
274
|
type: 'COLLABROOM',
|
|
270
275
|
data: {
|
|
271
276
|
type: 'emailNotificationGetUserInfo',
|
|
@@ -280,7 +285,7 @@ const sendUserInfo = (context, emailFound, email, userInfo) => {
|
|
|
280
285
|
});
|
|
281
286
|
} else {
|
|
282
287
|
// No options set for this userId
|
|
283
|
-
context.
|
|
288
|
+
context.socket.emit("message", {
|
|
284
289
|
type: 'COLLABROOM',
|
|
285
290
|
data: {
|
|
286
291
|
type: 'emailNotificationGetUserInfo',
|
package/index.js
CHANGED
|
@@ -54,8 +54,16 @@ exports.registerRoute = (hookName, args, callback) => {
|
|
|
54
54
|
// Take a moment to clean all obsolete pending data
|
|
55
55
|
await cleanPendingData(padId);
|
|
56
56
|
};
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
// Express 5 / path-to-regexp v6 doesn't accept inline regex like
|
|
58
|
+
// `:action(subscribe|unsubscribe)=:actionId([\\s\\S]{0,})`, so use a
|
|
59
|
+
// regular expression route and extract the unnamed capture groups.
|
|
60
|
+
args.app.get(/^\/p\/([^/]+)\/(subscribe|unsubscribe)=([\s\S]+)$/,
|
|
61
|
+
(req, res, next) => {
|
|
62
|
+
req.params.padId = req.params[0];
|
|
63
|
+
req.params.action = req.params[1];
|
|
64
|
+
req.params.actionId = req.params[2];
|
|
65
|
+
return handle(req, res).catch((err) => next(err || new Error(err)));
|
|
66
|
+
});
|
|
59
67
|
|
|
60
68
|
callback(); // Am I even called?
|
|
61
69
|
};
|
package/package.json
CHANGED
package/static/js/ep_email.js
CHANGED
|
@@ -3,6 +3,21 @@
|
|
|
3
3
|
const cookie = require('ep_etherpad-lite/static/js/pad_cookie').padcookie;
|
|
4
4
|
let optionsAlreadyRecovered = false;
|
|
5
5
|
|
|
6
|
+
// Etherpad core sets `_ = html10n.get` (an unbound reference). Calling
|
|
7
|
+
// `_('key')` puts `this = window` inside the get implementation, so
|
|
8
|
+
// `this.translations` is `undefined` and the function falls into its
|
|
9
|
+
// "No translations available (yet)" branch and returns undefined — every
|
|
10
|
+
// time, regardless of whether translations have actually loaded. Newer
|
|
11
|
+
// jquery-gritter versions validate the `text` parameter and reject calls
|
|
12
|
+
// where it's undefined, so all of this plugin's $.gritter.add calls would
|
|
13
|
+
// silently fail to render. Use a properly-bound localizer instead.
|
|
14
|
+
const _ = (key) => {
|
|
15
|
+
const h = window.html10n;
|
|
16
|
+
if (!h || typeof h.get !== 'function') return key;
|
|
17
|
+
const out = h.get.call(h, key);
|
|
18
|
+
return out == null ? key : out;
|
|
19
|
+
};
|
|
20
|
+
|
|
6
21
|
exports.postAceInit = (hook, context) => {
|
|
7
22
|
// If panelDisplayLocation setting is missing, set default value
|
|
8
23
|
if (typeof clientVars.panelDisplayLocation !== 'object') {
|
|
@@ -71,10 +86,6 @@ exports.handleClientMessage_emailSubscriptionSuccess = (hook, context) => {
|
|
|
71
86
|
$('#options-emailNotifications').prop('checked', false);
|
|
72
87
|
}
|
|
73
88
|
|
|
74
|
-
if (clientVars.panelDisplayLocation.popup === true &&
|
|
75
|
-
$('#ep_email_form_popup').is(':visible')) {
|
|
76
|
-
$('#ep_email_form_popup').parent().parent().parent().hide();
|
|
77
|
-
}
|
|
78
89
|
}
|
|
79
90
|
};
|
|
80
91
|
|
|
@@ -95,10 +106,6 @@ exports.handleClientMessage_emailUnsubscriptionSuccess = (hook, context) => {
|
|
|
95
106
|
$('#options-emailNotifications').prop('checked', false);
|
|
96
107
|
}
|
|
97
108
|
|
|
98
|
-
if (clientVars.panelDisplayLocation.popup === true &&
|
|
99
|
-
$('#ep_email_form_popup').is(':visible')) {
|
|
100
|
-
$('#ep_email_form_popup').parent().parent().parent().hide();
|
|
101
|
-
}
|
|
102
109
|
}
|
|
103
110
|
};
|
|
104
111
|
|
|
@@ -133,9 +140,9 @@ exports.handleClientMessage_emailNotificationMissingParams = (hook, context) =>
|
|
|
133
140
|
if (context.payload === true) {
|
|
134
141
|
$.gritter.add({
|
|
135
142
|
// (string | mandatory) the heading of the notification
|
|
136
|
-
title: `× ${
|
|
143
|
+
title: `× ${_('ep_email_notifications.titleGritterError')}`,
|
|
137
144
|
// (string | mandatory) the text inside the notification
|
|
138
|
-
text:
|
|
145
|
+
text: _('ep_email_notifications.msgParamsMissing'),
|
|
139
146
|
// (bool | optional) if you want it to fade out on its own or just sit there
|
|
140
147
|
sticky: true,
|
|
141
148
|
// (string | optional) add a class name to the gritter msg
|
|
@@ -151,88 +158,24 @@ exports.handleClientMessage_emailNotificationMissingParams = (hook, context) =>
|
|
|
151
158
|
}
|
|
152
159
|
|
|
153
160
|
// Hide the popup if it is visible
|
|
154
|
-
if (clientVars.panelDisplayLocation.popup === true &&
|
|
155
|
-
$('#ep_email_form_popup').is(':visible')) {
|
|
156
|
-
$('#ep_email_form_popup').parent().parent().parent().hide();
|
|
157
|
-
}
|
|
158
161
|
}
|
|
159
162
|
};
|
|
160
163
|
|
|
161
164
|
/**
|
|
162
|
-
*
|
|
165
|
+
* Nudge the user toward Settings → Email Notifications. Earlier versions
|
|
166
|
+
* of this plugin tried to clone the entire mysettings form into the
|
|
167
|
+
* gritter `text` field, but newer jquery-gritter escapes that text so
|
|
168
|
+
* the popup rendered as raw HTML. The form already lives in the user
|
|
169
|
+
* settings panel — point people there instead.
|
|
163
170
|
*/
|
|
164
171
|
const initPopupForm = () => {
|
|
165
|
-
const
|
|
166
|
-
if (
|
|
167
|
-
const cookieVal = `${pad.getPadId()}email`;
|
|
168
|
-
if (cookie.getPref(cookieVal) !== 'true') { // if this user hasn't already subscribed
|
|
169
|
-
askClientToEnterEmail(); // ask the client to register TODO uncomment me for a pop up
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
/*
|
|
174
|
-
const clientHasAlreadyRegistered = () => {
|
|
175
|
-
// Has the client already registered for emails on this?
|
|
176
|
-
// Given a specific AuthorID do we have an email address in the database?
|
|
177
|
-
// Given that email address is it registered to this pad?
|
|
178
|
-
// need to pass the server a message to check
|
|
179
|
-
const userId = pad.getUserId();
|
|
180
|
-
const message = {};
|
|
181
|
-
message.type = 'USERINFO_AUTHOR_EMAIL_IS_REGISTERED_TO_PAD';
|
|
182
|
-
message.userInfo = {};
|
|
183
|
-
message.userInfo.userId = userId;
|
|
184
|
-
pad.collabClient.sendMessage(message);
|
|
185
|
-
};
|
|
186
|
-
*/
|
|
187
|
-
|
|
188
|
-
const askClientToEnterEmail = () => {
|
|
189
|
-
const formContent = $('.ep_email_settings')
|
|
190
|
-
.html()
|
|
191
|
-
.replace('ep_email_form_mysettings', 'ep_email_form_popup');
|
|
192
|
-
|
|
172
|
+
const cookieVal = `${pad.getPadId()}email`;
|
|
173
|
+
if (cookie.getPref(cookieVal) === 'true') return;
|
|
193
174
|
$.gritter.add({
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
// (string | mandatory) the text inside the notification
|
|
197
|
-
text: `<p class='ep_email_form_popup_header'>
|
|
198
|
-
${window._('ep_email_notifications.headerGritterSubscr')}
|
|
199
|
-
</p>${formContent}`,
|
|
200
|
-
// (bool | optional) if you want it to fade out on its own or just sit there
|
|
175
|
+
title: `× ${_('ep_email_notifications.titleGritterSubscr')}`,
|
|
176
|
+
text: _('ep_email_notifications.headerGritterSubscr'),
|
|
201
177
|
sticky: true,
|
|
202
|
-
// (string | optional) add a class name to the gritter msg
|
|
203
178
|
class_name: 'emailNotificationsPopupForm',
|
|
204
|
-
// the function to bind to the form
|
|
205
|
-
after_open: (e) => {
|
|
206
|
-
$('#ep_email_form_popup').submit(() => {
|
|
207
|
-
sendEmailToServer('ep_email_form_popup');
|
|
208
|
-
return false;
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
// Prepare subscription before submit form
|
|
212
|
-
$('#ep_email_form_popup [name=ep_email_subscribe]').on('click', (e) => {
|
|
213
|
-
$('#ep_email_form_popup [name=ep_email_option]').val('subscribe');
|
|
214
|
-
checkAndSend(e);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
// Prepare unsubscription before submit form
|
|
218
|
-
$('#ep_email_form_popup [name=ep_email_unsubscribe]').on('click', (e) => {
|
|
219
|
-
$('#ep_email_form_popup [name=ep_email_option]').val('unsubscribe');
|
|
220
|
-
checkAndSend(e);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
if (optionsAlreadyRecovered === false) {
|
|
224
|
-
getDataForUserId('ep_email_form_popup');
|
|
225
|
-
} else {
|
|
226
|
-
// Get datas from form in mysettings menu
|
|
227
|
-
$('#ep_email_form_popup [name=ep_email]')
|
|
228
|
-
.val($('#ep_email_form_mysettings [name=ep_email]').val());
|
|
229
|
-
$('#ep_email_form_popup [name=ep_email_onStart]')
|
|
230
|
-
.prop('checked', $('#ep_email_form_mysettings [name=ep_email_onStart]')
|
|
231
|
-
.prop('checked'));
|
|
232
|
-
$('#ep_email_form_popup [name=ep_email_onEnd]')
|
|
233
|
-
.prop('checked', $('#ep_email_form_mysettings [name=ep_email_onEnd]').prop('checked'));
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
179
|
});
|
|
237
180
|
};
|
|
238
181
|
|
|
@@ -249,9 +192,9 @@ const checkAndSend = (e) => {
|
|
|
249
192
|
!$(`#${formName} [name=ep_email_onEnd]`).is(':checked')) {
|
|
250
193
|
$.gritter.add({
|
|
251
194
|
// (string | mandatory) the heading of the notification
|
|
252
|
-
title: `× ${
|
|
195
|
+
title: `× ${_('ep_email_notifications.titleGritterError')}`,
|
|
253
196
|
// (string | mandatory) the text inside the notification
|
|
254
|
-
text:
|
|
197
|
+
text: _('ep_email_notifications.msgOptionsNotChecked'),
|
|
255
198
|
// (string | optional) add a class name to the gritter msg
|
|
256
199
|
class_name: 'emailNotificationsSubscrOptionsMissing',
|
|
257
200
|
});
|
|
@@ -308,9 +251,9 @@ Manage return msgs from server
|
|
|
308
251
|
const showRegistrationSuccess = () => {
|
|
309
252
|
$.gritter.add({
|
|
310
253
|
// (string | mandatory) the heading of the notification
|
|
311
|
-
title: `× ${
|
|
254
|
+
title: `× ${_('ep_email_notifications.titleGritterSubscr')}`,
|
|
312
255
|
// (string | mandatory) the text inside the notification
|
|
313
|
-
text:
|
|
256
|
+
text: _('ep_email_notifications.msgSubscrSuccess'),
|
|
314
257
|
// (int | optional) the time you want it to be alive for before fading out
|
|
315
258
|
time: 10000,
|
|
316
259
|
// (string | optional) add a class name to the gritter msg
|
|
@@ -324,15 +267,15 @@ const showRegistrationSuccess = () => {
|
|
|
324
267
|
const showAlreadyRegistered = (type) => {
|
|
325
268
|
let msg;
|
|
326
269
|
if (type === 'malformedEmail') {
|
|
327
|
-
msg =
|
|
270
|
+
msg = _('ep_email_notifications.msgEmailMalformed');
|
|
328
271
|
} else if (type === 'alreadyRegistered') {
|
|
329
|
-
msg =
|
|
272
|
+
msg = _('ep_email_notifications.msgAlreadySubscr');
|
|
330
273
|
} else {
|
|
331
|
-
msg =
|
|
274
|
+
msg = _('ep_email_notifications.msgUnknownErr');
|
|
332
275
|
}
|
|
333
276
|
$.gritter.add({
|
|
334
277
|
// (string | mandatory) the heading of the notification
|
|
335
|
-
title: `× ${
|
|
278
|
+
title: `× ${_('ep_email_notifications.titleGritterSubscr')}`,
|
|
336
279
|
// (string | mandatory) the text inside the notification
|
|
337
280
|
text: msg,
|
|
338
281
|
// (int | optional) the time you want it to be alive for before fading out
|
|
@@ -348,9 +291,9 @@ const showAlreadyRegistered = (type) => {
|
|
|
348
291
|
const showUnregistrationSuccess = () => {
|
|
349
292
|
$.gritter.add({
|
|
350
293
|
// (string | mandatory) the heading of the notification
|
|
351
|
-
title: `× ${
|
|
294
|
+
title: `× ${_('ep_email_notifications.titleGritterUnsubscr')}`,
|
|
352
295
|
// (string | mandatory) the text inside the notification
|
|
353
|
-
text:
|
|
296
|
+
text: _('ep_email_notifications.msgUnsubscrSuccess'),
|
|
354
297
|
// (int | optional) the time you want it to be alive for before fading out
|
|
355
298
|
time: 10000,
|
|
356
299
|
// (string | optional) add a class name to the gritter msg
|
|
@@ -364,9 +307,9 @@ const showUnregistrationSuccess = () => {
|
|
|
364
307
|
const showWasNotRegistered = () => {
|
|
365
308
|
$.gritter.add({
|
|
366
309
|
// (string | mandatory) the heading of the notification
|
|
367
|
-
title: `× ${
|
|
310
|
+
title: `× ${_('ep_email_notifications.titleGritterUnsubscr')}`,
|
|
368
311
|
// (string | mandatory) the text inside the notification
|
|
369
|
-
text:
|
|
312
|
+
text: _('ep_email_notifications.msgUnsubscrNotExisting'),
|
|
370
313
|
// (int | optional) the time you want it to be alive for before fading out
|
|
371
314
|
time: 7000,
|
|
372
315
|
// (string | optional) add a class name to the gritter msg
|
|
@@ -9,41 +9,119 @@ test.describe('ep_email_notifications', () => {
|
|
|
9
9
|
const malformedEmail = 'tutti@bad-email';
|
|
10
10
|
const goodEmail = 'tutti@non-existing-domain.org';
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
// Settings popup opens but .ep_email_settings stays collapsed by default;
|
|
13
|
+
// legacy spec used jQuery's .slideDown() and reached into hidden inputs
|
|
14
|
+
// anyway. Drive the form via DOM so visibility doesn't gate anything.
|
|
15
|
+
const submitForm = (
|
|
16
|
+
page: any,
|
|
17
|
+
{name, email, onStart, onEnd}: {
|
|
18
|
+
name: string; email: string; onStart: boolean; onEnd: boolean;
|
|
19
|
+
},
|
|
20
|
+
) => page.evaluate(
|
|
21
|
+
({name, email, onStart, onEnd}: any) => {
|
|
22
|
+
const set = (selector: string, mutate: (el: HTMLInputElement) => void) => {
|
|
23
|
+
const el = document.querySelector<HTMLInputElement>(selector);
|
|
24
|
+
if (!el) throw new Error(`element ${selector} not found`);
|
|
25
|
+
mutate(el);
|
|
26
|
+
};
|
|
27
|
+
set('#ep_email_form_mysettings [name=ep_email]', (el) => { el.value = email; });
|
|
28
|
+
set('#ep_email_form_mysettings [name=ep_email_onStart]',
|
|
29
|
+
(el) => { el.checked = onStart; });
|
|
30
|
+
set('#ep_email_form_mysettings [name=ep_email_onEnd]',
|
|
31
|
+
(el) => { el.checked = onEnd; });
|
|
32
|
+
// Mirror the plugin's per-button option setter so the click handler's
|
|
33
|
+
// ep_email_option check passes regardless of the order Playwright
|
|
34
|
+
// fires the event.
|
|
35
|
+
const optEl = document.querySelector<HTMLInputElement>(
|
|
36
|
+
'#ep_email_form_mysettings [name=ep_email_option]')!;
|
|
37
|
+
if (name === 'ep_email_subscribe') optEl.value = 'subscribe';
|
|
38
|
+
else if (name === 'ep_email_unsubscribe') optEl.value = 'unsubscribe';
|
|
39
|
+
// dispatchEvent fires synchronously, so the click handler (and
|
|
40
|
+
// checkAndSend) runs to completion in this same task — no chance for
|
|
41
|
+
// the popup's USERINFO_GET response handler to slip in.
|
|
42
|
+
document.querySelector<HTMLElement>(
|
|
43
|
+
`#ep_email_form_mysettings [name=${name}]`)!.dispatchEvent(
|
|
44
|
+
new MouseEvent('click', {bubbles: true, cancelable: true}));
|
|
45
|
+
}, {name, email, onStart, onEnd});
|
|
46
|
+
const openSettings = (page: any) => page.evaluate(
|
|
47
|
+
() => document.querySelector<HTMLElement>('.buttonicon-settings')!.click());
|
|
48
|
+
|
|
49
|
+
// Wait for the plugin's postAceInit to run so the click handler on
|
|
50
|
+
// [name=ep_email_subscribe] / [name=ep_email_unsubscribe] is bound.
|
|
51
|
+
// postAceInit normalizes clientVars.panelDisplayLocation to an object
|
|
52
|
+
// (the server ships the literal string 'undefined' when the plugin
|
|
53
|
+
// isn't configured), so a typeof === 'object' check is a reliable proxy.
|
|
54
|
+
const waitForPluginReady = (page: any) => page.waitForFunction(() => {
|
|
55
|
+
const cv = (window as any).clientVars;
|
|
56
|
+
return cv && typeof cv.panelDisplayLocation === 'object';
|
|
57
|
+
}, undefined, {timeout: 30_000});
|
|
16
58
|
|
|
17
59
|
test('subscribe with no notification options shows missing-options notice', async ({page}) => {
|
|
60
|
+
await waitForPluginReady(page);
|
|
18
61
|
await openSettings(page);
|
|
19
|
-
await page
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
62
|
+
await submitForm(page, {
|
|
63
|
+
name: 'ep_email_subscribe', email: goodEmail, onStart: false, onEnd: false,
|
|
64
|
+
});
|
|
65
|
+
// checkAndSend short-circuits with no server round-trip when no options are
|
|
66
|
+
// checked, so this assertion holds in CI even without ep_email_notifications
|
|
67
|
+
// configured in settings.json.
|
|
68
|
+
const gritter = page.locator('.emailNotificationsSubscrOptionsMissing');
|
|
69
|
+
await expect(gritter).toHaveCount(1, {timeout: 30_000});
|
|
70
|
+
// Assert the localized strings rendered, not just that the gritter exists.
|
|
71
|
+
// window._ in core is an unbound reference to html10n.get, so naïvely
|
|
72
|
+
// calling window._('key') returns undefined and the gritter would render
|
|
73
|
+
// with title "× undefined" and missing text — which the count check
|
|
74
|
+
// wouldn't catch. en.json values are reproduced verbatim here so a
|
|
75
|
+
// localization regression breaks this test instead of the user.
|
|
76
|
+
await expect(gritter).toContainText('Email subscription error');
|
|
77
|
+
await expect(gritter).toContainText('You need to check at least one checkbox.');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// The mysettings menu label is rendered server-side and translated via html10n's
|
|
81
|
+
// data-l10n-id pass; assert that ep_email_notifications.* keys actually resolve
|
|
82
|
+
// on this page so a future locale-loading regression is loud.
|
|
83
|
+
test('mysettings menu label is localized', async ({page}) => {
|
|
84
|
+
await waitForPluginReady(page);
|
|
85
|
+
await expect(page.locator('label[for="options-emailNotifications"]'))
|
|
86
|
+
.toHaveText('Email Notifications', {timeout: 30_000});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// The 10s auto-popup used to clone the mysettings form into the gritter
|
|
90
|
+
// text field. Newer jquery-gritter escapes that field, so the popup
|
|
91
|
+
// rendered as raw HTML. The popup is now a simple text nudge — assert
|
|
92
|
+
// it stays that way.
|
|
93
|
+
test('auto-popup is text-only and contains no embedded form', async ({page}) => {
|
|
94
|
+
await waitForPluginReady(page);
|
|
95
|
+
const popup = page.locator('.emailNotificationsPopupForm');
|
|
96
|
+
await expect(popup).toBeVisible({timeout: 15_000});
|
|
97
|
+
await expect(popup).toContainText('Email subscription');
|
|
98
|
+
await expect(popup).toContainText('Get an email notification when someone else edits this pad');
|
|
99
|
+
await expect(popup.locator('form')).toHaveCount(0);
|
|
25
100
|
});
|
|
26
101
|
|
|
27
102
|
test('subscribe with malformed email is rejected', async ({page}) => {
|
|
103
|
+
await waitForPluginReady(page);
|
|
28
104
|
await openSettings(page);
|
|
29
|
-
await page
|
|
30
|
-
|
|
31
|
-
|
|
105
|
+
await submitForm(page, {
|
|
106
|
+
name: 'ep_email_subscribe', email: malformedEmail, onStart: true, onEnd: false,
|
|
107
|
+
});
|
|
32
108
|
await expect(page.locator('.gritter-item').first()).toBeVisible({timeout: 30_000});
|
|
33
109
|
const missing = await page.evaluate(
|
|
34
110
|
() => (window as any).clientVars && (window as any).clientVars.ep_email_missing);
|
|
35
111
|
if (missing) test.skip(true, 'email settings not configured');
|
|
36
|
-
await expect(page.locator('.emailNotificationsSubscrResponseBad')).
|
|
112
|
+
await expect(page.locator('.emailNotificationsSubscrResponseBad')).toHaveCount(1);
|
|
37
113
|
});
|
|
38
114
|
|
|
39
115
|
test('unsubscribe with unregistered email is rejected', async ({page}) => {
|
|
116
|
+
await waitForPluginReady(page);
|
|
40
117
|
await openSettings(page);
|
|
41
|
-
await page
|
|
42
|
-
|
|
118
|
+
await submitForm(page, {
|
|
119
|
+
name: 'ep_email_unsubscribe', email: goodEmail, onStart: false, onEnd: false,
|
|
120
|
+
});
|
|
43
121
|
await expect(page.locator('.gritter-item').first()).toBeVisible({timeout: 30_000});
|
|
44
122
|
const missing = await page.evaluate(
|
|
45
123
|
() => (window as any).clientVars && (window as any).clientVars.ep_email_missing);
|
|
46
124
|
if (missing) test.skip(true, 'email settings not configured');
|
|
47
|
-
await expect(page.locator('.emailNotificationsUnsubscrResponseBad')).
|
|
125
|
+
await expect(page.locator('.emailNotificationsUnsubscrResponseBad')).toHaveCount(1);
|
|
48
126
|
});
|
|
49
127
|
});
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
<p>
|
|
2
|
-
<input type="checkbox" id="options-emailNotifications"
|
|
2
|
+
<input type="checkbox" id="options-emailNotifications">
|
|
3
3
|
<label for="options-emailNotifications" data-l10n-id="ep_email_notifications.menuLabel"></label>
|
|
4
|
-
<div class="ep_email_settings">
|
|
5
|
-
<form id='ep_email_form_mysettings'>
|
|
6
|
-
<input name='ep_email' class='ep_email_input' placeholder='your@email.com' type=email>
|
|
7
|
-
<br />
|
|
8
|
-
<label data-l10n-id="ep_email_notifications.formOptionsTitle"></label>
|
|
9
|
-
<br />
|
|
10
|
-
<input name='ep_email_onStart' type="checkbox" class="ep_email_checkbox"></input>
|
|
11
|
-
<label for="ep_email_onStart" data-l10n-id="ep_email_notifications.formOptionOnStart"></label>
|
|
12
|
-
<br />
|
|
13
|
-
<input name='ep_email_onEnd' type="checkbox" class="ep_email_checkbox"></input>
|
|
14
|
-
<label for="ep_email_onEnd" data-l10n-id="ep_email_notifications.formOptionOnEnd"></label>
|
|
15
|
-
<input name='ep_email_option' type=hidden >
|
|
16
|
-
<br />
|
|
17
|
-
<button name='ep_email_subscribe' type=button class="ep_email_buttons" data-l10n-id="ep_email_notifications.formBtnSubscr"></button>
|
|
18
|
-
<button name='ep_email_unsubscribe'type=button class="ep_email_buttons" data-l10n-id="ep_email_notifications.formBtnUnsubscr"></button>
|
|
19
|
-
</form>
|
|
20
|
-
</div>
|
|
21
4
|
</p>
|
|
5
|
+
<div class="ep_email_settings">
|
|
6
|
+
<form id="ep_email_form_mysettings">
|
|
7
|
+
<input id="ep_email" name="ep_email" class="ep_email_input" placeholder="your@email.com" type="email">
|
|
8
|
+
<br>
|
|
9
|
+
<label data-l10n-id="ep_email_notifications.formOptionsTitle"></label>
|
|
10
|
+
<br>
|
|
11
|
+
<input id="ep_email_onStart" name="ep_email_onStart" type="checkbox" class="ep_email_checkbox">
|
|
12
|
+
<label for="ep_email_onStart" data-l10n-id="ep_email_notifications.formOptionOnStart"></label>
|
|
13
|
+
<br>
|
|
14
|
+
<input id="ep_email_onEnd" name="ep_email_onEnd" type="checkbox" class="ep_email_checkbox">
|
|
15
|
+
<label for="ep_email_onEnd" data-l10n-id="ep_email_notifications.formOptionOnEnd"></label>
|
|
16
|
+
<input name="ep_email_option" type="hidden">
|
|
17
|
+
<br>
|
|
18
|
+
<button name="ep_email_subscribe" type="button" class="ep_email_buttons" data-l10n-id="ep_email_notifications.formBtnSubscr"></button>
|
|
19
|
+
<button name="ep_email_unsubscribe" type="button" class="ep_email_buttons" data-l10n-id="ep_email_notifications.formBtnUnsubscr"></button>
|
|
20
|
+
</form>
|
|
21
|
+
</div>
|
package/update.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Main job is to check pads periodically for activity and notify owners when
|
|
4
4
|
// someone begins editing and when someone finishes.
|
|
5
5
|
const db = require('ep_etherpad-lite/node/db/DB');
|
|
6
|
-
const API = require('ep_etherpad-lite/node/db/API
|
|
6
|
+
const API = require('ep_etherpad-lite/node/db/API');
|
|
7
7
|
const email = require('emailjs');
|
|
8
8
|
const settings = require('ep_etherpad-lite/node/utils/Settings');
|
|
9
9
|
const util = require('util');
|