Skip to content

Commit

Permalink
Fixed #13. Error thrown for unncessary reason.
Browse files Browse the repository at this point in the history
- Modify serverside method to not check if user is logged in.  Method
  does not return sensitive information, and does not depend on the
  current user.
- Add permissionIds isn't undefined/null check to serverside method.
- Move security banner logic, display to its own template.  Helps to
  separate RocketChat and chat-locker code.  Makes banner modular and
  reuseable.
- banner is reactively dependent on Session's roomData+roomId.  access
  permission changes will propagate to new security banner template.
  • Loading branch information
rwakida committed Aug 8, 2015
1 parent f39bde1 commit 8b4ca30
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 33 deletions.
30 changes: 4 additions & 26 deletions client/views/app/room.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ Template.room.helpers
noRtcLayout: ->
return (!Session.get('rtcLayoutmode') || (Session.get('rtcLayoutmode') == 0) ? true: false);

bannerData: ->
permissions: ->
# The data context only contains the room id. one way to get the banner data is to just pass
# this id to a server-side method and let it look up the room details (such as permissions)
# and then return the banner info.
Expand All @@ -281,18 +281,9 @@ Template.room.helpers
# this is to make "bannerData" itself reactive by having it depend directly on the room data.
# Then, since that data gets synchronized with the server, the template will be reprocessed
# when the data changes.
accessPermissions = ChatRoom.findOne(this._id)?.accessPermissions || []
Template.instance().updateBannerData(accessPermissions)
return Template.instance().bannerData

# For helpers "classificationId" and "securityBannerText", "this" refers to what is returned
# from "bannerData"
classificationId: ->
return this.get 'classificationId'

securityBannerText: ->
return this.get 'text'

roomData = Session.get('roomData' + this._id)
return roomData?.accessPermissions

maxMessageLength: ->
return RocketChat.settings.get('Message_MaxAllowedSize')

Expand Down Expand Up @@ -590,19 +581,6 @@ Template.room.onCreated ->
this.showUsersOffline = new ReactiveVar false
this.atBottom = true

this.bannerData = new ReactiveDict
this.bannerData.set 'text', 'Unknown'
this.bannerData.set 'classificationId', 'U'

this.updateBannerData = (accessPermissions) ->
Meteor.call 'getSecurityBanner', accessPermissions, (error, result) ->
if error
toastr.error error.reason
else
self.bannerData.set 'text', result.text
self.bannerData.set 'classificationId', result.classificationId


Template.room.onRendered ->
FlexTab.check()
this.chatMessages = new ChatMessages
Expand Down
6 changes: 1 addition & 5 deletions client/views/app/room.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ <h2>
{{/if}}
</h2>
</header>
{{#with bannerData}}
<div class="security-banner {{classificationId}}">
{{securityBannerText}}
</div>
{{/with}}
{{> securityBanner permissions=permissions }}
<div class="messages-box">
<div class="wrapper">
<ul>
Expand Down
20 changes: 20 additions & 0 deletions client/views/app/securityBanner.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Template.securityBanner.helpers
bannerData: ->
Template.instance().updateBannerData(this.permissions)
return Template.instance().bannerData.get()


Template.securityBanner.onCreated ->
self = this
this.bannerData = new ReactiveVar {text:'Unknown', classificationId : 'U'}

this.updateBannerData = (accessPermissions) ->
# ignore undefined/null
unless accessPermissions
return

Meteor.call 'getSecurityBanner', accessPermissions, (error, result) ->
if error
console.error error.reason
else
self.bannerData.set result
7 changes: 7 additions & 0 deletions client/views/app/securityBanner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template name="securityBanner">
{{#with bannerData}}
<div class="security-banner {{classificationId}}">
{{text}}
</div>
{{/with}}
</template>
4 changes: 2 additions & 2 deletions server/methods/getSecurityBanner.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Meteor.methods
getSecurityBanner: (permissionIds) ->
if not Meteor.userId()
throw new Meteor.Error('invalid-user', "[methods] getSecurityBanner -> Invalid user")
if not permissionIds
throw new Meteor.Error('invalid-argument', "No permission ids specified")

banner = {}

Expand Down

0 comments on commit 8b4ca30

Please sign in to comment.