1
0
Fork 0
mirror of synced 2024-09-29 08:51:28 +13:00

remove wildcard permissions from subscriptions

This commit is contained in:
Torsten Dittmann 2021-03-01 12:23:45 +01:00
parent 787c275338
commit 3e92d28cc8
4 changed files with 12 additions and 12 deletions

View file

@ -25,7 +25,7 @@ class Realtime
*/
static function getRoles()
{
$roles = ['*', 'role:' . ((self::$user->isEmpty()) ? Auth::USER_ROLE_GUEST : Auth::USER_ROLE_MEMBER)];
$roles = ['role:' . ((self::$user->isEmpty()) ? Auth::USER_ROLE_GUEST : Auth::USER_ROLE_MEMBER)];
if (!(self::$user->isEmpty())) {
$roles[] = 'user:' . self::$user->getId();
}
@ -87,7 +87,10 @@ class Realtime
foreach ($connection['roles'] as $role) {
if (\array_key_exists($role, $subscriptions[$event['project']])) {
foreach ($event['data']['channels'] as $channel) {
if (\array_key_exists($channel, $subscriptions[$event['project']][$role]) && \in_array($role, $event['permissions'])) {
if (
\array_key_exists($channel, $subscriptions[$event['project']][$role])
&& (\in_array($role, $event['permissions']) || \in_array('*', $event['permissions']))
) {
foreach (array_keys($subscriptions[$event['project']][$role][$channel]) as $ids) {
$receivers[] = $ids;
}

View file

@ -115,11 +115,10 @@ class RealtimeChannelsTest extends TestCase
* - XXX users
* - XXX teams
* - XXX team roles (2 roles per team)
* - 1 *
* - 1 role:guest
* - 1 role:member
*/
$this->assertCount(($this->connectionsAuthenticated + (3 * $this->connectionsPerChannel) + 3), $this->subscriptions['1']);
$this->assertCount(($this->connectionsAuthenticated + (3 * $this->connectionsPerChannel) + 2), $this->subscriptions['1']);
/**
* Check for connections
@ -131,9 +130,9 @@ class RealtimeChannelsTest extends TestCase
Realtime::removeSubscription(-1, $this->subscriptions, $this->connections);
$this->assertCount($this->connectionsTotal, $this->connections);
$this->assertCount(($this->connectionsAuthenticated + (3 * $this->connectionsPerChannel) + 3), $this->subscriptions['1']);
$this->assertCount(($this->connectionsAuthenticated + (3 * $this->connectionsPerChannel) + 2), $this->subscriptions['1']);
for ($i=0; $i < $this->connectionsCount; $i++) {
for ($i = 0; $i < $this->connectionsCount; $i++) {
Realtime::removeSubscription($i, $this->subscriptions, $this->connections);
$this->assertCount(($this->connectionsCount - $i - 1), $this->connections);

View file

@ -26,8 +26,7 @@ class RealtimeGuestTest extends TestCase
]));
$roles = Realtime::getRoles();
$this->assertCount(2, $roles);
$this->assertContains('*', $roles);
$this->assertCount(1, $roles);
$this->assertContains('role:guest', $roles);
$channels = [
@ -205,7 +204,7 @@ class RealtimeGuestTest extends TestCase
Realtime::removeSubscription(2, $this->subscriptions, $this->connections);
$this->assertCount(1, $this->connections);
$this->assertCount(2, $this->subscriptions['1']);
$this->assertCount(1, $this->subscriptions['1']);
Realtime::removeSubscription(1, $this->subscriptions, $this->connections);

View file

@ -42,8 +42,7 @@ class RealtimeTest extends TestCase
$roles = Realtime::getRoles();
$this->assertCount(8, $roles);
$this->assertContains('*', $roles);
$this->assertCount(7, $roles);
$this->assertContains('user:123', $roles);
$this->assertContains('role:member', $roles);
$this->assertContains('team:abc', $roles);
@ -223,7 +222,7 @@ class RealtimeTest extends TestCase
Realtime::removeSubscription(2, $this->subscriptions, $this->connections);
$this->assertCount(1, $this->connections);
$this->assertCount(8, $this->subscriptions['1']);
$this->assertCount(7, $this->subscriptions['1']);
Realtime::removeSubscription(1, $this->subscriptions, $this->connections);