Skip to content

Commit

Permalink
Merge pull request #818 from RocketChat/feature/292-roles
Browse files Browse the repository at this point in the history
Create roles and permissions
  • Loading branch information
rodrigok committed Sep 16, 2015
2 parents ee30206 + 8aab1ea commit a134a87
Show file tree
Hide file tree
Showing 74 changed files with 572 additions and 146 deletions.
1 change: 1 addition & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ todda00:friendly-slugs
underscorestring:underscore.string
yasaricli:slugify
yasinuslu:blaze-meta
rocketchat:authorization
2 changes: 2 additions & 0 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ accounts-meteor-developer@1.0.4
accounts-oauth@1.1.5
accounts-password@1.1.1
accounts-twitter@1.0.4
alanning:roles@1.2.13
aldeed:simple-schema@1.3.3
arunoda:streams@0.1.17
autoupdate@1.2.1
Expand Down Expand Up @@ -100,6 +101,7 @@ reactive-dict@1.1.0
reactive-var@1.0.5
reload@1.1.3
retry@1.0.3
rocketchat:authorization@0.0.1
rocketchat:autolinker@0.0.1
rocketchat:colors@0.0.1
rocketchat:custom-oauth@1.0.0
Expand Down
10 changes: 7 additions & 3 deletions client/lib/chatMessages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ class @ChatMessages
return -1

edit: (element, index) ->
return unless RocketChat.settings.get 'Message_AllowEditing'
id = element.getAttribute("id")
message = ChatMessage.findOne { _id: id }
hasPermission = RocketChat.authz.hasAtLeastOnePermission('edit-message', message.rid)
editAllowed = RocketChat.settings.get 'Message_AllowEditing'
editOwn = message?.u?._id is Meteor.userId()

return unless hasPermission or (editAllowed and editOwn)
return if element.classList.contains("system")
this.clearEditing()
id = element.getAttribute("id")
message = ChatMessage.findOne { _id: id, 'u._id': Meteor.userId() }
this.input.value = message.msg
this.editing.element = element
this.editing.index = index or this.getEditingIndex(element)
Expand Down
7 changes: 6 additions & 1 deletion client/methods/deleteMessage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ Meteor.methods
if not Meteor.userId()
throw new Meteor.Error 203, t('general.User_logged_out')

if not RocketChat.settings.get 'Message_AllowDeleting'
hasPermission = RocketChat.authz.hasAtLeastOnePermission('delete-message', message.rid)
deleteAllowed = RocketChat.settings.get 'Message_AllowDeleting'
deleteOwn = message?.u?._id is Meteor.userId()

unless hasPermission or (deleteAllowed and deleteOwn)
throw new Meteor.Error 'message-deleting-not-allowed', t('Message_deleting_not_allowed')


Tracker.nonreactive ->
ChatMessage.remove
_id: message._id
Expand Down
8 changes: 7 additions & 1 deletion client/methods/updateMessage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ Meteor.methods
if not Meteor.userId()
throw new Meteor.Error 203, t('User_logged_out')

if not RocketChat.settings.get 'Message_AllowEditing'
originalMessage = ChatMessage.findOne message._id

hasPermission = RocketChat.authz.hasAtLeastOnePermission('edit-message', message.rid)
editAllowed = RocketChat.settings.get 'Message_AllowEditing'
editOwn = originalMessage?.u?._id is Meteor.userId()

unless hasPermission or (editAllowed and editOwn)
throw new Meteor.Error 'message-editing-not-allowed', t('Message_editing_not_allowed')

