Skip to content

Commit

Permalink
Merge pull request #1504 from RocketChat/account-box-customizable-items
Browse files Browse the repository at this point in the history
Account box customizable items
  • Loading branch information
sampaiodiego committed Nov 27, 2015
2 parents 3a35260 + b8a53c9 commit 90cc64d
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 21 deletions.
4 changes: 3 additions & 1 deletion i18n/en.i18n.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"Access_online_demo" : "Access the online demo",
"Access_Online_Demo" : "Access the Online Demo",
"Access_not_authorized" : "Access not authorized",
"Accounts" : "Accounts",
"Accounts_AllowedDomainsList" : "Allowed Domains List",
"Accounts_AllowedDomainsList_Description" : "Comma-separated list of allowed domains",
Expand Down Expand Up @@ -271,6 +272,7 @@
"No_permission_to_view_room" : "You don't have permission to view this room",
"No_user_with_username_%s_was_found" : "No user with username <strong>\"%s\"</strong> was found!",
"Not_allowed" : "Not allowed",
"Not_authorized" : "Not authorized",
"Not_found_or_not_allowed" : "Not Found or Not Allowed",
"Nothing_found" : "Nothing found",
"Notify_all_in_this_room" : "Notify all in this room",
Expand Down Expand Up @@ -456,4 +458,4 @@
"You_will_not_be_able_to_recover" : "You will not be able to recover this message!",
"Your_entry_has_been_deleted" : "Your entry has been deleted.",
"Your_Open_Source_solution" : "Your own Open Source chat solution"
}
}
2 changes: 2 additions & 0 deletions i18n/pt.i18n.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"Access_online_demo" : "Acesse o demo online",
"Access_Online_Demo" : "Acesse o Demo Online",
"Access_not_authorized" : "Accesso não autorizado",
"Accounts" : "Contas",
"Accounts_AllowedDomainsList" : "Lista de domínios permitidos (separados por vírgula)",
"Accounts_AllowUsernameChange" : "Permitir alterar usuário",
Expand Down Expand Up @@ -238,6 +239,7 @@
"No_permission_to_view_room" : "Sem permissões para ver a sala",
"No_user_with_username_%s_was_found" : "Nenhum usuário com nome de usuário <strong>\"%s\"</strong> foi encontrado!",
"Not_allowed" : "Não permitido",
"Not_authorized" : "Não autorizado",
"Not_found_or_not_allowed" : "Não encontrado ou não permitido",
"Nothing_found" : "Nada encontrado",
"Notify_all_in_this_room" : "Notificar todos nesta sala",
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-authorization/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Package.onUse(function(api) {
api.versionsFrom('1.0');
api.use([
'coffeescript',
'underscore',
'rocketchat:[email protected]',
'alanning:[email protected]'
]);
Expand Down
13 changes: 12 additions & 1 deletion packages/rocketchat-lib/client/lib/roomTypes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ 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
Expand Down Expand Up @@ -34,7 +45,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: config.route.action
action: protectedAction config
triggersExit: [roomExit]

###
Expand Down
25 changes: 22 additions & 3 deletions packages/rocketchat-livechat/client/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,29 @@ RocketChat.roomTypes.add('l', 5, {
openRoom('l', params.name);
},
link: (sub) => {
return { name: sub.name }
return {
name: sub.name
}
}
},
permissions: [ 'view-l-room' ]
permissions: ['view-l-room']
});

AccountBox.addOption({ name: 'Livechat', icon: 'icon-chat-empty', class: 'livechat-manager', roles: ['livechat-manager'] });
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']
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<template name="livechat-manager">
<h1>livechat-manager</h1>
<p>Example</p>
</template>
2 changes: 2 additions & 0 deletions packages/rocketchat-livechat/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Package.onUse(function(api) {

api.addFiles('client/ui.js', 'client');
api.addFiles('client/route.js', 'client');

api.addFiles('client/views/app/livechat-manager.html', 'client');
api.addFiles('client/views/sideNav/livechat.html', 'client');
api.addFiles('client/views/sideNav/livechat.js', 'client');

Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-livechat/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ Meteor.startup(() => {
}
if (RocketChat.models && RocketChat.models.Permissions) {
RocketChat.models.Permissions.createOrUpdate('view-l-room', ['livechat-agent', 'livechat-manager']);
RocketChat.models.Permissions.createOrUpdate('view-livechat-manager', ['livechat-manager']);
}
});
9 changes: 9 additions & 0 deletions packages/rocketchat-theme/assets/stylesheets/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,15 @@ input.search {
}
}

