Node.js based forum software built for the modern web
improve registration queue (#14856)
Elias Hackradt9d122948cf78
diff --git a/public/language/en-GB/registration-queue.json b/public/language/en-GB/registration-queue.jsonindex 7d7e28e832..400f5c5818 100644--- a/public/language/en-GB/registration-queue.json+++ b/public/language/en-GB/registration-queue.json@@ -2,8 +2,14 @@"queue": "Queue","no-users-in-queue": "There are no users in the registration queue.","description": "To enable this feature, go to <a href=\"%1\">Settings → User → User Registration</a> and set <strong>Registration Type</strong> to \"Admin Approval\".",+ "requests": "Registration Requests",+ "suspected-spam": "Suspected Spam",+ "suspected-spam-description": "These registrations matched one or more known spam signals. A match is not proof — review the details before rejecting.",+ "select-all": "Select all","reject-all": "Reject All",- "reject-all-confirm": "Do you want to reject all registration requests?",+ "reject-all-confirm": "Do you want to reject all registration requests on this page?",+ "reject-selected": "Reject Selected",+ "reject-selected-confirm": "Do you want to reject %1 selected registration request(s)?","list.name": "Name","list.email": "Email","list.ip": "IP",diff --git a/public/openapi/components/schemas/RegistrationQueueUser.yaml b/public/openapi/components/schemas/RegistrationQueueUser.yamlnew file mode 100644index 0000000000..ebafc26329--- /dev/null+++ b/public/openapi/components/schemas/RegistrationQueueUser.yaml@@ -0,0 +1,60 @@+RegistrationQueueUser:+ type: object+ properties:+ username:+ type: string+ email:+ type: string+ ip:+ type: string+ timestampISO:+ type: string+ usernameEscaped:+ type: string+ spamSuspected:+ type: boolean+ description: Whether a spam prevention plugin flagged this registration. Set by core from+ `usernameSpam`/`emailSpam`/`ipSpam` unless a plugin sets it explicitly in+ `filter:user.getRegistrationQueue`+ ipMatch:+ type: array+ items:+ type: object+ properties:+ username:+ type: string+ description: A friendly name for a given user account+ userslug:+ type: string+ description: An URL-safe variant of the username (i.e. lower-cased, spaces+ removed, etc.)+ picture:+ type: string+ uid:+ type: number+ description: A user identifier+ icon:text:+ type: string+ description: A single-letter representation of a username. This is used in the+ auto-generated icon given to users without+ an avatar+ icon:bgColor:+ type: string+ description: A six-character hexadecimal colour code assigned to the user. This+ value is used in conjunction with+ `icon:text` for the user's auto-generated+ icon+ example: "#f44336"+ customActions:+ type: array+ items:+ type: object+ properties:+ title:+ type: string+ id:+ type: string+ class:+ type: string+ icon:+ type: stringdiff --git a/public/openapi/read/registration-queue.yaml b/public/openapi/read/registration-queue.yamlindex de7dbe35a7..45a3d80b1a 100644--- a/public/openapi/read/registration-queue.yaml+++ b/public/openapi/read/registration-queue.yaml@@ -16,64 +16,35 @@ get:registrationQueueCount:type: numberusers:+ type: array+ description: Every registration on the current page, in queue order. Kept for+ backwards compatibility; `cleanUsers` and `spamUsers` are the same+ entries partitioned by `spamSuspected`+ items:+ $ref: ../components/schemas/RegistrationQueueUser.yaml#/RegistrationQueueUser+ cleanUsers:+ type: array+ items:+ $ref: ../components/schemas/RegistrationQueueUser.yaml#/RegistrationQueueUser+ spamUsers:+ type: array+ items:+ $ref: ../components/schemas/RegistrationQueueUser.yaml#/RegistrationQueueUser+ customHeaders:+ type: array+ customBulkActions:type: arrayitems:type: objectproperties:- username:- type: string- email:+ title:type: string- ip:+ id:type: string- timestampISO:+ class:type: string- usernameEscaped:+ icon:type: string- ipMatch:- type: array- items:- type: object- properties:- username:- type: string- description: A friendly name for a given user account- userslug:- type: string- description: An URL-safe variant of the username (i.e. lower-cased, spaces- removed, etc.)- picture:- type: string- uid:- type: number- description: A user identifier- icon:text:- type: string- description: A single-letter representation of a username. This is used in the- auto-generated icon given to users without- an avatar- icon:bgColor:- type: string- description: A six-character hexadecimal colour code assigned to the user. This- value is used in conjunction with- `icon:text` for the user's auto-generated- icon- example: "#f44336"- customActions:- type: array- items:- type: object- properties:- title:- type: string- id:- type: string- class:- type: string- icon:- type: string- customHeaders:- type: arrayinvites:type: arrayitems:diff --git a/public/src/client/registration-queue.js b/public/src/client/registration-queue.jsindex c52b2c09d8..34916024ef 100644--- a/public/src/client/registration-queue.js+++ b/public/src/client/registration-queue.js@@ -4,19 +4,49 @@define('forum/registration', ['modals', 'alerts'], function (modals, alerts) {const Registration = {};+ // exposed so plugins adding bulk actions can read the current selection+ Registration.getSelectedUsernames = function (groupEl) {+ return $(groupEl)+ .find('[component="registration-queue/select/single"]:checked')+ .map((index, el) => $(el).attr('data-username'))+ .get();+ };+Registration.init = function () {$('[data-bs-toggle="tooltip"]').tooltip();+ async function rejectUsernames(usernames) {+ await Promise.all(usernames.map(+ username => socket.emit('user.rejectRegistration', { username }).catch(alerts.error)+ ));+ ajaxify.refresh();+ }++ $('[component="registration-queue/select/all"]').on('change', function () {+ $(this)+ .closest('.registration-queue-group')+ .find('[component="registration-queue/select/single"]')+ .prop('checked', $(this).is(':checked'));+ });+$('[data-action="reject-all"]').on('click', () => {modals.confirm('[[registration-queue:reject-all-confirm]]', async (ok) => {if (ok) {- const rowEls = $('.users-list [data-username]');- await Promise.all(rowEls.map((index, rowEl) => {- return socket.emit('user.rejectRegistration', {- username: $(rowEl).attr('data-username'),- }).catch(alerts.error);- }));- ajaxify.refresh();+ await rejectUsernames($('.users-list tr[data-username]').map(+ (index, rowEl) => $(rowEl).attr('data-username')+ ).get());+ }+ });+ });++ $('[data-action="reject-selected"]').on('click', function () {+ const usernames = Registration.getSelectedUsernames($(this).closest('.registration-queue-group'));+ if (!usernames.length) {+ return alerts.error('[[error:no-users-selected]]');+ }+ modals.confirm(`[[registration-queue:reject-selected-confirm, ${usernames.length}]]`, async (ok) => {+ if (ok) {+ await rejectUsernames(usernames);}});});diff --git a/src/controllers/globalmods.js b/src/controllers/globalmods.jsindex 1fad36a615..d16bdd0c5e 100644--- a/src/controllers/globalmods.js+++ b/src/controllers/globalmods.js@@ -39,20 +39,33 @@ globalModsController.registrationQueue = async function (req, res, next) {const start = (page - 1) * 20;const stop = start + itemsPerPage - 1;- const [registrationQueueCount, users, customHeaders, invites] = await Promise.all([+ const [registrationQueueCount, users, customHeaders, customBulkActions, invites] = await Promise.all([db.sortedSetCard('registration:queue'),user.getRegistrationQueue(start, stop),plugins.hooks.fire('filter:admin.registrationQueue.customHeaders', { headers: [] }),+ plugins.hooks.fire('filter:admin.registrationQueue.customBulkActions', { actions: [] }),getInvites(),]);const pageCount = Math.max(1, Math.ceil(registrationQueueCount / itemsPerPage));+ const cleanUsers = [];+ const spamUsers = [];+ users.forEach((userData) => {+ if (userData.spamSuspected === undefined) {+ userData.spamSuspected = !!(userData.usernameSpam || userData.emailSpam || userData.ipSpam);+ }+ (userData.spamSuspected ? spamUsers : cleanUsers).push(userData);+ });+res.render('registration-queue', {title: '[[pages:registration-queue]]',pagination: pagination.create(page, pageCount, req.query),customHeaders: customHeaders.headers,+ customBulkActions: customBulkActions.actions,invites,users,+ cleanUsers,+ spamUsers,registrationQueueCount,queueEnabled: meta.config.registrationApprovalType === 'admin-approval' || meta.config.registrationApprovalType === 'admin-approval-ip',});diff --git a/src/views/partials/registration-queue/table-head.tpl b/src/views/partials/registration-queue/table-head.tplnew file mode 100644index 0000000000..5f4235d580--- /dev/null+++ b/src/views/partials/registration-queue/table-head.tpl@@ -0,0 +1,15 @@+<thead>+ <tr>+ <th class="align-middle" style="width: 1px;">+ <input class="form-check-input border-secondary" component="registration-queue/select/all" type="checkbox" aria-label="{{tx("registration-queue:select-all")}}"/>+ </th>+ <th>{{tx("registration-queue:list.name")}}</th>+ <th>{{tx("registration-queue:list.email")}}</th>+ <th class="hidden-xs">{{tx("registration-queue:list.ip")}}</th>+ <th class="hidden-xs">{{tx("registration-queue:list.time")}}</th>+ {{{ each customHeaders }}}+ <th class="hidden-xs">{{tx(./label)}}</th>+ {{{ end }}}+ <th></th>+ </tr>+</thead>diff --git a/src/views/partials/registration-queue/user-row.tpl b/src/views/partials/registration-queue/user-row.tplnew file mode 100644index 0000000000..4642c9abed--- /dev/null+++ b/src/views/partials/registration-queue/user-row.tpl@@ -0,0 +1,71 @@+<tr data-username="{./username}" class="align-middle">+ <td>+ <input class="form-check-input border-secondary" component="registration-queue/select/single" data-username="{./username}" type="checkbox" {{{ if ./spamSuspected }}}checked{{{ end }}}/>+ </td>+ <td>+ {{{ if ./usernameSpam }}}+ <i class="fa fa-times-circle text-danger" title="{{tx("registration-queue:list.username-spam", ./spamData.username.frequency, ./spamData.username.appears, ./spamData.username.confidence)}}" data-bs-toggle="tooltip" data-bs-html="true"></i>+ {{{ else }}}+ {{{ if ./spamChecked }}}+ <i class="fa fa-check text-success"></i>+ {{{ end }}}+ {{{ end }}}+ {./username}+ {{{ if ./sso }}}+ <i class="{./sso.icon}" title="{./sso.name}"></i>+ {{{ end }}}+ </td>+ <td>+ {{{ if ./emailSpam }}}+ <i class="fa fa-times-circle text-danger" title="{{tx("registration-queue:list.email-spam", ./spamData.email.frequency, ./spamData.email.appears, ./spamData.email.confidence)}}" data-bs-toggle="tooltip" data-bs-html="true"></i>+ {{{ else }}}+ {{{ if ./spamChecked }}}+ <i class="fa fa-check text-success"></i>+ {{{ end }}}+ {{{ end }}}+ {./email}+ </td>+ <td class="hidden-xs">+ <div class="d-flex gap-2 align-items-center">+ {{{ if ./ipSpam }}}+ <i class="fa fa-times-circle text-danger" title="{{tx("registration-queue:list.ip-spam", ./spamData.ip.frequency, ./spamData.ip.appears, ./spamData.ip.confidence)}}" data-bs-toggle="tooltip" data-bs-html="true"></i>+ {{{ else }}}+ {{{ if ./spamChecked }}}+ <i class="fa fa-check text-success"></i>+ {{{ end }}}+ {{{ end }}}+ {./ip}+ {{{ if ./ipMatch.length }}}+ <div class="dropdown position-static">+ <button type="button" class="btn btn-ghost btn-sm dropdown-toggle border" data-bs-toggle="dropdown" aria-expanded="false">{./ipMatch.length} <i class="fa-solid fa-users"></i></button>+ <ul class="dropdown-menu p-1 overflow-auto" style="max-height:300px;">+ {{{ each ./ipMatch}}}+ <li class="d-flex gap-1 align-items-center">+ <a href="{config.relative_path}/uid/{./uid}" class="dropdown-item rounded-1">{{buildAvatar(@value, "24px", true)}} {./username}</a>+ </li>+ {{{ end }}}+ </ul>+ </div>+ {{{ end }}}+ </div>+ </td>+ <td class="hidden-xs">+ <span class="timeago" title="{./timestampISO}"></span>+ </td>++ {{{ each ./customRows }}}+ <td class="hidden-xs">{./value}</td>+ {{{ end }}}++ <td>+ <div class="d-flex gap-1 justify-content-end">+ <button class="btn btn-light btn-sm" data-action="accept"><i class="fa fa-check text-success"></i></button>+ <button class="btn btn-light btn-sm" data-action="delete"><i class="fa fa-trash text-danger"></i></button>+ {{{ each ./customActions }}}+ <button id="{./id}" title="{{tx(./title)}}" class="btn btn-sm {./class}">+ <i class="fa {./icon}"></i>+ </button>+ {{{ end }}}+ </div>+ </td>+</tr>diff --git a/src/views/registration-queue.tpl b/src/views/registration-queue.tplindex d52104e0ef..5dce47fdff 100644--- a/src/views/registration-queue.tpl+++ b/src/views/registration-queue.tpl@@ -39,109 +39,66 @@aria-labelledby="registration-queue-tab"tabindex="0">- {{{ if users.length }}}- <div class="text-end mb-2">- <button data-action="reject-all" class="btn btn-sm btn-light ff-secondary">{{tx("registration-queue:reject-all")}}</button>- </div>- {{{ end }}}<div class="registration mb-3">{{{ if !queueEnabled }}}<p>{{tx("registration-queue:description", concat(config.relative_path, "/admin/settings/user#user-registration"))}}</p>{{{ end }}}- {{{ if queueEnabled }}}- {{{ end }}}{{{ if !users.length }}}<p>{{tx("registration-queue:no-users-in-queue")}}</p>- {{{ else }}}- <div class="table-responsive">- <table class="table table-sm text-sm users-list">- <thead>- <tr>- <th>{{tx("registration-queue:list.name")}}</th>- <th>{{tx("registration-queue:list.email")}}</th>- <th class="hidden-xs">{{tx("registration-queue:list.ip")}}</th>- <th class="hidden-xs">{{tx("registration-queue:list.time")}}</th>- {{{ each customHeaders }}}- <th class="hidden-xs">{{tx(./label)}}</th>+ {{{ end }}}++ {{{ if cleanUsers.length }}}+ <div class="registration-queue-group mb-4" data-group="requests">+ <h3 class="fs-5 mb-2">{{tx("registration-queue:requests")}} <span class="badge text-bg-light">{cleanUsers.length}</span></h3>+ <div class="table-responsive">+ <table class="table table-sm text-sm users-list">+ <!-- IMPORT partials/registration-queue/table-head.tpl -->+ <tbody>+ {{{ each cleanUsers }}}+ <!-- IMPORT partials/registration-queue/user-row.tpl -->{{{ end }}}- <th></th>- </tr>- </thead>- <tbody>- {{{ each users }}}- <tr data-username="{./username}" class="align-middle">- <td>- {{{ if ./usernameSpam }}}- <i class="fa fa-times-circle text-danger" title="{{tx("registration-queue:list.username-spam", ./spamData.username.frequency, ./spamData.username.appears, ./spamData.username.confidence)}}" data-bs-toggle="tooltip" data-bs-html="true"></i>- {{{ else }}}- {{{ if ./spamChecked }}}- <i class="fa fa-check text-success"></i>- {{{ end }}}- {{{ end }}}- {./username}- {{{ if ./sso }}}- <i class="{./sso.icon}" title="{./sso.name}"></i>- {{{ end }}}- </td>- <td>- {{{ if ./emailSpam }}}- <i class="fa fa-times-circle text-danger" title="{{tx("registration-queue:list.email-spam", ./spamData.email.frequency, ./spamData.email.appears, ./spamData.email.confidence)}}" data-bs-toggle="tooltip" data-bs-html="true"></i>- {{{ else }}}- {{{ if ./spamChecked }}}- <i class="fa fa-check text-success"></i>- {{{ end }}}- {{{ end }}}- {./email}- </td>- <td class="hidden-xs">- <div class="d-flex gap-2 align-items-center">- {{{ if ./ipSpam }}}- <i class="fa fa-times-circle text-danger" title="{{tx("registration-queue:list.ip-spam", ./spamData.ip.frequency, ./spamData.ip.appears, ./spamData.ip.confidence)}}" data-bs-toggle="tooltip" data-bs-html="true"></i>- {{{ else }}}- {{{ if ./spamChecked }}}- <i class="fa fa-check text-success"></i>- {{{ end }}}- {{{ end }}}- {./ip}- {{{ if ./ipMatch.length }}}- <div class="dropdown position-static">- <button type="button" class="btn btn-ghost btn-sm dropdown-toggle border" data-bs-toggle="dropdown" aria-expanded="false">{./ipMatch.length} <i class="fa-solid fa-users"></i></button>- <ul class="dropdown-menu p-1 overflow-auto" style="max-height:300px;">- {{{ each ./ipMatch}}}- <li class="d-flex gap-1 align-items-center">- <a href="{config.relative_path}/uid/{./uid}" class="dropdown-item rounded-1">{{buildAvatar(@value, "24px", true)}} {./username}</a>- </li>- {{{ end }}}- </ul>- </div>- {{{ end }}}- </div>- </td>- <td class="hidden-xs">- <span class="timeago" title="{./timestampISO}"></span>- </td>+ </tbody>+ </table>+ </div>+ <div class="d-flex flex-wrap gap-1 justify-content-end mt-2">+ <button data-action="reject-all" class="btn btn-sm btn-light ff-secondary">{{tx("registration-queue:reject-all")}}</button>+ <button data-action="reject-selected" class="btn btn-sm btn-light ff-secondary">{{tx("registration-queue:reject-selected")}}</button>+ </div>+ </div>+ {{{ end }}}- {{{ each ./customRows }}}- <td class="hidden-xs">{./value}</td>+ {{{ if spamUsers.length }}}+ <div class="registration-queue-group mb-4" data-group="spam">+ <h3 class="fs-5 mb-0">{{tx("registration-queue:suspected-spam")}} <span class="badge text-bg-danger">{spamUsers.length}</span></h3>+ <p class="text-muted text-sm">{{tx("registration-queue:suspected-spam-description")}}</p>+ <div class="table-responsive">+ <table class="table table-sm text-sm users-list">+ <!-- IMPORT partials/registration-queue/table-head.tpl -->+ <tbody>+ {{{ each spamUsers }}}+ <!-- IMPORT partials/registration-queue/user-row.tpl -->{{{ end }}}+ </tbody>+ </table>+ </div>+ <div class="d-flex flex-wrap gap-1 justify-content-end mt-2">+ {{{ each customBulkActions }}}+ <button id="{./id}" class="btn btn-sm {./class}">+ {{{ if ./icon }}}<i class="fa {./icon}"></i> {{{ end }}}{{tx(./title)}}+ </button>+ {{{ end }}}+ <button data-action="reject-selected" class="btn btn-sm btn-light ff-secondary">{{tx("registration-queue:reject-selected")}}</button>+ </div>+ </div>+ {{{ end }}}- <td>- <div class="d-flex gap-1 justify-content-end">- <button class="btn btn-light btn-sm" data-action="accept"><i class="fa fa-check text-success"></i></button>- <button class="btn btn-light btn-sm" data-action="delete"><i class="fa fa-trash text-danger"></i></button>- {{{ each ./customActions }}}- <button id="{./id}" title="{{tx(./title)}}" class="btn btn-sm {./class}">- <i class="fa {./icon}"></i>- </button>- {{{ end }}}- </div>- </td>- </tr>- {{{ end }}}- </tbody>- </table>+ {{{ if !cleanUsers.length }}}+ {{{ if users.length }}}+ <div class="d-flex justify-content-end mt-2">+ <button data-action="reject-all" class="btn btn-sm btn-light ff-secondary">{{tx("registration-queue:reject-all")}}</button></div>{{{ end }}}+ {{{ end }}}<!-- IMPORT admin/partials/paginator.tpl --></div>diff --git a/test/user.js b/test/user.jsindex 352501fc0c..60ef5bb072 100644--- a/test/user.js+++ b/test/user.js@@ -1993,6 +1993,37 @@ describe('User', () => {assert(body.includes('<script>alert("ok")<script>[email protected]'));});+ it('should split the queue into regular requests and suspected spam', async () => {+ await helpers.registerUser({+ username: 'spamqueued',+ password: '123456',+ email: '[email protected]',+ gdpr_consent: true,+ });+ const filterMethod = async (data) => {+ data.users.forEach((user) => {+ if (user.username === 'spamqueued') {+ user.spamChecked = true;+ user.ipSpam = true;+ }+ });+ return data;+ };+ plugins.hooks.register('test-plugin', { hook: 'filter:user.getRegistrationQueue', method: filterMethod });+ try {+ const { jar } = await helpers.loginUser('admin', '123456');+ const { body } = await request.get(`${nconf.get('url')}/api/registration-queue`, { jar });+ assert.deepStrictEqual(body.spamUsers.map(u => u.username), ['spamqueued']);+ assert(body.spamUsers.every(u => u.spamSuspected === true));+ assert(!body.cleanUsers.some(u => u.username === 'spamqueued'));+ assert(body.cleanUsers.every(u => u.spamSuspected === false));+ assert.strictEqual(body.users.length, body.cleanUsers.length + body.spamUsers.length);+ } finally {+ plugins.hooks.unregister('test-plugin', 'filter:user.getRegistrationQueue', filterMethod);+ await User.rejectRegistration('spamqueued');+ }+ });+it('should fail to add user to queue if username is taken', async () => {const { body } = await helpers.registerUser({username: 'rejectme',