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

Convert rocketchat-authorization to main module structure #12523

Merged
merged 3 commits into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion packages/rocketchat-authorization/client/hasPermission.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* globals ChatPermissions */
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { RocketChat } from 'meteor/rocketchat:lib';
import { ChatPermissions } from './lib/ChatPermissions';

function atLeastOne(permissions = [], scope) {
return permissions.some((permissionId) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-authorization/client/hasRole.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RocketChat } from 'meteor/rocketchat:lib';

RocketChat.authz.hasRole = function(userId, roleNames, scope) {
roleNames = [].concat(roleNames);
return RocketChat.models.Roles.isUserInRoles(userId, roleNames, scope);
Expand Down
14 changes: 14 additions & 0 deletions packages/rocketchat-authorization/client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import './stylesheets/permissions.css';
import '../lib/rocketchat';
import './lib/models/Roles';
import './lib/models/Users';
import './lib/models/Subscriptions';
import './hasPermission';
import './hasRole';
import './usersNameChanged';
import './route';
import './startup';
import './views/permissions.html';
import './views/permissions';
import './views/permissionsRole.html';
import './views/permissionsRole';
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { RocketChat } from 'meteor/rocketchat:lib';

RocketChat.authz.cachedCollection = new RocketChat.CachedCollection({
name: 'permissions',
eventType: 'onLogged',
});

this.ChatPermissions = RocketChat.authz.cachedCollection.collection;
export const ChatPermissions = RocketChat.authz.cachedCollection.collection;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Mongo } from 'meteor/mongo';
import { RocketChat } from 'meteor/rocketchat:lib';

RocketChat.models.Roles = new Mongo.Collection('rocketchat_roles');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RocketChat } from 'meteor/rocketchat:lib';
import _ from 'underscore';

if (_.isUndefined(RocketChat.models.Subscriptions)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RocketChat } from 'meteor/rocketchat:lib';
import _ from 'underscore';

if (_.isUndefined(RocketChat.models.Users)) {
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-authorization/client/route.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FlowRouter } from 'meteor/kadira:flow-router';
import { BlazeLayout } from 'meteor/kadira:blaze-layout';
import { t } from 'meteor/rocketchat:ui';

