Skip to content
Snippets Groups Projects
Commit 733f7ea4 authored by Diego Sampaio's avatar Diego Sampaio
Browse files

new apis for roomTypes

parent 400aaeee
No related branches found
No related tags found
No related merge requests found
Meteor.startup ->
roles = ['admin', 'moderator', 'user']
RocketChat.roomTypes.addType('starredRooms', roles);
RocketChat.roomTypes.addType('channels', roles);
RocketChat.roomTypes.addType('directMessages', roles);
RocketChat.roomTypes.addType('privateGroups', roles);
# RocketChat.roomTypes.addType('starredRooms', roles);
RocketChat.roomTypes.setIcon('c', 'icon-hash');
RocketChat.roomTypes.setIcon('d', 'icon-at');
RocketChat.roomTypes.setIcon('p', 'icon-lock');
RocketChat.roomTypes.add 'c',
template: 'channels'
icon: 'icon-hash'
route:
name: 'channel'
path: '/channel/:name'
action: (params, queryParams) ->
Session.set 'showUserInfo'
openRoom 'c', params.name
link: (sub) ->
return { name: sub.name }
permissions: [ 'view-c-room' ]
RocketChat.roomTypes.setRoute 'c', 'channel', (sub) ->
return { name: sub.name }
RocketChat.roomTypes.add 'd',
template: 'directMessages'
icon: 'icon-at'
route:
name: 'direct'
path: '/direct/:username'
action: (params, queryParams) ->
Session.set 'showUserInfo'
openRoom 'd', params.name
link: (sub) ->
return { username: sub.name }
permissions: [ 'view-d-room' ]
RocketChat.roomTypes.setRoute 'd', 'direct', (sub) ->
return { username: sub.name }
RocketChat.roomTypes.setRoute 'p', 'group', (sub) ->
return { name: sub.name }
RocketChat.roomTypes.add 'p',
template: 'privateGroups'
icon: 'icon-lock'
route:
name: 'group'
path: '/group/:name'
action: (params, queryParams) ->
Session.set 'showUserInfo'
openRoom 'p', params.name
link: (sub) ->
return { name: sub.name }
permissions: [ 'view-p-room' ]
......@@ -28,8 +28,7 @@ hasPermission = (permissions, scope=Roles.GLOBAL_GROUP, strategy) ->
unless RocketChat.authz.subscription.ready()
return false
unless _.isArray(permissions)
permissions = [permissions]
permissions = [].concat permissions
roleNames = Roles.getRolesForUser(userId, scope)
......
......@@ -9,3 +9,6 @@ RocketChat.models.Permissions = new class extends RocketChat.models._Base
roles: role
return @find query, options
createOrUpdate: (name, roles) ->
@upsert { _id: name }, { $set: { roles: roles } }
......@@ -77,6 +77,15 @@ Meteor.startup ->
{ _id: 'bulk-create-c',
roles : ['admin']}
{ _id: 'view-c-room',
roles : ['admin', 'site-moderator', 'user']}
{ _id: 'view-p-room',
roles : ['admin', 'site-moderator', 'user']}
{ _id: 'view-d-room',
roles : ['admin', 'site-moderator', 'user']}
]
#alanning:roles
......
RocketChat.roomTypes = new class
rooms = []
routes = {}
publishes = {}
icons = {}
roomTypesOrder = []
roomTypes = {}
### Adds a room type to app
@param identifier MUST BE equals to `db.rocketchat_room.t` field
@param config
template: template name to render on sideNav
permissions: list of permissions to see the sideNav template
icon: icon class
route:
name: route name
action: route action function
###
add = (identifier, config) ->
if roomTypes[identifier]?
throw new Meteor.Error 'identifier-already-set', t('Room_type_identifier_already_set')
# @TODO validate config options
roomTypesOrder.push identifier
roomTypes[identifier] = config
### Sets a route for a room type
@param roomType: room type (e.g.: c (for channels), d (for direct channels))
......@@ -39,7 +55,12 @@ RocketChat.roomTypes = new class
roles: [].concat roles
getAllTypes = ->
return rooms
typesPermitted = []
roomTypesOrder.forEach (type) ->
if roomTypes[type].permissions? and RocketChat.authz.hasAtLeastOnePermission roomTypes[type].permissions
typesPermitted.push roomTypes[type]
return typesPermitted
### add a publish for a room type
@param roomType: room type (e.g.: c (for channels), d (for direct channels))
......
Meteor.startup(function() {
RocketChat.roomTypes.addType('livechat', ['livechat-agent', 'livechat-manager']);
RocketChat.roomTypes.setIcon('l', 'icon-chat-empty');
RocketChat.roomTypes.setRoute('l', 'live', function(sub) {
return { name: sub.name };
RocketChat.roomTypes.add('l', {
template: 'livechat',
icon: 'icon-chat-empty',
route: {
name: 'live',
path: '/live/:name',
action: (params, queryParams) => {
Session.set('showUserInfo');
openRoom('l', params.name);
},
link: (sub) => {
return { name: sub.name }
}
},
permissions: [ 'view-l-room' ]
});
AccountBox.addOption({ name: 'Livechat', icon: 'icon-chat-empty', class: 'livechat-manager', roles: ['livechat-manager'] });
......
Meteor.startup(function() {
var i, j, len, len1, permission, ref, role, roles,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
var permissions = [
{
_id: 'receive-livechat',
roles : ['livechat-agent']
},
{
_id: 'edit-livechat-settings',
roles : ['livechat-manager']
}
];
roles = _.pluck(Roles.getAllRoles().fetch(), 'name');
for (i = 0, len = permissions.length; i < len; i++) {
permission = permissions[i];
RocketChat.models.Permissions.upsert(permission._id, {
$setOnInsert: permission
});
ref = permission.roles;
for (j = 0, len1 = ref.length; j < len1; j++) {
role = ref[j];
if (indexOf.call(roles, role) < 0) {
Roles.createRole(role);
roles.push(role);
}
}
Meteor.startup(() => {
if (RocketChat.models && RocketChat.models.Permissions) {
RocketChat.models.Permissions.createOrUpdate('view-l-room', ['livechat-agent', 'livechat-manager']);
}
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment