Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Remove thumbnails from channels.files response #27022

Closed
wants to merge 9 commits into from
14 changes: 13 additions & 1 deletion apps/meteor/app/api/server/v1/channels.js
Expand Up @@ -285,7 +285,19 @@ API.v1.addRoute(
const { offset, count } = this.getPaginationItems();
const { sort, fields, query } = this.parseJsonQuery();

const ourQuery = Object.assign({}, query, { rid: findResult._id });
const thumbnailFilters = {
...(!query.typeGroup && { typeGroup: { $nin: ['thumbnail'] } }),
name: { ...query.name, $not: /thumb-/ },
};

const ourQuery = Object.assign(
{},
query,
{
rid: findResult._id,
},
thumbnailFilters,
);

const { cursor, totalCount } = Uploads.findPaginated(ourQuery, {
sort: sort || { name: 1 },
Expand Down
14 changes: 13 additions & 1 deletion apps/meteor/app/api/server/v1/groups.js
Expand Up @@ -344,7 +344,19 @@ API.v1.addRoute(
const { offset, count } = this.getPaginationItems();
const { sort, fields, query } = this.parseJsonQuery();

const ourQuery = Object.assign({}, query, { rid: findResult.rid });
const thumbnailFilters = {
...(!query.typeGroup && { typeGroup: { $nin: ['thumbnail'] } }),
name: { ...query.name, $not: /thumb-/ },
};

const ourQuery = Object.assign(
{},
query,
{
rid: findResult.rid,
},
thumbnailFilters,
);

const { cursor, totalCount } = Uploads.findPaginated(ourQuery, {
sort: sort || { name: 1 },
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/app/file-upload/server/lib/FileUpload.js
Expand Up @@ -327,6 +327,7 @@ export const FileUpload = {
name: `thumb-${file.name}`,
size: buffer.length,
type: file.type,
typeGroup: 'thumbnail',
rid,
userId,
};
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/server/startup/migrations/index.ts
Expand Up @@ -40,4 +40,5 @@ import './v278';
import './v279';
import './v280';
import './v281';
import './v282';
import './xrun';
24 changes: 24 additions & 0 deletions apps/meteor/server/startup/migrations/v282.ts
@@ -0,0 +1,24 @@
import { Uploads } from '@rocket.chat/models';

import { addMigration } from '../../lib/migrations';

addMigration({
version: 282,
async up() {
await Uploads.updateMany(
{
name: {
$regex: 'thumb-',
},
typeGroup: {
$exists: false,
},
},
{
$set: {
typeGroup: 'thumbnail',
},
},
);
},
});
38 changes: 38 additions & 0 deletions apps/meteor/tests/end-to-end/api/02-channels.js
Expand Up @@ -7,6 +7,7 @@ import { updatePermission, updateSetting } from '../../data/permissions.helper';
import { createRoom } from '../../data/rooms.helper';
import { createVisitor } from '../../data/livechat/rooms';
import { createIntegration, removeIntegration } from '../../data/integration.helper';
import { imgURL } from '../../data/interactions.js';

function getRoomInfo(roomId) {
return new Promise((resolve /* , reject*/) => {
Expand Down Expand Up @@ -303,6 +304,25 @@ describe('[Channels]', function () {

describe('[/channels.files]', () => {
before(() => updateSetting('VoIP_Enabled', true));

before((done) => {
request
.post(api(`rooms.upload/${channel._id}`))
.set(credentials)
.attach('file', imgURL)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
const { message } = res.body;
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.nested.property('message._id', message._id);
expect(res.body).to.have.nested.property('message.rid', channel._id);
expect(res.body).to.have.nested.property('message.file._id', message.file._id);
expect(res.body).to.have.nested.property('message.file.type', message.file.type);
expect(res.body).to.have.nested.property('message.file.name', message.file.name);
})
.end(done);
});
const createVoipRoom = async () => {
const testUser = await createUser({ roles: ['user', 'livechat-agent'] });
const testUserCredentials = await login(testUser.username, password);
Expand Down Expand Up @@ -363,6 +383,24 @@ describe('[Channels]', function () {
.end(done);
});

it('should not list thumbnails when listing by room id', (done) => {
request
.get(api('channels.files'))
.set(credentials)
.query({
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.property('files').and.to.be.an('array');
const thumbnails = res.body.files.filter((f) => f.typeGroup === 'thumbnail');
expect(thumbnails.length).to.be.eq(0);
})
.end(done);
});

it('should succeed when searching by roomId even requested with count and offset params', (done) => {
request
.get(api('channels.files'))
Expand Down