FlowRouter.route('/admin/permissions', {
name: 'admin-permissions',
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-authorization/client/startup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';

RocketChat.CachedCollectionManager.onLogin(() => {
Meteor.subscribe('roles');
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-authorization/client/usersNameChanged.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* globals RoomRoles */
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import { RoomRoles } from 'meteor/rocketchat:ui';

Meteor.startup(function() {
RocketChat.Notifications.onLogged('Users:NameChanged', function({ _id, name }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* globals ChatPermissions */
import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import { Tracker } from 'meteor/tracker';
import { Template } from 'meteor/templating';
import { RocketChat } from 'meteor/rocketchat:lib';
import { ChatPermissions } from '../lib/ChatPermissions';

Template.permissions.helpers({
role() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { Template } from 'meteor/templating';
import { t, modal } from 'meteor/rocketchat:ui';
import { RocketChat, handleError } from 'meteor/rocketchat:lib';

import toastr from 'toastr';

Template.permissionsRole.helpers({
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-authorization/lib/rocketchat.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
import { RocketChat } from 'meteor/rocketchat:lib';

RocketChat.authz = {};
70 changes: 10 additions & 60 deletions packages/rocketchat-authorization/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,15 @@ Package.onUse(function(api) {
api.use([
'ecmascript',
'rocketchat:lib',
'mongo',
]);

api.use('mongo', ['client', 'server']);
api.use('kadira:flow-router', 'client');
api.use('kadira:blaze-layout', 'client');
api.use('tracker', 'client');

api.use('templating', 'client');

api.addFiles('lib/rocketchat.js', ['server', 'client']);

api.addFiles('client/lib/ChatPermissions.js', ['client']);
api.addFiles('client/lib/models/Roles.js', ['client']);
api.addFiles('client/lib/models/Users.js', ['client']);
api.addFiles('client/lib/models/Subscriptions.js', ['client']);

api.addFiles('client/startup.js', ['client']);
api.addFiles('client/hasPermission.js', ['client']);
api.addFiles('client/hasRole.js', ['client']);
api.addFiles('client/requiresPermission.html', ['client']);

api.addFiles('client/route.js', ['client']);
api.addFiles('client/usersNameChanged.js', ['client']);

// views
api.addFiles('client/views/permissions.html', ['client']);
api.addFiles('client/views/permissions.js', ['client']);
api.addFiles('client/views/permissionsRole.html', ['client']);
api.addFiles('client/views/permissionsRole.js', ['client']);

// stylesheets
api.addFiles('client/stylesheets/permissions.css', 'client');

api.addFiles('server/models/Permissions.js', ['server']);
api.addFiles('server/models/Roles.js', ['server']);
api.addFiles('server/models/Base.js', ['server']);
api.addFiles('server/models/Users.js', ['server']);
api.addFiles('server/models/Subscriptions.js', ['server']);

api.addFiles('server/functions/addUserRoles.js', ['server']);
api.addFiles('server/functions/canAccessRoom.js', ['server']);
api.addFiles('server/functions/getRoles.js', ['server']);
api.addFiles('server/functions/getUsersInRole.js', ['server']);
api.addFiles('server/functions/hasPermission.js', ['server']);
api.addFiles('server/functions/hasRole.js', ['server']);
api.addFiles('server/functions/removeUserFromRoles.js', ['server']);

// publications
api.addFiles('server/publications/permissions.js', 'server');
api.addFiles('server/publications/roles.js', 'server');
api.addFiles('server/publications/usersInRole.js', 'server');

// methods
api.addFiles('server/methods/addUserToRole.js', 'server');
api.addFiles('server/methods/deleteRole.js', 'server');
api.addFiles('server/methods/removeUserFromRole.js', 'server');
api.addFiles('server/methods/saveRole.js', 'server');
api.addFiles('server/methods/addPermissionToRole.js', 'server');
api.addFiles('server/methods/removeRoleFromPermission.js', 'server');

api.addFiles('server/startup.js', ['server']);
api.use([
'templating',
'tracker',
'kadira:flow-router',
'kadira:blaze-layout',
], 'client');

api.mainModule('client/index.js', 'client');
api.mainModule('server/index.js', 'server');
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import _ from 'underscore';

RocketChat.authz.addUserRoles = function(userId, roleNames, scope) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RocketChat } from 'meteor/rocketchat:lib';

RocketChat.authz.getRoles = function() {
return RocketChat.models.Roles.find().fetch();
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RocketChat } from 'meteor/rocketchat:lib';

RocketChat.authz.getUsersInRole = function(roleName, scope, options) {
return RocketChat.models.Roles.findUsersInRole(roleName, scope, options);
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RocketChat } from 'meteor/rocketchat:lib';

function atLeastOne(userId, permissions = [], scope) {
return permissions.some((permissionId) => {
const permission = RocketChat.models.Permissions.findOne(permissionId);
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-authorization/server/functions/hasRole.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RocketChat } from 'meteor/rocketchat:lib';

RocketChat.authz.hasRole = function(userId, roleNames, scope) {
roleNames = [].concat(roleNames);
return RocketChat.models.Roles.isUserInRoles(userId, roleNames, scope);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import _ from 'underscore';

RocketChat.authz.removeUserFromRoles = function(userId, roleNames, scope) {
Expand Down
24 changes: 24 additions & 0 deletions packages/rocketchat-authorization/server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import '../lib/rocketchat';
import './models/Base';
import './models/Permissions';
import './models/Roles';
import './models/Subscriptions';
import './models/Users';
import './functions/addUserRoles';
import './functions/canAccessRoom';
import './functions/getRoles';
import './functions/getUsersInRole';
import './functions/hasPermission';
import './functions/hasRole';
import './functions/removeUserFromRoles';
import './functions/removeUserFromRoles';
import './methods/addPermissionToRole';
import './methods/addUserToRole';
import './methods/deleteRole';
import './methods/removeRoleFromPermission';
import './methods/removeUserFromRole';
import './methods/saveRole';
import './publications/permissions';
import './publications/roles';
import './publications/usersInRole';
import './startup';
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';

Meteor.methods({
'authorization:addPermissionToRole'(permission, role) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import _ from 'underscore';

Meteor.methods({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';

Meteor.methods({
'authorization:deleteRole'(roleName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';

Meteor.methods({
'authorization:removeRoleFromPermission'(permission, role) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import _ from 'underscore';

Meteor.methods({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';

Meteor.methods({
'authorization:saveRole'(roleData) {
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-authorization/server/models/Base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import _ from 'underscore';

RocketChat.models._Base.prototype.roleBaseQuery = function(/* userId, scope*/) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RocketChat } from 'meteor/rocketchat:lib';

class ModelPermissions extends RocketChat.models._Base {
constructor(...args) {
super(...args);
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-authorization/server/models/Roles.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RocketChat } from 'meteor/rocketchat:lib';

class ModelRoles extends RocketChat.models._Base {
constructor(...args) {
super(...args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RocketChat } from 'meteor/rocketchat:lib';
import _ from 'underscore';

RocketChat.models.Subscriptions.roleBaseQuery = function(userId, scope) {
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-authorization/server/models/Users.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RocketChat } from 'meteor/rocketchat:lib';

RocketChat.models.Users.roleBaseQuery = function(userId) {
return { _id: userId };
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';

Meteor.methods({
'permissions/get'(updatedAt) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';

Meteor.publish('roles', function() {
if (!this.userId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';

Meteor.publish('usersInRole', function(roleName, scope, limit = 50) {
if (!this.userId) {
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-authorization/server/startup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint no-multi-spaces: 0 */
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';

Meteor.startup(function() {
// Note:
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-ui/client/lib/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ChatRoom = this.CachedChatRoom.collection;
this.CachedChatSubscription = new RocketChat.CachedCollection({ name: 'subscriptions' });
this.ChatSubscription = this.CachedChatSubscription.collection;
this.UserRoles = new Mongo.Collection(null);
this.RoomRoles = new Mongo.Collection(null);
RoomRoles = new Mongo.Collection(null); //eslint-disable-line
this.UserAndRoom = new Mongo.Collection(null);
this.CachedChannelList = new Mongo.Collection(null);
this.CachedUserList = new Mongo.Collection(null);
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-ui/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,5 @@ Package.onUse(function(api) {
api.export('modal', 'client');
api.export('fireGlobalEvent', 'client');
api.export('ChatRoom', 'client');
api.export('RoomRoles', 'client');
});