Skip to content
Snippets Groups Projects
Commit 9965ab4c authored by Gabriel Engel's avatar Gabriel Engel Committed by GitHub
Browse files

Merge pull request #3958 from RocketChat/improvements/guest-direct-room-access

Allow guest users to view joined direct rooms
parents 62407729 1cb2429c
No related branches found
No related tags found
No related merge requests found
...@@ -45,7 +45,7 @@ RocketChat.roomTypes.add 'd', 20, ...@@ -45,7 +45,7 @@ RocketChat.roomTypes.add 'd', 20,
roomName: (roomData) -> roomName: (roomData) ->
return ChatSubscription.findOne({ rid: roomData._id }, { fields: { name: 1 } })?.name return ChatSubscription.findOne({ rid: roomData._id }, { fields: { name: 1 } })?.name
condition: -> condition: ->
return RocketChat.authz.hasAllPermission 'view-d-room' return RocketChat.authz.hasAtLeastOnePermission ['view-d-room', 'view-joined-room']
RocketChat.roomTypes.add 'p', 30, RocketChat.roomTypes.add 'p', 30,
template: 'privateGroups' template: 'privateGroups'
......
RocketChat.authz.hasPermission = (userId, permissionId, scope) -> atLeastOne = (userId, permissions, scope) ->
permission = RocketChat.models.Permissions.findOne permissionId return _.some permissions, (permissionId) ->
return RocketChat.models.Roles.isUserInRoles(userId, permission.roles, scope) 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)
...@@ -50,6 +50,6 @@ Meteor.startup -> ...@@ -50,6 +50,6 @@ Meteor.startup ->
jitsiTimeout: 1 jitsiTimeout: 1
user = RocketChat.models.Users.findOneById this.userId, fields: username: 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 RocketChat.models.Rooms.findByTypeContainigUsernames 'd', [user.username, identifier], options
return this.ready() return this.ready()
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