Tracker.nonreactive ->
Expand Down
4 changes: 2 additions & 2 deletions client/stylesheets/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -2374,14 +2374,14 @@ a.github-fork {
display: none;
cursor: pointer;
}
&.own:hover:not(.system) .edit-message {
&:hover:not(.system) .edit-message {
display: inline-block;
}
.delete-message {
display: none;
cursor: pointer;
}
&.own:hover:not(.system) .delete-message {
&:hover:not(.system) .delete-message {
display: inline-block;
}
.user {
Expand Down
2 changes: 0 additions & 2 deletions client/views/admin/admin.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Template.admin.helpers
isAdmin: ->
return Meteor.user().admin is true
group: ->
group = FlowRouter.getParam('group')
group ?= Settings.findOne({ type: 'group' })?._id
Expand Down
2 changes: 1 addition & 1 deletion client/views/admin/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h2>
</h2>
</head>
<div class="content">
{{#unless isAdmin}}
{{#unless hasPermission 'view-privileged-setting'}}
<p>You are not authorized to view this page.</p>
{{else}}
{{#with group}}
Expand Down
41 changes: 26 additions & 15 deletions client/views/admin/adminFlex.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,35 @@ <h4>{{_ "Administration"}}</h4>
<div class="content">
<div class="wrapper">
<ul>
<li>
<a href="{{pathFor 'admin-statistics'}}" class="admin-link">{{_ "Statistics"}}</a>
</li>
<li>
<a href="{{pathFor 'admin-rooms'}}" class="admin-link">{{_ "Rooms"}}</a>
</li>
<li>
<a href="{{pathFor 'admin-users'}}" class="admin-link">{{_ "Users"}}</a>
</li>

{{#if hasPermission 'view-statistics'}}
<li>
<a href="{{pathFor 'admin-statistics'}}" class="admin-link">{{_ "Statistics"}}</a>
</li>
{{/if}}

{{#if hasPermission 'view-room-administration'}}
<li>
<a href="{{pathFor 'admin-rooms'}}" class="admin-link">{{_ "Rooms"}}</a>
</li>
{{/if}}

{{#if hasPermission 'view-user-administration'}}
<li>
<a href="{{pathFor 'admin-users'}}" class="admin-link">{{_ "Users"}}</a>
</li>
{{/if}}

<h3 class="add-room">
{{_ "Settings"}}
</h3>
{{#each groups}}
<li>
<a href="{{pathFor 'admin' group=_id}}" class="admin-link">{{_ i18nLabel}}</a>
</li>
{{/each}}

{{#if hasPermission 'view-privileged-setting'}}
{{#each groups}}
<li>
<a href="{{pathFor 'admin' group=_id}}" class="admin-link">{{_ i18nLabel}}</a>
</li>
{{/each}}
{{/if}}
</ul>
</div>
</div>
Expand Down
2 changes: 0 additions & 2 deletions client/views/admin/adminStatistics.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Template.adminStatistics.helpers
isAdmin: ->
return Meteor.user().admin is true
isReady: ->
return Template.instance().ready.get()
statistics: ->
Expand Down
2 changes: 1 addition & 1 deletion client/views/admin/adminStatistics.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h2>
</h2>
</head>
<div class="content">
{{#unless isAdmin}}
{{#unless hasPermission 'view-statistics'}}
<p>You are not authorized to view this page.</p>
{{else}}
{{#if isReady}}
Expand Down
3 changes: 3 additions & 0 deletions client/views/admin/rooms/adminRoomInfo.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Template.adminRoomInfo.helpers
canDeleteRoom: ->
return RocketChat.authz.hasAtLeastOnePermission("delete-#{@t}")

type: ->
return if @t is 'd' then 'at' else if @t is 'p' then 'lock' else 'hash'
name: ->
Expand Down
30 changes: 18 additions & 12 deletions client/views/admin/rooms/adminRoomInfo.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
<template name="adminRoomInfo">
<div>
<h3><a href="{{route}}"><i class="icon-{{type}}"></i> {{name}}</a></h3>
</div>
<div>
<h3>{{_ "Users"}}:</h3>
{{#each usernames}}
{{.}}<br />
{{/each}}
</div>
<nav>
<button class='button delete red'><span><i class='icon-trash'></i> {{_ "Delete"}}</span></button>
</nav>
{{#unless hasPermission 'view-room-administration'}}
<p>You are not authorized to view this page.</p>
{{else}}
<div>
<h3><a href="{{route}}"><i class="icon-{{type}}"></i> {{name}}</a></h3>
</div>
<div>
<h3>{{_ "Users"}}:</h3>
{{#each usernames}}
{{.}}<br />
{{/each}}
</div>
{{#if canDeleteRoom}}
<nav>
<button class='button delete red'><span><i class='icon-trash'></i> {{_ "Delete"}}</span></button>
</nav>
{{/if}}
{{/unless}}
</template>
2 changes: 0 additions & 2 deletions client/views/admin/rooms/adminRooms.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Template.adminRooms.helpers
isAdmin: ->
return Meteor.user().admin is true
isReady: ->
return Template.instance().ready?.get()
rooms: ->
Expand Down
2 changes: 1 addition & 1 deletion client/views/admin/rooms/adminRooms.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h2>
</h2>
</head>
<div class="content">
{{#unless isAdmin}}
{{#unless hasPermission 'view-room-administration'}}
<p>You are not authorized to view this page.</p>
{{else}}
<form class="search-form" role="form">
Expand Down
10 changes: 7 additions & 3 deletions client/views/admin/users/adminUserChannels.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<template name="adminUserChannels">
<div class="user-info-channel">
<h3><a href="{{route}}"><i class="icon-{{type}}"></i> {{name}}</a></h3>
</div>
{{#unless hasPermission 'view-full-other-user-info'}}
<p>You are not authorized to view this page.</p>
{{else}}
<div class="user-info-channel">
<h3><a href="{{route}}"><i class="icon-{{type}}"></i> {{name}}</a></h3>
</div>
{{/unless}}
</template>
38 changes: 21 additions & 17 deletions client/views/admin/users/adminUserEdit.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
<template name="adminUserEdit">
<div class="about clearfix">
<form class="edit-form">
<h3>{{name}}</h3>
<div class="input-line">
<label for="name">{{_ "Name"}}</label>
<input type="text" id="name" autocomplete="off" value="{{name}}">
</div>
<div class="input-line">
<label for="username">{{_ "Username"}}</label>
<input type="text" id="username" autocomplete="off" value="{{username}}">
</div>
</form>
</div>
<nav>
<button class='button button-block cancel secondary'><span>{{_ "Cancel"}}</span></button>
<button class='button button-block blue save'><span>{{_ "Save"}}</span></button>
</nav>
{{#unless hasPermission 'edit-other-user-info'}}
<p>You are not authorized to view this page.</p>
{{else}}
<div class="about clearfix">
<form class="edit-form">
<h3>{{name}}</h3>
<div class="input-line">
<label for="name">{{_ "Name"}}</label>
<input type="text" id="name" autocomplete="off" value="{{name}}">
</div>
<div class="input-line">
<label for="username">{{_ "Username"}}</label>
<input type="text" id="username" autocomplete="off" value="{{username}}">
</div>
</form>
</div>
<nav>
<button class='button button-block cancel secondary'><span>{{_ "Cancel"}}</span></button>
<button class='button button-block blue save'><span>{{_ "Save"}}</span></button>
</nav>
{{/unless}}
</template>
5 changes: 3 additions & 2 deletions client/views/admin/users/adminUserInfo.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Template.adminUserInfo.helpers
isAdmin: ->
return Meteor.user()?.admin is true
name: ->
return if @name then @name else TAPi18next.t 'project:Unnamed'
email: ->
Expand All @@ -20,6 +18,9 @@ Template.adminUserInfo.helpers
@utcOffset = "+#{@utcOffset}"

return "UTC #{@utcOffset}"
hasAdminRole: ->
console.log 'hasAdmin: ', RocketChat.authz.hasRole(@_id, 'admin')
return RocketChat.authz.hasRole(@_id, 'admin')

Template.adminUserInfo.events
'click .deactivate': (e) ->
Expand Down
22 changes: 14 additions & 8 deletions client/views/admin/users/adminUserInfo.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
<template name="adminUserInfo">
{{#if isAdmin}}
{{> userInfo user=.}}
<nav>
<button class='button lightblue edit-user button-block'><span><i class='icon-edit'></i> {{_ "Edit"}}</span></button>
{{#if admin}}
{{> userInfo user=.}}
<nav>
{{#if hasPermission 'edit-other-user-info'}}
<button class='button lightblue edit-user button-block'><span><i class='icon-edit'></i> {{_ "Edit"}}</span></button>
{{/if}}
{{#if hasPermission 'assign-admin-role'}}
{{#if hasAdminRole}}
<button class='button lightblue remove-admin button-block'><span><i class='icon-shield'></i> {{_ "Remove_Admin"}}</span></button>
{{else}}
<button class='button lightblue make-admin button-block'><span><i class='icon-shield'></i> {{_ "Make_Admin"}}</span></button>
{{/if}}
{{/if}}
{{#if hasPermission 'edit-other-user-active-status'}}
{{#if active}}
<button class='button deactivate button-block'><span><i class='icon-block'></i> {{_ "Deactivate"}}</span></button>
{{else}}
<button class='button activate button-block'><span><i class='icon-ok-circled'></i> {{_ "Activate"}}</span></button>
{{/if}}
<button class='button delete red button-block'><span><i class='icon-trash'></i> {{_ "Delete"}}</span></button>
</nav>
{{/if}}
{{/if}}
{{#if hasPermission 'delete-user'}}
<button class='button delete red button-block'><span><i class='icon-trash'></i> {{_ "Delete"}}</span></button>
{{/if}}
</nav>
</template>
2 changes: 0 additions & 2 deletions client/views/admin/users/adminUsers.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Template.adminUsers.helpers
isAdmin: ->
return Meteor.user().admin is true
isReady: ->
return Template.instance().ready?.get()
users: ->
Expand Down
2 changes: 1 addition & 1 deletion client/views/admin/users/adminUsers.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h2>
</h2>
</head>
<div class="content">
{{#unless isAdmin}}
{{#unless hasPermission 'view-user-administration'}}
<p>You are not authorized to view this page.</p>
{{else}}
<form class="search-form" role="form">
Expand Down
11 changes: 9 additions & 2 deletions client/views/app/message.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ Template.message.helpers
pinned: ->
return this.pinned
canEdit: ->
return RocketChat.settings.get 'Message_AllowEditing'
if RocketChat.authz.hasAtLeastOnePermission('edit-message', this.rid )
return true

return RocketChat.settings.get('Message_AllowEditing') and this.u?._id is Meteor.userId()

canDelete: ->
return RocketChat.settings.get 'Message_AllowDeleting'
if RocketChat.authz.hasAtLeastOnePermission('delete-message', this.rid )
return true

return RocketChat.settings.get('Message_AllowDeleting') and this.u?._id is Meteor.userId()
canPin: ->
return RocketChat.settings.get 'Message_AllowPinning'
showEditedStatus: ->
Expand Down
8 changes: 4 additions & 4 deletions client/views/app/room.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ Template.room.helpers
canEditName: ->
roomData = Session.get('roomData' + this._id)
return '' unless roomData
return roomData.u?._id is Meteor.userId() and roomData.t in ['c', 'p']
if roomData.t in ['c', 'p']
return RocketChat.authz.hasAtLeastOnePermission('edit-room', this._id)
else
return ''

canDirectMessage: ->
return Meteor.user()?.username isnt this.username
Expand Down Expand Up @@ -183,9 +186,6 @@ Template.room.helpers
maxMessageLength: ->
return RocketChat.settings.get('Message_MaxAllowedSize')

isAdmin: ->
return Meteor.user()?.admin is true

utc: ->
if @utcOffset?
return "UTC #{@utcOffset}"
Expand Down
Loading

0 comments on commit a134a87

Please sign in to comment.