From e224ca440b1f5a8bdc73a2e3494bcc2f62c0486e Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 3 Apr 2024 16:36:21 +1300 Subject: [PATCH] Allow setting event parameters as sensitive --- app/controllers/shared/api.php | 2 +- src/Appwrite/Event/Event.php | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index ad9ed97b63..2444813b40 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -590,7 +590,7 @@ App::shutdown() Realtime::send( projectId: $target['projectId'] ?? $project->getId(), - payload: $queueForEvents->getPayload(), + payload: $queueForEvents->getRealtimePayload(), events: $allEvents, channels: $target['channels'], roles: $target['roles'], diff --git a/src/Appwrite/Event/Event.php b/src/Appwrite/Event/Event.php index fa9ddf1315..f85195b154 100644 --- a/src/Appwrite/Event/Event.php +++ b/src/Appwrite/Event/Event.php @@ -52,6 +52,7 @@ class Event protected string $class = ''; protected string $event = ''; protected array $params = []; + protected array $sensitive = []; protected array $payload = []; protected array $context = []; protected ?Document $project = null; @@ -161,12 +162,17 @@ class Event * Set payload for this event. * * @param array $payload + * @param array $sensitive * @return self */ - public function setPayload(array $payload): self + public function setPayload(array $payload, array $sensitive = []): self { $this->payload = $payload; + foreach ($sensitive as $key) { + $this->sensitive[$key] = true; + } + return $this; } @@ -180,6 +186,19 @@ class Event return $this->payload; } + public function getRealtimePayload(): array + { + $payload = []; + + foreach ($this->payload as $key => $value) { + if (!isset($this->sensitive[$key])) { + $payload[$key] = $value; + } + } + + return $payload; + } + /** * Set context for this event. * @@ -242,6 +261,13 @@ class Event return $this; } + public function setParamSensitive(string $key): self + { + $this->sensitive[$key] = true; + + return $this; + } + /** * Get param of event. * @@ -294,6 +320,7 @@ class Event public function reset(): self { $this->params = []; + $this->sensitive = []; return $this; }