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

removed permission paremeter from roomTypes and accountBox

now it only on `condition` parameter which implements their
own logic, including checking for permission =)
parent 114aa950
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,8 @@ RocketChat.roomTypes.add 'c', 10,
openRoom 'c', params.name
link: (sub) ->
return { name: sub.name }
permissions: [ 'view-c-room' ]
condition: ->
return RocketChat.authz.hasAllPermission 'view-c-room'
RocketChat.roomTypes.add 'd', 20,
template: 'directMessages'
......@@ -26,7 +27,8 @@ RocketChat.roomTypes.add 'd', 20,
openRoom 'd', params.username
link: (sub) ->
return { username: sub.name }
permissions: [ 'view-d-room' ]
condition: ->
return RocketChat.authz.hasAllPermission 'view-d-room'
RocketChat.roomTypes.add 'p', 30,
template: 'privateGroups'
......@@ -39,4 +41,5 @@ RocketChat.roomTypes.add 'p', 30,
openRoom 'p', params.name
link: (sub) ->
return { name: sub.name }
permissions: [ 'view-p-room' ]
condition: ->
return RocketChat.authz.hasAllPermission 'view-p-room'
......@@ -66,7 +66,9 @@ RocketChat.roomTypes.add('l', 5, {
return { name: sub.name }
}
},
permissions: [ 'view-l-room' ]
condition: () => {
return RocketChat.authz.hasAllPermission('view-l-room');
}
});
```
......@@ -95,19 +97,9 @@ AccountBox.addItem({
name: 'Livechat',
icon: 'icon-chat-empty',
class: 'livechat-manager',
route: {
name: 'livechat-manager',
path: '/livechat-manager',
action(params, queryParams) {
Session.set('openedRoom');
BlazeLayout.render('main', {
center: 'page-container',
pageTitle: 'Live Chat Manager',
pageTemplate: 'livechat-manager'
});
}
},
permissions: ['view-livechat-manager']
condition: () => {
return RocketChat.authz.hasAllPermission('view-livechat-manager');
}
});
```
......
......@@ -3,23 +3,11 @@ RocketChat.roomTypes = new class
roomTypes = {}
mainOrder = 1
protectedAction = (item) ->
# if not item.permissions? or RocketChat.authz.hasAtLeastOnePermission item.permissions
return item.route.action
# return ->
# BlazeLayout.render 'main',
# center: 'pageContainer'
# # @TODO text Not_authorized don't get the correct language
# pageTitle: t('Not_authorized')
# pageTemplate: 'notAuthorized'
### Adds a room type to app
@param identifier An identifier to the room type. If a real room, MUST BE the same of `db.rocketchat_room.t` field, if not, can be null
@param order Order number of the type
@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
......@@ -45,7 +33,7 @@ RocketChat.roomTypes = new class
if config.route?.path? and config.route?.name? and config.route?.action?
FlowRouter.route config.route.path,
name: config.route.name
action: protectedAction config
action: config.route.action
triggersExit: [roomExit]
###
......@@ -58,19 +46,16 @@ RocketChat.roomTypes = new class
return FlowRouter.path roomTypes[roomType].route.name, roomTypes[roomType].route.link(subData)
checkPermission = (roomType) ->
return not roomType.permissions? or RocketChat.authz.hasAtLeastOnePermission roomType.permissions
checkCondition = (roomType) ->
return not roomType.condition? or roomType.condition()
getAllTypes = ->
typesPermitted = []
orderedTypes = []
_.sortBy(roomTypesOrder, 'order').forEach (type) ->
typesPermitted.push roomTypes[type.identifier]
orderedTypes.push roomTypes[type.identifier]
return typesPermitted
return orderedTypes
getIcon = (roomType) ->
return roomTypes[roomType]?.icon
......@@ -92,6 +77,4 @@ RocketChat.roomTypes = new class
checkCondition: checkCondition
checkPermission: checkPermission
add: add
......@@ -14,7 +14,9 @@ RocketChat.roomTypes.add('l', 5, {
}
}
},
permissions: ['view-l-room']
condition: () => {
return RocketChat.settings.get('Livechat_enabled') && RocketChat.authz.hasAllPermission('view-l-room');
}
});
AccountBox.addItem({
......@@ -22,5 +24,7 @@ AccountBox.addItem({
icon: 'icon-chat-empty',
href: 'livechat-users',
sideNav: 'livechatFlex',
permissions: ['view-livechat-manager'],
condition: () => {
return RocketChat.settings.get('Livechat_enabled') && RocketChat.authz.hasAllPermission('view-livechat-manager');
},
});
......@@ -19,7 +19,7 @@ Template.sideNav.helpers
return RocketChat.roomTypes.getTypes()
canShowRoomType: ->
return RocketChat.roomTypes.checkPermission(@) and RocketChat.roomTypes.checkCondition(@)
return RocketChat.roomTypes.checkCondition(@)
templateName: ->
return @template
......
......@@ -41,9 +41,12 @@
actual.push newItem
items.set actual
checkCondition = (item) ->
return not item.condition? or item.condition()
getItems = ->
return _.filter items.get(), (item) ->
if not item.permissions? or RocketChat.authz.hasAllPermission item.permissions
if checkCondition(item)
return true
addRoute = (newRoute, router = FlowRouter) ->
......
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