Node.js based forum software built for the modern web
fix: tests
Barış Soner Uşaklıa411df132116
diff --git a/public/openapi/read.yaml b/public/openapi/read.yamlindex 02dad71349..885307aee8 100644--- a/public/openapi/read.yaml+++ b/public/openapi/read.yaml@@ -79,24 +79,6 @@ paths:$ref: 'read/admin/manage/tags.yaml'/api/admin/manage/users:$ref: 'read/admin/manage/users.yaml'- /api/admin/manage/users/search:- $ref: 'read/admin/manage/users/search.yaml'- /api/admin/manage/users/latest:- $ref: 'read/admin/manage/users/latest.yaml'- /api/admin/manage/users/not-validated:- $ref: 'read/admin/manage/users/not-validated.yaml'- /api/admin/manage/users/no-posts:- $ref: 'read/admin/manage/users/no-posts.yaml'- /api/admin/manage/users/top-posters:- $ref: 'read/admin/manage/users/top-posters.yaml'- /api/admin/manage/users/most-reputation:- $ref: 'read/admin/manage/users/most-reputation.yaml'- /api/admin/manage/users/inactive:- $ref: 'read/admin/manage/users/inactive.yaml'- /api/admin/manage/users/flagged:- $ref: 'read/admin/manage/users/flagged.yaml'- /api/admin/manage/users/banned:- $ref: 'read/admin/manage/users/banned.yaml'/api/admin/manage/registration:$ref: 'read/admin/manage/registration.yaml'/api/admin/manage/admins-mods:diff --git a/public/openapi/read/admin/manage/privileges/cid.yaml b/public/openapi/read/admin/manage/privileges/cid.yamlindex 07f6de868a..ddeadfefd3 100644--- a/public/openapi/read/admin/manage/privileges/cid.yaml+++ b/public/openapi/read/admin/manage/privileges/cid.yaml@@ -79,6 +79,8 @@ get:description: Each privilege will have a key in this objectisPrivate:type: boolean+ isSystem:+ type: booleancolumnCountUser:type: numbercolumnCountUserOther:diff --git a/public/openapi/read/admin/manage/users.yaml b/public/openapi/read/admin/manage/users.yamlindex 5248bb4d52..8bca9c7661 100644--- a/public/openapi/read/admin/manage/users.yaml+++ b/public/openapi/read/admin/manage/users.yaml@@ -21,12 +21,12 @@ get:type: numberresultsPerPage:type: number- latest:+ reverse:type: boolean- search_display:+ sortBy:type: string- requireEmailConfirmation:- type: number+ sort_online:+ type: booleaninviteOnly:type: booleanadminInviteOnly:diff --git a/public/openapi/read/admin/manage/users/banned.yaml b/public/openapi/read/admin/manage/users/banned.yamldeleted file mode 100644index 8c0d42a954..0000000000--- a/public/openapi/read/admin/manage/users/banned.yaml+++ /dev/null@@ -1,7 +0,0 @@-get:- tags:- - admin- summary: Get banned users- responses:- "418":- description: "TODO: A proper response needs to be added. It is not really a teapot | Replace this responses block with the block from /manage/users/latest"\ No newline at end of filediff --git a/public/openapi/read/admin/manage/users/flagged.yaml b/public/openapi/read/admin/manage/users/flagged.yamldeleted file mode 100644index 058e9f480e..0000000000--- a/public/openapi/read/admin/manage/users/flagged.yaml+++ /dev/null@@ -1,7 +0,0 @@-get:- tags:- - admin- summary: Get flagged users- responses:- "418":- description: "TODO: A proper response needs to be added. It is not really a teapot | Replace this responses block with the block from /manage/users/latest"\ No newline at end of filediff --git a/public/openapi/read/admin/manage/users/inactive.yaml b/public/openapi/read/admin/manage/users/inactive.yamldeleted file mode 100644index 60c01f8eb9..0000000000--- a/public/openapi/read/admin/manage/users/inactive.yaml+++ /dev/null@@ -1,7 +0,0 @@-get:- tags:- - admin- summary: Get inactive users- responses:- "418":- description: "TODO: A proper response needs to be added. It is not really a teapot | Replace this responses block with the block from /manage/users/latest"\ No newline at end of filediff --git a/public/openapi/read/admin/manage/users/latest.yaml b/public/openapi/read/admin/manage/users/latest.yamldeleted file mode 100644index b965d0c4c2..0000000000--- a/public/openapi/read/admin/manage/users/latest.yaml+++ /dev/null@@ -1,7 +0,0 @@-get:- tags:- - admin- summary: Get latest users- responses:- "418":- description: "TODO: A proper response needs to be added. It is not really a teapot | Replace this responses block with the block from /manage/users/latest"\ No newline at end of filediff --git a/public/openapi/read/admin/manage/users/most-reputation.yaml b/public/openapi/read/admin/manage/users/most-reputation.yamldeleted file mode 100644index 81758e8d60..0000000000--- a/public/openapi/read/admin/manage/users/most-reputation.yaml+++ /dev/null@@ -1,7 +0,0 @@-get:- tags:- - admin- summary: Get users with the most reputation- responses:- "418":- description: "TODO: A proper response needs to be added. It is not really a teapot | Replace this responses block with the block from /manage/users/latest"\ No newline at end of filediff --git a/public/openapi/read/admin/manage/users/no-posts.yaml b/public/openapi/read/admin/manage/users/no-posts.yamldeleted file mode 100644index 4d0e85b337..0000000000--- a/public/openapi/read/admin/manage/users/no-posts.yaml+++ /dev/null@@ -1,7 +0,0 @@-get:- tags:- - admin- summary: Get users with no posts- responses:- "418":- description: "TODO: A proper response needs to be added. It is not really a teapot | Replace this responses block with the block from /manage/users/latest"\ No newline at end of filediff --git a/public/openapi/read/admin/manage/users/not-validated.yaml b/public/openapi/read/admin/manage/users/not-validated.yamldeleted file mode 100644index 2a2e6fd29a..0000000000--- a/public/openapi/read/admin/manage/users/not-validated.yaml+++ /dev/null@@ -1,7 +0,0 @@-get:- tags:- - admin- summary: Get non-verified users- responses:- "418":- description: "TODO: A proper response needs to be added. It is not really a teapot | Replace this responses block with the block from /manage/users/latest"\ No newline at end of filediff --git a/public/openapi/read/admin/manage/users/search.yaml b/public/openapi/read/admin/manage/users/search.yamldeleted file mode 100644index bb5c8d7eaa..0000000000--- a/public/openapi/read/admin/manage/users/search.yaml+++ /dev/null@@ -1,39 +0,0 @@-get:- tags:- - admin- summary: Get users via search term- responses:- "200":- description: ""- content:- application/json:- schema:- allOf:- - type: object- properties:- search_display:- type: string- matchCount:- type: number- query:- type: string- uidQuery:- type: string- usernameQuery:- type: string- emailQuery:- type: string- ipQuery:- type: string- pageCount:- type: number- resultsPerPage:- type: number- timing:- type: number- users:- type: array- items:- $ref: ../../../../components/schemas/UserObject.yaml#/UserObjectACP- - $ref: ../../../../components/schemas/CommonProps.yaml#/CommonProps- - $ref: ../../../../components/schemas/Pagination.yaml#/Pagination\ No newline at end of filediff --git a/public/openapi/read/admin/manage/users/top-posters.yaml b/public/openapi/read/admin/manage/users/top-posters.yamldeleted file mode 100644index 41c11599d5..0000000000--- a/public/openapi/read/admin/manage/users/top-posters.yaml+++ /dev/null@@ -1,7 +0,0 @@-get:- tags:- - admin- summary: Get users with the most posts- responses:- "418":- description: "TODO: A proper response needs to be added. It is not really a teapot | Replace this responses block with the block from /manage/users/latest"\ No newline at end of filediff --git a/src/controllers/admin/users.js b/src/controllers/admin/users.jsindex 59cb1f20be..b505fda6d2 100644--- a/src/controllers/admin/users.js+++ b/src/controllers/admin/users.js@@ -36,7 +36,7 @@ async function getUsers(req, res) {resultsPerPage = 50;}let sortBy = validator.escape(req.query.sortBy || '');- const filterBy = Array.isArray(req.query.filters) ? req.query.filters : [req.query.filters];+ const filterBy = Array.isArray(req.query.filters || []) ? (req.query.filters || []) : [req.query.filters];const start = Math.max(0, page - 1) * resultsPerPage;const stop = start + resultsPerPage - 1;@@ -230,8 +230,10 @@ function render(req, res, data) {data.inviteOnly = registrationType === 'invite-only' || registrationType === 'admin-invite-only';data.adminInviteOnly = registrationType === 'admin-invite-only';data['sort_' + data.sortBy] = true;- data['searchBy_' + validator.escape(String(req.query.searchBy))] = true;- const filterBy = Array.isArray(req.query.filters) ? req.query.filters : [req.query.filters];+ if (req.query.searchBy) {+ data['searchBy_' + validator.escape(String(req.query.searchBy))] = true;+ }+ const filterBy = Array.isArray(req.query.filters || []) ? (req.query.filters || []) : [req.query.filters];filterBy.forEach(function (filter) {data['filterBy_' + validator.escape(String(filter))] = true;});diff --git a/src/groups/join.js b/src/groups/join.jsindex d29808c612..09d94954a4 100644--- a/src/groups/join.js+++ b/src/groups/join.js@@ -90,7 +90,10 @@ module.exports = function (Groups) {}async function setGroupTitleIfNotSet(groupNames, uid) {- groupNames = groupNames.filter(groupName => groupName !== 'registered-users' && !Groups.isPrivilegeGroup(groupName));+ const ignore = ['registered-users', 'verified-users', 'unverified-users'];+ groupNames = groupNames.filter(+ groupName => !ignore.includes(groupName) && !Groups.isPrivilegeGroup(groupName)+ );if (!groupNames.length) {return;}diff --git a/test/controllers-admin.js b/test/controllers-admin.jsindex 9fe1e4084c..61a6217ed8 100644--- a/test/controllers-admin.js+++ b/test/controllers-admin.js@@ -219,78 +219,6 @@ describe('Admin Controllers', function () {});});- it('should load /admin/manage/users/search', function (done) {- request(nconf.get('url') + '/api/admin/manage/users/search', { jar: jar, json: true }, function (err, res, body) {- assert.ifError(err);- assert.equal(res.statusCode, 200);- assert(body.users);- done();- });- });-- it('should load /admin/manage/users/not-validated', function (done) {- request(nconf.get('url') + '/api/admin/manage/users/not-validated', { jar: jar, json: true }, function (err, res, body) {- assert.ifError(err);- assert.equal(res.statusCode, 200);- assert(body);- done();- });- });-- it('should load /admin/manage/users/no-posts', function (done) {- request(nconf.get('url') + '/api/admin/manage/users/no-posts', { jar: jar, json: true }, function (err, res, body) {- assert.ifError(err);- assert.equal(res.statusCode, 200);- assert(body);- done();- });- });-- it('should load /admin/manage/users/top-posters', function (done) {- request(nconf.get('url') + '/api/admin/manage/users/top-posters', { jar: jar, json: true }, function (err, res, body) {- assert.ifError(err);- assert.equal(res.statusCode, 200);- assert(body);- done();- });- });-- it('should load /admin/manage/users/most-reputation', function (done) {- request(nconf.get('url') + '/api/admin/manage/users/most-reputation', { jar: jar, json: true }, function (err, res, body) {- assert.ifError(err);- assert.equal(res.statusCode, 200);- assert(body);- done();- });- });-- it('should load /admin/manage/users/inactive', function (done) {- request(nconf.get('url') + '/api/admin/manage/users/inactive', { jar: jar, json: true }, function (err, res, body) {- assert.ifError(err);- assert.equal(res.statusCode, 200);- assert(body);- done();- });- });-- it('should load /admin/manage/users/flagged', function (done) {- request(nconf.get('url') + '/api/admin/manage/users/flagged', { jar: jar, json: true }, function (err, res, body) {- assert.ifError(err);- assert.equal(res.statusCode, 200);- assert(body);- done();- });- });-- it('should load /admin/manage/users/banned', function (done) {- request(nconf.get('url') + '/api/admin/manage/users/banned', { jar: jar, json: true }, function (err, res, body) {- assert.ifError(err);- assert.equal(res.statusCode, 200);- assert(body);- done();- });- });-it('should load /admin/manage/registration', function (done) {request(nconf.get('url') + '/api/admin/manage/registration', { jar: jar, json: true }, function (err, res, body) {assert.ifError(err);diff --git a/test/controllers.js b/test/controllers.jsindex d316cac0aa..62a7c40940 100644--- a/test/controllers.js+++ b/test/controllers.js@@ -661,7 +661,7 @@ describe('Controllers', function () {});it('should error if guests do not have search privilege', function (done) {- request(nconf.get('url') + '/api/users?term=bar§ion=sort-posts', { json: true }, function (err, res, body) {+ request(nconf.get('url') + '/api/users?query=bar§ion=sort-posts', { json: true }, function (err, res, body) {assert.ifError(err);assert.equal(res.statusCode, 500);assert(body);@@ -673,7 +673,7 @@ describe('Controllers', function () {it('should load users search page', function (done) {privileges.global.give(['groups:search:users'], 'guests', function (err) {assert.ifError(err);- request(nconf.get('url') + '/users?term=bar§ion=sort-posts', function (err, res, body) {+ request(nconf.get('url') + '/users?query=bar§ion=sort-posts', function (err, res, body) {assert.ifError(err);assert.equal(res.statusCode, 200);assert(body);@@ -1509,6 +1509,7 @@ describe('Controllers', function () {assert.ifError(err);request(nconf.get('url') + '/api/user/groupie', { json: true }, function (err, res, body) {assert.ifError(err);+ console.log(body);assert.equal(res.statusCode, 200);assert(Array.isArray(body.selectedGroup));assert.equal(body.selectedGroup[0].name, 'selectedGroup');