[NEW][API] Endpoint `groups.setEncrypted` (#13477)

pull/14697/head
Montel Laurent 6 years ago committed by GitHub
parent ee85880e0e
commit 7c22f5d321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      app/api/server/v1/groups.js
  2. 78
      tests/end-to-end/api/03-groups.js

@ -1,5 +1,6 @@
import _ from 'underscore';
import { Meteor } from 'meteor/meteor';
import { Match } from 'meteor/check';
import { mountIntegrationQueryBasedOnPermissions } from '../../../integrations/server/lib/mountQueriesBasedOnPermission';
import { Subscriptions, Rooms, Messages, Uploads, Integrations, Users } from '../../../models/server';
@ -819,3 +820,19 @@ API.v1.addRoute('groups.moderators', { authRequired: true }, {
});
},
});
API.v1.addRoute('groups.setEncrypted', { authRequired: true }, {
post() {
if (!Match.test(this.bodyParams, Match.ObjectIncluding({ encrypted: Boolean }))) {
return API.v1.failure('The bodyParam "encrypted" is required');
}
const findResult = findPrivateGroupByIdOrName({ params: this.requestParams(), userId: this.userId });
Meteor.call('saveRoomSettings', findResult.rid, 'encrypted', this.bodyParams.encrypted);
return API.v1.success({
group: this.composeRoomWithLastMessage(Rooms.findOneById(findResult.rid, { fields: API.v1.defaultFieldsToExclude }), this.userId),
});
},
});

@ -1099,4 +1099,82 @@ describe('[Groups]', function() {
.end(done);
});
});
describe('/groups.setEncrypted', () => {
let testGroup;
it('/groups.create', (done) => {
request.post(api('groups.create'))
.set(credentials)
.send({
name: `group.encrypted.test.${ Date.now() }`,
})
.end((err, res) => {
testGroup = res.body.group;
done();
});
});
it('should return an error when passing no boolean param', (done) => {
request.post(api('groups.setEncrypted'))
.set(credentials)
.send({
roomId: testGroup._id,
encrypted: 'no-boolean',
})
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('error', 'The bodyParam "encrypted" is required');
})
.end(done);
});
it('should set group as encrypted correctly and return the new data', (done) => {
request.post(api('groups.setEncrypted'))
.set(credentials)
.send({
roomId: testGroup._id,
encrypted: true,
})
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('group');
expect(res.body.group).to.have.property('_id', testGroup._id);
expect(res.body.group).to.have.property('encrypted', true);
})
.end(done);
});
it('should return the updated room encrypted', async () => {
const roomInfo = await getRoomInfo(testGroup._id);
expect(roomInfo).to.have.a.property('success', true);
expect(roomInfo.group).to.have.a.property('_id', testGroup._id);
expect(roomInfo.group).to.have.a.property('encrypted', true);
});
it('should set group as unencrypted correctly and return the new data', (done) => {
request.post(api('groups.setEncrypted'))
.set(credentials)
.send({
roomId: testGroup._id,
encrypted: false,
})
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('group');
expect(res.body.group).to.have.property('_id', testGroup._id);
expect(res.body.group).to.have.property('encrypted', false);
})
.end(done);
});
it('should return the updated room unencrypted', async () => {
const roomInfo = await getRoomInfo(testGroup._id);
expect(roomInfo).to.have.a.property('success', true);
expect(roomInfo.group).to.have.a.property('_id', testGroup._id);
expect(roomInfo.group).to.have.a.property('encrypted', false);
});
});
});

Loading…
Cancel
Save