[NEW] Add /api/v1/channels.roles & /api/v1/groups.roles (#10607)

[NEW] Add REST endpoints `channels.roles` & `groups.roles`
pull/10741/head
Matheus Cardoso 7 years ago committed by Rodrigo Nascimento
parent e8054b943d
commit 4e9f0250dd
  1. 11
      packages/rocketchat-api/server/v1/channels.js
  2. 12
      packages/rocketchat-api/server/v1/groups.js
  3. 70
      tests/end-to-end/api/02-channels.js
  4. 70
      tests/end-to-end/api/03-groups.js

@ -866,3 +866,14 @@ RocketChat.API.v1.addRoute('channels.getAllUserMentionsByChannel', { authRequire
}
});
RocketChat.API.v1.addRoute('channels.roles', { authRequired: true }, {
get() {
const findResult = findChannelByIdOrName({ params: this.requestParams() });
const roles = Meteor.runAsUser(this.userId, () => Meteor.call('getRoomRoles', findResult._id));
return RocketChat.API.v1.success({
roles
});
}
});

@ -649,3 +649,15 @@ RocketChat.API.v1.addRoute('groups.unarchive', { authRequired: true }, {
return RocketChat.API.v1.success();
}
});
RocketChat.API.v1.addRoute('groups.roles', { authRequired: true }, {
get() {
const findResult = findPrivateGroupByIdOrName({ params: this.requestParams(), userId: this.userId });
const roles = Meteor.runAsUser(this.userId, () => Meteor.call('getRoomRoles', findResult.rid));
return RocketChat.API.v1.success({
roles
});
}
});

@ -627,4 +627,74 @@ describe('[Channels]', function() {
.end(done);
});
});
describe('/channels.roles', () => {
let testChannel;
it('/channels.create', (done) => {
request.post(api('channels.create'))
.set(credentials)
.send({
name: `channel.roles.test.${ Date.now() }`
})
.end((err, res) => {
testChannel = res.body.channel;
done();
});
});
it('/channels.invite', async(done) => {
request.post(api('channels.invite'))
.set(credentials)
.send({
roomId: testChannel._id,
userId: 'rocket.cat'
})
.end(done);
});
it('/channels.addModerator', (done) => {
request.post(api('channels.addModerator'))
.set(credentials)
.send({
roomId: testChannel._id,
userId: 'rocket.cat'
})
.end(done);
});
it('/channels.addLeader', (done) => {
request.post(api('channels.addLeader'))
.set(credentials)
.send({
roomId: testChannel._id,
userId: 'rocket.cat'
})
.end(done);
});
it('should return an array of role <-> user relationships in a channel', (done) => {
request.get(api('channels.roles'))
.set(credentials)
.query({
roomId: testChannel._id
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.a.property('success', true);
expect(res.body).to.have.a.property('roles').that.is.an('array').that.has.lengthOf(2);
expect(res.body.roles[0]).to.have.a.property('_id').that.is.a('string');
expect(res.body.roles[0]).to.have.a.property('rid').that.is.equal(testChannel._id);
expect(res.body.roles[0]).to.have.a.property('roles').that.is.an('array').that.includes('moderator', 'leader');
expect(res.body.roles[0]).to.have.a.property('u').that.is.an('object');
expect(res.body.roles[0].u).to.have.a.property('_id').that.is.a('string');
expect(res.body.roles[0].u).to.have.a.property('username').that.is.a('string');
expect(res.body.roles[1]).to.have.a.property('_id').that.is.a('string');
expect(res.body.roles[1]).to.have.a.property('rid').that.is.equal(testChannel._id);
expect(res.body.roles[1]).to.have.a.property('roles').that.is.an('array').that.includes('owner');
expect(res.body.roles[1]).to.have.a.property('u').that.is.an('object');
expect(res.body.roles[1].u).to.have.a.property('_id').that.is.a('string');
expect(res.body.roles[1].u).to.have.a.property('username').that.is.a('string');
})
.end(done);
});
});
});

@ -465,4 +465,74 @@ describe('groups', function() {
.end(done);
});
});
describe('/groups.roles', () => {
let testGroup;
it('/groups.create', (done) => {
request.post(api('groups.create'))
.set(credentials)
.send({
name: `group.roles.test.${ Date.now() }`
})
.end((err, res) => {
testGroup = res.body.group;
done();
});
});
it('/groups.invite', async(done) => {
request.post(api('groups.invite'))
.set(credentials)
.send({
roomId: testGroup._id,
userId: 'rocket.cat'
})
.end(done);
});
it('/groups.addModerator', (done) => {
request.post(api('groups.addModerator'))
.set(credentials)
.send({
roomId: testGroup._id,
userId: 'rocket.cat'
})
.end(done);
});
it('/groups.addLeader', (done) => {
request.post(api('groups.addLeader'))
.set(credentials)
.send({
roomId: testGroup._id,
userId: 'rocket.cat'
})
.end(done);
});
it('should return an array of roles <-> user relationships in a private group', (done) => {
request.get(api('groups.roles'))
.set(credentials)
.query({
roomId: testGroup._id
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.a.property('success', true);
expect(res.body).to.have.a.property('roles').that.is.an('array').that.has.lengthOf(2);
expect(res.body.roles[0]).to.have.a.property('_id').that.is.a('string');
expect(res.body.roles[0]).to.have.a.property('rid').that.is.equal(testGroup._id);
expect(res.body.roles[0]).to.have.a.property('roles').that.is.an('array').that.includes('moderator', 'leader');
expect(res.body.roles[0]).to.have.a.property('u').that.is.an('object');
expect(res.body.roles[0].u).to.have.a.property('_id').that.is.a('string');
expect(res.body.roles[0].u).to.have.a.property('username').that.is.a('string');
expect(res.body.roles[1]).to.have.a.property('_id').that.is.a('string');
expect(res.body.roles[1]).to.have.a.property('rid').that.is.equal(testGroup._id);
expect(res.body.roles[1]).to.have.a.property('roles').that.is.an('array').that.includes('owner');
expect(res.body.roles[1]).to.have.a.property('u').that.is.an('object');
expect(res.body.roles[1].u).to.have.a.property('_id').that.is.a('string');
expect(res.body.roles[1].u).to.have.a.property('username').that.is.a('string');
})
.end(done);
});
});
});

Loading…
Cancel
Save