ep_email_notifications 11.0.16 → 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.
@@ -22,10 +22,14 @@ jobs:
22
22
  version: 1.0
23
23
  -
24
24
  name: Install etherpad core
25
- uses: actions/checkout@v4
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@v4
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@v4
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: Check out the plugin
36
- uses: actions/checkout@v4
40
+ name: Checkout plugin repository
41
+ uses: actions/checkout@v6
37
42
  with:
38
- path: ./node_modules/__tmp
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
- curl -sSfo /dev/null http://localhost:9001/ || return 1
85
- connected=true
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 15 ] && ! can_connect; do
90
- sleep 1
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 --with-deps
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
- // if it's a request to update an authors email
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.client.json.send({
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.client.json.send({
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.client.json.send({
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.client.json.send({
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.client.json.send({
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.client.json.send({
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.client.json.send({
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.client.json.send({
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
- args.app.get('/p/:padId/:action(subscribe|unsubscribe)=:actionId([\\s\\S]{0,})',
58
- (req, res, next) => handle(req, res).catch((err) => next(err || new Error(err))));
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ep_email_notifications",
3
3
  "description": "Subscribe to a pad and receive an email when someone edits your pad",
4
- "version": "11.0.16",
4
+ "version": "11.0.18",
5
5
  "author": {
6
6
  "name": "John Mclear",
7
7
  "email": "john@mclear.co.uk",
@@ -38,7 +38,7 @@
38
38
  "devDependencies": {
39
39
  "eslint": "^8.57.1",
40
40
  "eslint-config-etherpad": "^4.0.5",
41
- "typescript": "^6.0.2"
41
+ "typescript": "^6.0.3"
42
42
  },
43
43
  "scripts": {
44
44
  "lint": "eslint .",
@@ -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: `× ${window._('ep_email_notifications.titleGritterError')}`,
143
+ title: `× ${_('ep_email_notifications.titleGritterError')}`,
137
144
  // (string | mandatory) the text inside the notification
138
- text: window._('ep_email_notifications.msgParamsMissing'),
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
- * Initialize the popup panel form for subscription
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 popUpIsAlreadyVisible = $('#ep_email_form_popup').is(':visible');
166
- if (!popUpIsAlreadyVisible) { // if the popup isn't already visible
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
- // (string | mandatory) the heading of the notification
195
- title: `× ${window._('ep_email_notifications.titleGritterSubscr')}`,
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: `× ${window._('ep_email_notifications.titleGritterError')}`,
195
+ title: `× ${_('ep_email_notifications.titleGritterError')}`,
253
196
  // (string | mandatory) the text inside the notification
254
- text: window._('ep_email_notifications.msgOptionsNotChecked'),
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: `× ${window._('ep_email_notifications.titleGritterSubscr')}`,
254
+ title: `× ${_('ep_email_notifications.titleGritterSubscr')}`,
312
255
  // (string | mandatory) the text inside the notification
313
- text: window._('ep_email_notifications.msgSubscrSuccess'),
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 = window._('ep_email_notifications.msgEmailMalformed');
270
+ msg = _('ep_email_notifications.msgEmailMalformed');
328
271
  } else if (type === 'alreadyRegistered') {
329
- msg = window._('ep_email_notifications.msgAlreadySubscr');
272
+ msg = _('ep_email_notifications.msgAlreadySubscr');
330
273
  } else {
331
- msg = window._('ep_email_notifications.msgUnknownErr');
274
+ msg = _('ep_email_notifications.msgUnknownErr');
332
275
  }
333
276
  $.gritter.add({
334
277
  // (string | mandatory) the heading of the notification
335
- title: `× ${window._('ep_email_notifications.titleGritterSubscr')}`,
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: `× ${window._('ep_email_notifications.titleGritterUnsubscr')}`,
294
+ title: `× ${_('ep_email_notifications.titleGritterUnsubscr')}`,
352
295
  // (string | mandatory) the text inside the notification
353
- text: window._('ep_email_notifications.msgUnsubscrSuccess'),
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: `× ${window._('ep_email_notifications.titleGritterUnsubscr')}`,
310
+ title: `× ${_('ep_email_notifications.titleGritterUnsubscr')}`,
368
311
  // (string | mandatory) the text inside the notification
369
- text: window._('ep_email_notifications.msgUnsubscrNotExisting'),
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
@@ -0,0 +1,127 @@
1
+ import {expect, test} from '@playwright/test';
2
+ import {goToNewPad} from 'ep_etherpad-lite/tests/frontend-new/helper/padHelper';
3
+
4
+ test.beforeEach(async ({page}) => {
5
+ await goToNewPad(page);
6
+ });
7
+
8
+ test.describe('ep_email_notifications', () => {
9
+ const malformedEmail = 'tutti@bad-email';
10
+ const goodEmail = 'tutti@non-existing-domain.org';
11
+
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});
58
+
59
+ test('subscribe with no notification options shows missing-options notice', async ({page}) => {
60
+ await waitForPluginReady(page);
61
+ await openSettings(page);
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);
100
+ });
101
+
102
+ test('subscribe with malformed email is rejected', async ({page}) => {
103
+ await waitForPluginReady(page);
104
+ await openSettings(page);
105
+ await submitForm(page, {
106
+ name: 'ep_email_subscribe', email: malformedEmail, onStart: true, onEnd: false,
107
+ });
108
+ await expect(page.locator('.gritter-item').first()).toBeVisible({timeout: 30_000});
109
+ const missing = await page.evaluate(
110
+ () => (window as any).clientVars && (window as any).clientVars.ep_email_missing);
111
+ if (missing) test.skip(true, 'email settings not configured');
112
+ await expect(page.locator('.emailNotificationsSubscrResponseBad')).toHaveCount(1);
113
+ });
114
+
115
+ test('unsubscribe with unregistered email is rejected', async ({page}) => {
116
+ await waitForPluginReady(page);
117
+ await openSettings(page);
118
+ await submitForm(page, {
119
+ name: 'ep_email_unsubscribe', email: goodEmail, onStart: false, onEnd: false,
120
+ });
121
+ await expect(page.locator('.gritter-item').first()).toBeVisible({timeout: 30_000});
122
+ const missing = await page.evaluate(
123
+ () => (window as any).clientVars && (window as any).clientVars.ep_email_missing);
124
+ if (missing) test.skip(true, 'email settings not configured');
125
+ await expect(page.locator('.emailNotificationsUnsubscrResponseBad')).toHaveCount(1);
126
+ });
127
+ });
@@ -1,21 +1,21 @@
1
1
  <p>
2
- <input type="checkbox" id="options-emailNotifications"></input>
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.js');
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');
@@ -1,130 +0,0 @@
1
- 'use strict';
2
-
3
- describe('email notifications plugin', function () {
4
- // create a new pad before each test run
5
- beforeEach(function (cb) {
6
- helper.newPad(cb);
7
- this.timeout(60000);
8
- });
9
-
10
- // Subscribe malformed email
11
- const malformedEmail = 'tutti@bad-email';
12
-
13
- // Subscribe good email
14
- const goodEmail = 'tutti@non-existing-domain.org';
15
-
16
- // Test the form in mysetting menu
17
-
18
- // Launch the tests
19
- // First test without options selected
20
- it('makes test without options selected', function (done) {
21
- const chrome$ = helper.padChrome$;
22
-
23
- // click on the settings button to make settings visible
24
- const $settingsButton = chrome$('.buttonicon-settings');
25
- $settingsButton.click();
26
-
27
- // Show the notification form
28
- chrome$('.ep_email_settings').slideDown(() => {
29
- chrome$('#ep_email_form_mysettings [name=ep_email]').val(goodEmail);
30
- chrome$('#ep_email_form_mysettings [name=ep_email_onStart]').prop('checked', false);
31
- chrome$('#ep_email_form_mysettings [name=ep_email_onEnd]').prop('checked', false);
32
-
33
- chrome$('#ep_email_form_mysettings [name=ep_email_subscribe]').click(); // function() {
34
-
35
- // Is the correct gritter msg there
36
- helper.waitFor(() => chrome$('.gritter-item').is(':visible') === true)
37
- .done(() => {
38
- expect(chrome$('.emailNotificationsSubscrOptionsMissing').is(':visible')).to.be(true);
39
- done();
40
- });
41
- });
42
- });
43
-
44
- // Second, test with a malformed email
45
- it('makes test subscription with malformed email address', function (done) {
46
- const chrome$ = helper.padChrome$;
47
-
48
- // click on the settings button to make settings visible
49
- const $settingsButton = chrome$('.buttonicon-settings');
50
- $settingsButton.click();
51
-
52
- // Show the notification form
53
- chrome$('.ep_email_settings').slideDown(() => {
54
- chrome$('#ep_email_form_mysettings [name=ep_email]').val(malformedEmail);
55
- chrome$('#ep_email_form_mysettings [name=ep_email_onStart]').prop('checked', true);
56
-
57
- chrome$('#ep_email_form_mysettings [name=ep_email_subscribe]').click();
58
-
59
- // Is the correct gritter msg there
60
- helper.waitFor(() => chrome$('.gritter-item').is(':visible') === true)
61
- .done(() => {
62
- const clientVars = $('iframe')[0].contentWindow.window.clientVars;
63
- if (clientVars.ep_email_missing) { // don't test if settings aren't set
64
- return done();
65
- }
66
- expect(chrome$('.emailNotificationsSubscrResponseBad').is(':visible')).to.be(true);
67
- done();
68
- });
69
- });
70
- });
71
-
72
- // Third, test unsubscription with an email not registered
73
- it('makes test unsubscription with an unregistered email address', function (done) {
74
- const chrome$ = helper.padChrome$;
75
-
76
- // click on the settings button to make settings visible
77
- const $settingsButton = chrome$('.buttonicon-settings');
78
- $settingsButton.click();
79
-
80
- // Show the notification form
81
- chrome$('.ep_email_settings').slideDown(() => {
82
- chrome$('#ep_email_form_mysettings [name=ep_email]').val(goodEmail);
83
-
84
- chrome$('#ep_email_form_mysettings [name=ep_email_unsubscribe]').click();
85
-
86
- // Is the correct gritter msg there
87
- helper.waitFor(() => chrome$('.gritter-item').is(':visible') === true)
88
- .done(() => {
89
- const clientVars = $('iframe')[0].contentWindow.window.clientVars;
90
- if (clientVars.ep_email_missing) { // don't test if settings aren't set
91
- return done();
92
- }
93
-
94
- expect(chrome$('.emailNotificationsUnsubscrResponseBad').is(':visible')).to.be(true);
95
-
96
- done();
97
- });
98
- });
99
- });
100
-
101
- // Fourth, test subscription with a good email
102
- it('makes test subscription with an unregistered email address', function (done) {
103
- const chrome$ = helper.padChrome$;
104
-
105
- // click on the settings button to make settings visible
106
- const $settingsButton = chrome$('.buttonicon-settings');
107
- $settingsButton.click();
108
-
109
- // Show the notification form
110
- chrome$('.ep_email_settings').slideDown(() => {
111
- chrome$('#ep_email_form_mysettings [name=ep_email]').val(goodEmail);
112
- chrome$('#ep_email_form_mysettings [name=ep_email_onStart]').prop('checked', true);
113
-
114
- chrome$('#ep_email_form_mysettings [name=ep_email_subscribe]').click();
115
-
116
- // Is the correct gritter msg there
117
- helper.waitFor(() => chrome$('.gritter-item').is(':visible') === true)
118
- .done(() => {
119
- const clientVars = $('iframe')[0].contentWindow.window.clientVars;
120
- if (clientVars.ep_email_missing) { // don't test if settings aren't set
121
- return done();
122
- }
123
-
124
- expect(chrome$('.emailNotificationsSubscrResponseGood').is(':visible')).to.be(true);
125
-
126
- done();
127
- });
128
- });
129
- });
130
- });