Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow guest users to view joined direct rooms #3958

Merged
merged 1 commit into from
Aug 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/startup/defaultRoomTypes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ RocketChat.roomTypes.add 'd', 20,
roomName: (roomData) ->
return ChatSubscription.findOne({ rid: roomData._id }, { fields: { name: 1 } })?.name
condition: ->
return RocketChat.authz.hasAllPermission 'view-d-room'
return RocketChat.authz.hasAtLeastOnePermission ['view-d-room', 'view-joined-room']

RocketChat.roomTypes.add 'p', 30,
template: 'privateGroups'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
RocketChat.authz.hasPermission = (userId, permissionId, scope) ->
permission = RocketChat.models.Permissions.findOne permissionId
return RocketChat.models.Roles.isUserInRoles(userId, permission.roles, scope)
atLeastOne = (userId, permissions, scope) ->
return _.some permissions, (permissionId) ->
permission = RocketChat.models.Permissions.findOne permissionId
RocketChat.models.Roles.isUserInRoles(userId, permission.roles, scope)

all = (userId, permissions, scope) ->
return _.every permissions, (permissionId) ->
permission = RocketChat.models.Permissions.findOne permissionId
RocketChat.models.Roles.isUserInRoles(userId, permission.roles, scope)

hasPermission = (userId, permissions, scope, strategy) ->
unless userId
return false

permissions = [].concat permissions

return strategy(userId, permissions, scope)



RocketChat.authz.hasAllPermission = (userId, permissions, scope) ->
return hasPermission(userId, permissions, scope, all)

RocketChat.authz.hasPermission = RocketChat.authz.hasAllPermission

RocketChat.authz.hasAtLeastOnePermission = (userId, permissions, scope) ->
return hasPermission(userId, permissions, scope, atLeastOne)
2 changes: 1 addition & 1 deletion server/startup/roomPublishes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ Meteor.startup ->
jitsiTimeout: 1

user = RocketChat.models.Users.findOneById this.userId, fields: username: 1
if RocketChat.authz.hasPermission(this.userId, 'view-d-room')
if RocketChat.authz.hasAtLeastOnePermission(this.userId, ['view-d-room', 'view-joined-room'])
return RocketChat.models.Rooms.findByTypeContainigUsernames 'd', [user.username, identifier], options
return this.ready()