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] API to fetch permissions & user roles #9519

Merged
merged 6 commits into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/rocketchat-api/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Package.onUse(function(api) {
api.addFiles('server/v1/im.js', 'server');
api.addFiles('server/v1/integrations.js', 'server');
api.addFiles('server/v1/misc.js', 'server');
api.addFiles('server/v1/permissions.js', 'server');
api.addFiles('server/v1/push.js', 'server');
api.addFiles('server/v1/settings.js', 'server');
api.addFiles('server/v1/stats.js', 'server');
Expand Down
17 changes: 17 additions & 0 deletions packages/rocketchat-api/server/v1/permissions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
This API returns all permissions that exists
on the server, with respective roles.

Method: GET
Route: api/v1/permissions
*/
RocketChat.API.v1.addRoute('permissions', { authRequired: true }, {
get() {
let result;
Meteor.runAsUser(this.userId, () =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarcosSpessatto could you change this to

const result = Meteor.runAsUser(this.userId, () => Meteor.call('permissions/get'));

Meteor.runAsUser returns the result of the passed function.

result = Meteor.call('permissions/get')
);

return RocketChat.API.v1.success(result);
}
});
24 changes: 24 additions & 0 deletions packages/rocketchat-api/server/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,27 @@ RocketChat.API.v1.addRoute('users.createToken', { authRequired: true }, {
return data ? RocketChat.API.v1.success({data}) : RocketChat.API.v1.unauthorized();
}
});

/**
This API returns the logged user roles.

Method: GET
Route: api/v1/user.roles
*/
RocketChat.API.v1.addRoute('user.roles', { authRequired: true }, {
get() {
let result;
let currentUserRoles = {};

Meteor.runAsUser(this.userId, () =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

result = Meteor.call('getUserRoles')
);

if (Array.isArray(result) && result.length > 0) {
currentUserRoles = result[0];
}

return RocketChat.API.v1.success(currentUserRoles);
}
});