form.inline {
input[type='text'],
input[type='number'],
input[type='email'],
input[type='password'] {
width: auto;
}
}

.search-form {
position: relative;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/rocketchat-ui-sidenav/side-nav/sideNav.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ Template.sideNav.helpers
return RocketChat.authz.hasAtLeastOnePermission( ['view-statistics', 'view-room-administration', 'view-user-administration', 'view-privileged-setting'])

registeredMenus: ->
return AccountBox.getOptions()
return AccountBox.getItems()

itemPath: ->
FlowRouter.path @route.name

Template.sideNav.events
'click .close-flex': ->
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-ui-sidenav/side-nav/sideNav.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h4>{{username}}</h4>
<a href="" data-status="offline" class="status offline"><span>{{_ "Invisible"}}</span></a>
<a href="" id="account" class='account-link'><i class="icon-sliders"></i><span>{{_ "My_Account"}}</span></a>
{{#each registeredMenus}}
<a href="" class="{{class}}"><i class="{{icon}}"></i><span>{{name}}</span></a>
<a href="{{itemPath}}" class="{{class}}"><i class="{{icon}}"></i><span>{{name}}</span></a>
{{/each}}
{{#if showAdminOption }}
<a href="" id="admin" class='account-link'><i class="icon-wrench"></i><span>{{_ "Administration"}}</span></a>
Expand Down
45 changes: 31 additions & 14 deletions packages/rocketchat-ui/lib/accountBox.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@AccountBox = (->
status = 0
self = {}
options = new ReactiveVar []
items = new ReactiveVar []

setStatus = (status) ->
Meteor.call('UserPresence:setDefaultStatus', status)
Expand All @@ -28,29 +28,46 @@
self.box = $(".account-box")
self.options = self.box.find(".options")

protectedAction = (item) ->
if not item.permissions? or RocketChat.authz.hasAllPermission 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'

###
# @param newOption:
# name: Button label
# icon: Button icon
# class: Class of item
# roles: Which roles see this options
# name: Button label
# icon: Button icon
# class: Class of the item
# permissions: Which permissions a user should have (all of them) to see this item
###
addOption = (newOption) ->
addItem = (newItem) ->
Tracker.nonreactive ->
actual = options.get()
actual.push newOption
options.set actual
actual = items.get()
actual.push newItem
items.set actual

getOptions = ->
return _.filter options.get(), (option) ->
if not option.roles? or RocketChat.authz.hasRole(Meteor.userId(), option.roles)
if newItem.route?.path? and newItem.route?.name? and newItem.route?.action?
FlowRouter.route newItem.route.path,
name: newItem.route.name
action: protectedAction newItem

getItems = ->
return _.filter items.get(), (item) ->
if not item.permissions? or RocketChat.authz.hasAllPermission item.permissions
return true

setStatus: setStatus
toggle: toggle
open: open
close: close
init: init
addOption: addOption
getOptions: getOptions

addItem: addItem
getItems: getItems
)()
4 changes: 4 additions & 0 deletions packages/rocketchat-ui/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Package.onUse(function(api) {
'raix:ui-dropped-event'
]);

api.use('kadira:flow-router', 'client');

// LIB FILES
api.addFiles('lib/accountBox.coffee', 'client');
api.addFiles('lib/accounts.coffee', 'client');
Expand Down Expand Up @@ -74,6 +76,8 @@ Package.onUse(function(api) {
api.addFiles('views/app/audioNotification.html', 'client');
api.addFiles('views/app/burguer.html', 'client');
api.addFiles('views/app/home.html', 'client');
api.addFiles('views/app/notAuthorized.html', 'client');
api.addFiles('views/app/pageContainer.html', 'client');
api.addFiles('views/app/privateHistory.html', 'client');
api.addFiles('views/app/room.html', 'client');
api.addFiles('views/app/roomSearch.html', 'client');
Expand Down
3 changes: 3 additions & 0 deletions packages/rocketchat-ui/views/app/notAuthorized.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template name="notAuthorized">
<h2>{{_ "Access_not_authorized"}}</h2>
</template>
13 changes: 13 additions & 0 deletions packages/rocketchat-ui/views/app/pageContainer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template name="pageContainer">
<section class="page-container page-home page-static page-list">
<head class="fixed-title">
{{> burger}}
<h2>
<span class="page-title">{{pageTitle}}</span>
</h2>
</head>
<div class="content">
{{> Template.dynamic template=pageTemplate}}
</div>
</section>
</template>

0 comments on commit 90cc64d

Please sign in to comment.