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

feat: send event when deleting all sessions #3014

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
feat: add some notes
  • Loading branch information
christyjacob4 committed Mar 26, 2022
commit aef252a3ae90d8b7b0daef25e0a9d9db49a2055e
2 changes: 2 additions & 0 deletions app/controllers/api/teams.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@
->setParam('event', 'teams.memberships.create')
->setParam('resource', 'team/'.$teamId)
;
var_dump($audits);

$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic($membership
Expand Down Expand Up @@ -742,6 +743,7 @@
->setParam('event', 'teams.memberships.update.status')
->setParam('resource', 'team/'.$teamId)
;
var_dump($audits);

if (!Config::getParam('domainVerification')) {
$response
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/shared/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Appwrite\Extend\Exception;
use Utopia\Abuse\Abuse;
use Utopia\Abuse\Adapters\TimeLimit;
use Utopia\CLI\Console;
use Utopia\Database\Document;
use Utopia\Storage\Device\DOSpaces;
use Utopia\Database\Validator\Authorization;
Expand Down Expand Up @@ -90,6 +91,7 @@
$events
->setParam('projectId', $project->getId())
->setParam('webhooks', $project->getAttribute('webhooks', []))
// When membership status update happens here, the userId is empty since there is no cookie
->setParam('userId', $user->getId())
->setParam('event', $route->getLabel('event', ''))
->setParam('eventData', [])
Expand Down Expand Up @@ -227,6 +229,14 @@
bucket: $bucket,
);

// Console::success('API.PHP');
var_dump($events);

// The problem with solving point number 2 of issue #2626 is that we dont have
// a way to send events to multiple user IDs here.
// When a membership status updates, we need to send a message to atlease
// The team owner and the member who updated the membership status.

Realtime::send(
$target['projectId'] ?? $project->getId(),
$response->getPayload(),
Expand Down
2 changes: 2 additions & 0 deletions app/realtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ function () use ($register, $db, $redis) {
$redis->subscribe(['realtime'], function (Redis $redis, string $channel, string $payload) use ($server, $workerId, $stats, $register, $realtime) {
$event = json_decode($payload, true);

Console::success('Event received: ' . json_encode($event));

if ($event['permissionsChanged'] && isset($event['userId'])) {
$projectId = $event['project'];
$userId = $event['userId'];
Expand Down
8 changes: 4 additions & 4 deletions src/Appwrite/Messaging/Adapter/Realtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ public function hasSubscriber(string $projectId, string $role, string $channel =
*/
public static function send(string $projectId, array $payload, string $event, array $channels, array $roles, array $options = []): void
{
// Console::success('REALTIME');
// var_dump($projectId, $payload, $event, $channels, $roles, $options);
if (empty($channels) || empty($roles) || empty($projectId)) return;

// Console::success('REALTIME SEND');
// var_dump($projectId, $payload, $event, $channels, $roles, $options);

$permissionsChanged = array_key_exists('permissionsChanged', $options) && $options['permissionsChanged'];
$userId = array_key_exists('userId', $options) ? $options['userId'] : null;

Expand Down Expand Up @@ -260,7 +261,6 @@ public static function fromPayload(string $event, Document $payload, Document $p

break;
case strpos($event, 'account.sessions.') === 0:
var_dump($payload);
$channels[] = 'account';
$userId = $payload->getAttribute('userId');
if (empty($userId)) {
Expand Down Expand Up @@ -335,7 +335,7 @@ public static function fromPayload(string $event, Document $payload, Document $p
break;
}

var_dump($channels, $roles, $permissionsChanged, $projectId);
// var_dump($channels, $roles, $permissionsChanged, $projectId);
return [
'channels' => $channels,
'roles' => $roles,
Expand Down