diff --git a/apps/meteor/app/api/server/v1/channels.js b/apps/meteor/app/api/server/v1/channels.js index 0ba1e876094a..2b02a1f86079 100644 --- a/apps/meteor/app/api/server/v1/channels.js +++ b/apps/meteor/app/api/server/v1/channels.js @@ -455,13 +455,10 @@ API.v1.addRoute( projection: fields, }); - const [channels, total] = await Promise.all([ - cursor.map((room) => this.composeRoomWithLastMessage(room, this.userId)).toArray(), - totalCount, - ]); + const [channels, total] = await Promise.all([cursor.toArray(), totalCount]); return API.v1.success({ - channels, + channels: channels.map((room) => this.composeRoomWithLastMessage(room, this.userId)), count: channels.length, offset, total, @@ -492,13 +489,10 @@ API.v1.addRoute( projection: fields, }); - const [channels, total] = await Promise.all([ - cursor.map((room) => this.composeRoomWithLastMessage(room, this.userId)).toArray(), - totalCount, - ]); + const [channels, total] = await Promise.all([cursor.toArray(), totalCount]); return API.v1.success({ - channels, + channels: channels.map((room) => this.composeRoomWithLastMessage(room, this.userId)), offset, count: channels.length, total, diff --git a/apps/meteor/app/api/server/v1/groups.js b/apps/meteor/app/api/server/v1/groups.js index 94a690be732a..6593effe5b72 100644 --- a/apps/meteor/app/api/server/v1/groups.js +++ b/apps/meteor/app/api/server/v1/groups.js @@ -592,13 +592,10 @@ API.v1.addRoute( projection: fields, }); - const [groups, total] = await Promise.all([ - cursor.map((room) => this.composeRoomWithLastMessage(room, this.userId)).toArray(), - totalCount, - ]); + const [groups, total] = await Promise.all([cursor.toArray(), totalCount]); return API.v1.success({ - groups, + groups: groups.map((room) => this.composeRoomWithLastMessage(room, this.userId)), offset, count: groups.length, total, @@ -626,13 +623,10 @@ API.v1.addRoute( projection: fields, }); - const [rooms, total] = await Promise.all([ - cursor.map((room) => this.composeRoomWithLastMessage(room, this.userId)).toArray(), - totalCount, - ]); + const [rooms, total] = await Promise.all([cursor.toArray(), totalCount]); return API.v1.success({ - groups: rooms, + groups: rooms.map((room) => this.composeRoomWithLastMessage(room, this.userId)), offset, count: rooms.length, total, diff --git a/apps/meteor/app/api/server/v1/im.ts b/apps/meteor/app/api/server/v1/im.ts index 509713cb289b..eb66fefd6723 100644 --- a/apps/meteor/app/api/server/v1/im.ts +++ b/apps/meteor/app/api/server/v1/im.ts @@ -429,7 +429,7 @@ API.v1.addRoute( // TODO: CACHE: Add Breaking notice since we removed the query param - const subscriptions = await Subscriptions.find({ 'u._id': this.userId, 't': 'd' }) + const subscriptions = await Subscriptions.find({ 'u._id': this.userId, 't': 'd' }, { projection: { rid: 1 } }) .map((item) => item.rid) .toArray(); @@ -443,13 +443,10 @@ API.v1.addRoute( }, ); - const [ims, total] = await Promise.all([ - cursor.map((room: IRoom) => this.composeRoomWithLastMessage(room, this.userId)).toArray(), - totalCount, - ]); + const [ims, total] = await Promise.all([cursor.toArray(), totalCount]); return API.v1.success({ - ims, + ims: ims.map((room: IRoom) => this.composeRoomWithLastMessage(room, this.userId)), offset, count: ims.length, total, @@ -480,13 +477,10 @@ API.v1.addRoute( }, ); - const [rooms, total] = await Promise.all([ - cursor.map((room: IRoom) => this.composeRoomWithLastMessage(room, this.userId)).toArray(), - totalCount, - ]); + const [rooms, total] = await Promise.all([cursor.toArray(), totalCount]); return API.v1.success({ - ims: rooms, + ims: rooms.map((room: IRoom) => this.composeRoomWithLastMessage(room, this.userId)), offset, count: rooms.length, total, diff --git a/apps/meteor/server/startup/serverRunning.js b/apps/meteor/server/startup/serverRunning.js index b9927895e258..1cd991f7c5e4 100644 --- a/apps/meteor/server/startup/serverRunning.js +++ b/apps/meteor/server/startup/serverRunning.js @@ -20,6 +20,8 @@ const exitIfNotBypassed = (ignore, errorCode = 1) => { process.exit(errorCode); }; +const skipMongoDbDeprecationCheck = ['yes', 'true'].includes(String(process.env.SKIP_MONGODEPRECATION_CHECK).toLowerCase()); + Meteor.startup(function () { const { oplogEnabled, mongoVersion, mongoStorageEngine } = getMongoInfo(); @@ -82,7 +84,7 @@ Meteor.startup(function () { showSuccessBox('SERVER RUNNING', msg); // Deprecation - if (!semver.satisfies(semver.coerce(mongoVersion), '>=4.4.0')) { + if (!skipMongoDbDeprecationCheck && !semver.satisfies(semver.coerce(mongoVersion), '>=4.4.0')) { msg = [ `YOUR CURRENT MONGODB VERSION (${mongoVersion}) IS DEPRECATED.`, 'IT WILL NOT BE SUPPORTED ON ROCKET.CHAT VERSION 6.0.0 AND GREATER,', diff --git a/apps/meteor/tests/end-to-end/api/02-channels.js b/apps/meteor/tests/end-to-end/api/02-channels.js index 02f156338c7b..e9dffd8d372b 100644 --- a/apps/meteor/tests/end-to-end/api/02-channels.js +++ b/apps/meteor/tests/end-to-end/api/02-channels.js @@ -2013,4 +2013,92 @@ describe('[Channels]', function () { return expect(channel.usersCount).to.be.equals(3); }); }); + + context("Setting: 'Use Real Name': true", () => { + before(async () => { + await updateSetting('UI_Use_Real_Name', true); + + await request + .post(api('channels.join')) + .set(credentials) + .send({ + roomId: channel._id, + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.nested.property('channel._id', channel._id); + }); + + await request + .post(api('chat.sendMessage')) + .set(credentials) + .send({ + message: { + text: 'Sample message', + rid: channel._id, + }, + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + }); + }); + after(async () => { + await updateSetting('UI_Use_Real_Name', false); + + await request + .post(api('channels.leave')) + .set(credentials) + .send({ + roomId: channel._id, + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.nested.property('channel._id', channel._id); + }); + }); + + it('/channels.list', (done) => { + request + .get(api('channels.list')) + .set(credentials) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('count'); + expect(res.body).to.have.property('total'); + expect(res.body).to.have.property('channels').and.to.be.an('array'); + + const retChannel = res.body.channels.find(({ _id }) => _id === channel._id); + + expect(retChannel).to.have.nested.property('lastMessage.u.name', 'RocketChat Internal Admin Test'); + }) + .end(done); + }); + + it('/channels.list.joined', (done) => { + request + .get(api('channels.list.joined')) + .set(credentials) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('count'); + expect(res.body).to.have.property('total'); + expect(res.body).to.have.property('channels').and.to.be.an('array'); + + const retChannel = res.body.channels.find(({ _id }) => _id === channel._id); + + expect(retChannel).to.have.nested.property('lastMessage.u.name', 'RocketChat Internal Admin Test'); + }) + .end(done); + }); + }); }); diff --git a/apps/meteor/tests/end-to-end/api/03-groups.js b/apps/meteor/tests/end-to-end/api/03-groups.js index 3e5bd508dacb..d28e4e31ed51 100644 --- a/apps/meteor/tests/end-to-end/api/03-groups.js +++ b/apps/meteor/tests/end-to-end/api/03-groups.js @@ -639,15 +639,13 @@ describe('[Groups]', function () { request .get(api('groups.list')) .set(credentials) - .query({ - roomId: group._id, - }) .expect('Content-Type', 'application/json') .expect(200) .expect((res) => { expect(res.body).to.have.property('success', true); expect(res.body).to.have.property('count'); expect(res.body).to.have.property('total'); + expect(res.body).to.have.property('groups').and.to.be.an('array'); }) .end(done); }); @@ -1618,4 +1616,88 @@ describe('[Groups]', function () { .end(done); }); }); + + context("Setting: 'Use Real Name': true", () => { + let realNameGroup; + + before(async () => { + await updateSetting('UI_Use_Real_Name', true); + + await request + .post(api('groups.create')) + .set(credentials) + .send({ name: `group-${Date.now()}` }) + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + + realNameGroup = res.body.group; + }); + + await request + .post(api('chat.sendMessage')) + .set(credentials) + .send({ + message: { + text: 'Sample message', + rid: realNameGroup._id, + }, + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + }); + }); + after(async () => { + await updateSetting('UI_Use_Real_Name', false); + + await request + .post(api('groups.delete')) + .set(credentials) + .send({ roomId: realNameGroup._id }) + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + }); + }); + + it('/groups.list', (done) => { + request + .get(api('groups.list')) + .set(credentials) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('count'); + expect(res.body).to.have.property('total'); + expect(res.body).to.have.property('groups').and.to.be.an('array'); + + const retGroup = res.body.groups.find(({ _id }) => _id === realNameGroup._id); + + expect(retGroup).to.have.nested.property('lastMessage.u.name', 'RocketChat Internal Admin Test'); + }) + .end(done); + }); + + it('/groups.listAll', (done) => { + request + .get(api('groups.listAll')) + .set(credentials) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('count'); + expect(res.body).to.have.property('total'); + expect(res.body).to.have.property('groups').and.to.be.an('array'); + + const retGroup = res.body.groups.find(({ _id }) => _id === realNameGroup._id); + + expect(retGroup).to.have.nested.property('lastMessage.u.name', 'RocketChat Internal Admin Test'); + }) + .end(done); + }); + }); }); diff --git a/apps/meteor/tests/end-to-end/api/04-direct-message.js b/apps/meteor/tests/end-to-end/api/04-direct-message.js index cc041ee030eb..ac0923f6b1f5 100644 --- a/apps/meteor/tests/end-to-end/api/04-direct-message.js +++ b/apps/meteor/tests/end-to-end/api/04-direct-message.js @@ -229,6 +229,70 @@ describe('[Direct Messages]', function () { .end(done); }); + context("Setting: 'Use Real Name': true", () => { + before(async () => updateSetting('UI_Use_Real_Name', true)); + after(async () => updateSetting('UI_Use_Real_Name', false)); + + it('/im.list', (done) => { + request + .get(api('im.list')) + .set(credentials) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('count', 1); + expect(res.body).to.have.property('total', 1); + expect(res.body).to.have.property('ims').and.to.be.an('array'); + + const im = res.body.ims[0]; + + expect(im).to.have.property('_id'); + expect(im).to.have.property('t').and.to.be.eq('d'); + expect(im).to.have.property('msgs').and.to.be.a('number'); + expect(im).to.have.property('usernames').and.to.be.an('array'); + expect(im).to.have.property('lm'); + expect(im).to.have.property('_updatedAt'); + expect(im).to.have.property('ts'); + expect(im).to.have.property('lastMessage'); + + const { lastMessage } = im; + + expect(lastMessage).to.have.nested.property('u.name', 'RocketChat Internal Admin Test'); + }) + .end(done); + }); + + it('/im.list.everyone', (done) => { + request + .get(api('im.list.everyone')) + .set(credentials) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('count', 1); + expect(res.body).to.have.property('total', 1); + expect(res.body).to.have.property('ims').and.to.be.an('array'); + const im = res.body.ims[0]; + expect(im).to.have.property('_id'); + expect(im).to.have.property('t').and.to.be.eq('d'); + expect(im).to.have.property('msgs').and.to.be.a('number'); + expect(im).to.have.property('usernames').and.to.be.an('array'); + expect(im).to.have.property('ro'); + expect(im).to.have.property('sysMes'); + expect(im).to.have.property('_updatedAt'); + expect(im).to.have.property('ts'); + expect(im).to.have.property('lastMessage'); + + const { lastMessage } = im; + + expect(lastMessage).to.have.nested.property('u.name', 'RocketChat Internal Admin Test'); + }) + .end(done); + }); + }); + it('/im.open', (done) => { request .post(api('im.open'))