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] New API Endpoints for the new version of JS SDK #12623

Merged
merged 8 commits into from
Nov 16, 2018
21 changes: 21 additions & 0 deletions packages/rocketchat-api/server/v1/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,24 @@ RocketChat.API.v1.addRoute('rooms.cleanHistory', { authRequired: true }, {
},
});

RocketChat.API.v1.addRoute('rooms.info', { authRequired: true }, {
get() {
const room = findRoomByIdOrName({ params: this.requestParams() });
const { fields } = this.parseJsonQuery();
if (!Meteor.call('canAccessRoom', room._id, this.userId, {})) {
return RocketChat.API.v1.failure('not-allowed', 'Not Allowed');
}
return RocketChat.API.v1.success({ room: RocketChat.models.Rooms.findOneByIdOrName(room._id, { fields }) });
},
});

RocketChat.API.v1.addRoute('rooms.leave', { authRequired: true }, {
post() {
const room = findRoomByIdOrName({ params: this.bodyParams });
Meteor.runAsUser(this.userId, () => {
Meteor.call('leaveRoom', room._id);
});

return RocketChat.API.v1.success();
},
});
10 changes: 10 additions & 0 deletions tests/data/permissions.helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { api, credentials, request } from './api-data';

export const updatePermission = (permission, roles) => new Promise((resolve) => {
request.post(api('permissions.update'))
.set(credentials)
.send({ permissions: [{ _id: permission, roles }] })
.expect('Content-Type', 'application/json')
.expect(200)
.end(resolve);
});
44 changes: 44 additions & 0 deletions tests/data/rooms.helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { api, credentials, request } from './api-data';

export const createRoom = ({ name, type, username }) => {
if (!type) {
throw new Error('"type" is required in "createRoom" test helper');
}
if (type === 'd' && !username) {
throw new Error('To be able to create DM Room, you must provide the username');
}
const endpoints = {
c: 'channels.create',
p: 'groups.create',
d: 'im.create',
};
const params = type === 'd'
? ({ username })
: ({ name });

return request.post(api(endpoints[type]))
.set(credentials)
.send(params);
};

export const closeRoom = ({ type, roomId }) => {
if (!type) {
throw new Error('"type" is required in "closeRoom" test helper');
}
if (!roomId) {
throw new Error('"roomId" is required in "closeRoom" test helper');
}
const endpoints = {
c: 'channels.close',
p: 'groups.close',
d: 'im.close',
};
return new Promise((resolve) => {
request.post(api(endpoints[type]))
.set(credentials)
.send({
roomId,
})
.end(resolve);
});
};
Loading