diff --git a/.env b/.env
index edc7bb741a..dc2bc60763 100644
--- a/.env
+++ b/.env
@@ -2,7 +2,6 @@ _APP_ENV=development
_APP_EDITION=self-hosted
_APP_LOCALE=en
_APP_OPENSSL_KEY_V1=your-secret-key
-_APP_NOTIFICATIONS_TRACKING_SECRET=your-secret-key
_APP_RULES_FORMAT=md5
_APP_SYSTEM_RESPONSE_FORMAT=
_APP_TRUSTED_HEADERS=x-forwarded-for
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 2a4e8ab5bd..e3883e1838 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -213,7 +213,6 @@ jobs:
{ name: 'Webhooks', runner: runner4, functional: true, processes: null, timeout: 15 },
{ name: 'VCS', runner: runner4, functional: true, processes: null, timeout: 15 },
{ name: 'Messaging', runner: runner4, functional: true, processes: null, timeout: 15 },
- { name: 'Notifications', runner: runner4, functional: true, processes: null, timeout: 15 },
{ name: 'Migrations', runner: runner4, functional: true, processes: 1, timeout: 15 },
{ name: 'Project', runner: runner4, functional: true, processes: null, timeout: 15 },
{ name: 'Presences', runner: runner4, functional: true, processes: null, timeout: 15 },
diff --git a/Dockerfile b/Dockerfile
index bdda7298b2..7ffd23f683 100755
--- a/Dockerfile
+++ b/Dockerfile
@@ -93,7 +93,6 @@ RUN chmod +x /usr/local/bin/doctor && \
chmod +x /usr/local/bin/worker-functions && \
chmod +x /usr/local/bin/worker-mails && \
chmod +x /usr/local/bin/worker-messaging && \
- chmod +x /usr/local/bin/worker-notifications && \
chmod +x /usr/local/bin/worker-migrations && \
chmod +x /usr/local/bin/worker-webhooks && \
chmod +x /usr/local/bin/worker-stats-usage && \
diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php
index a90170946b..f93d82456e 100644
--- a/app/config/collections/platform.php
+++ b/app/config/collections/platform.php
@@ -485,17 +485,6 @@ $platformCollections = [
'array' => false,
'filters' => [],
],
- [
- '$id' => ID::custom('projectInternalId'),
- 'type' => Database::VAR_ID,
- 'format' => '',
- 'size' => 0,
- 'signed' => true,
- 'required' => false,
- 'default' => null,
- 'array' => false,
- 'filters' => [],
- ],
[
'$id' => ID::custom('schedule'),
'type' => Database::VAR_STRING,
@@ -556,13 +545,6 @@ $platformCollections = [
'lengths' => [],
'orders' => [],
],
- [
- '$id' => ID::custom('_key_region_resourceType_projectInternalId_resourceId'),
- 'type' => Database::INDEX_KEY,
- 'attributes' => ['region', 'resourceType', 'projectInternalId', 'resourceId'],
- 'lengths' => [],
- 'orders' => [],
- ],
[
'$id' => ID::custom('_key_project_id_region'),
'type' => Database::INDEX_KEY,
@@ -570,13 +552,6 @@ $platformCollections = [
'lengths' => [],
'orders' => [],
],
- [
- '$id' => ID::custom('_key_project_internal_id_region'),
- 'type' => Database::INDEX_KEY,
- 'attributes' => ['projectInternalId', 'region'],
- 'lengths' => [],
- 'orders' => [],
- ],
[
'$id' => ID::custom('_key_region_rt_active'),
'type' => Database::INDEX_KEY,
@@ -1068,238 +1043,6 @@ $platformCollections = [
],
],
- 'notifications' => [
- '$collection' => ID::custom(Database::METADATA),
- '$id' => ID::custom('notifications'),
- 'name' => 'Notifications',
- 'attributes' => [
- [
- '$id' => ID::custom('messageId'),
- 'type' => Database::VAR_STRING,
- 'format' => '',
- 'size' => Database::LENGTH_KEY,
- 'signed' => true,
- 'required' => false,
- 'default' => null,
- 'array' => false,
- 'filters' => [],
- ],
- [
- '$id' => ID::custom('recipientHash'),
- 'type' => Database::VAR_STRING,
- 'format' => '',
- 'size' => 64,
- 'signed' => true,
- 'required' => true,
- 'default' => null,
- 'array' => false,
- 'filters' => [],
- ],
- [
- '$id' => ID::custom('type'),
- 'type' => Database::VAR_STRING,
- 'format' => '',
- 'size' => 100,
- 'signed' => true,
- 'required' => false,
- 'default' => 'info',
- 'array' => false,
- 'filters' => [],
- ],
- [
- '$id' => ID::custom('channel'),
- 'type' => Database::VAR_STRING,
- 'format' => '',
- 'size' => 64,
- 'signed' => true,
- 'required' => true,
- 'default' => null,
- 'array' => false,
- 'filters' => [],
- ],
- [
- '$id' => ID::custom('resourceType'),
- 'type' => Database::VAR_STRING,
- 'format' => '',
- 'size' => 64,
- 'signed' => true,
- 'required' => true,
- 'default' => null,
- 'array' => false,
- 'filters' => [],
- ],
- [
- '$id' => ID::custom('resourceId'),
- 'type' => Database::VAR_STRING,
- 'format' => '',
- 'size' => Database::LENGTH_KEY,
- 'signed' => true,
- 'required' => true,
- 'default' => null,
- 'array' => false,
- 'filters' => [],
- ],
- [
- '$id' => ID::custom('projectId'),
- 'type' => Database::VAR_STRING,
- 'format' => '',
- 'size' => Database::LENGTH_KEY,
- 'signed' => true,
- 'required' => true,
- 'default' => null,
- 'array' => false,
- 'filters' => [],
- ],
- [
- '$id' => ID::custom('projectInternalId'),
- 'type' => Database::VAR_ID,
- 'format' => '',
- 'size' => 0,
- 'signed' => true,
- 'required' => true,
- 'default' => null,
- 'array' => false,
- 'filters' => [],
- ],
- [
- '$id' => ID::custom('resourceInternalId'),
- 'type' => Database::VAR_ID,
- 'format' => '',
- 'size' => 0,
- 'signed' => true,
- 'required' => true,
- 'default' => null,
- 'array' => false,
- 'filters' => [],
- ],
- [
- '$id' => ID::custom('parentResourceType'),
- 'type' => Database::VAR_STRING,
- 'format' => '',
- 'size' => 64,
- 'signed' => true,
- 'required' => true,
- 'default' => null,
- 'array' => false,
- 'filters' => [],
- ],
- [
- '$id' => ID::custom('parentResourceId'),
- 'type' => Database::VAR_STRING,
- 'format' => '',
- 'size' => Database::LENGTH_KEY,
- 'signed' => true,
- 'required' => true,
- 'default' => null,
- 'array' => false,
- 'filters' => [],
- ],
- [
- '$id' => ID::custom('parentResourceInternalId'),
- 'type' => Database::VAR_ID,
- 'format' => '',
- 'size' => 0,
- 'signed' => true,
- 'required' => true,
- 'default' => null,
- 'array' => false,
- 'filters' => [],
- ],
- [
- '$id' => ID::custom('title'),
- 'type' => Database::VAR_STRING,
- 'format' => '',
- 'size' => 256,
- 'signed' => true,
- 'required' => true,
- 'default' => null,
- 'array' => false,
- 'filters' => [],
- ],
- [
- '$id' => ID::custom('body'),
- 'type' => Database::VAR_STRING,
- 'format' => '',
- 'size' => 65535,
- 'signed' => true,
- 'required' => true,
- 'default' => null,
- 'array' => false,
- 'filters' => [],
- ],
- [
- '$id' => ID::custom('read'),
- 'type' => Database::VAR_BOOLEAN,
- 'format' => '',
- 'size' => 0,
- 'signed' => true,
- 'required' => false,
- 'default' => false,
- 'array' => false,
- 'filters' => [],
- ],
- [
- '$id' => ID::custom('firstSeen'),
- 'type' => Database::VAR_DATETIME,
- 'format' => '',
- 'size' => 0,
- 'signed' => false,
- 'required' => false,
- 'default' => null,
- 'array' => false,
- 'filters' => ['datetime'],
- ],
- [
- '$id' => ID::custom('lastSeen'),
- 'type' => Database::VAR_DATETIME,
- 'format' => '',
- 'size' => 0,
- 'signed' => false,
- 'required' => false,
- 'default' => null,
- 'array' => false,
- 'filters' => ['datetime'],
- ],
- ],
- 'indexes' => [
- [
- '$id' => ID::custom('_key_messageId'),
- 'type' => Database::INDEX_KEY,
- 'attributes' => ['messageId'],
- 'lengths' => [Database::LENGTH_KEY],
- 'orders' => [Database::ORDER_ASC],
- ],
- [
- '$id' => ID::custom('_key_recipient'),
- 'type' => Database::INDEX_UNIQUE,
- 'attributes' => ['messageId', 'channel', 'recipientHash'],
- 'lengths' => [Database::LENGTH_KEY, 64, 64],
- 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC, Database::ORDER_ASC],
- ],
- [
- '$id' => ID::custom('_key_project'),
- 'type' => Database::INDEX_KEY,
- 'attributes' => ['projectId', 'projectInternalId'],
- 'lengths' => [Database::LENGTH_KEY, 0],
- 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC],
- ],
- [
- '$id' => ID::custom('_key_project_resource'),
- 'type' => Database::INDEX_KEY,
- 'attributes' => ['projectId', 'projectInternalId', 'resourceType', 'resourceId', 'resourceInternalId'],
- 'lengths' => [Database::LENGTH_KEY, 0, 64, Database::LENGTH_KEY, 0],
- 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC, Database::ORDER_ASC, Database::ORDER_ASC, Database::ORDER_ASC],
- ],
- [
- '$id' => ID::custom('_key_project_parent_resource'),
- 'type' => Database::INDEX_KEY,
- 'attributes' => ['projectId', 'projectInternalId', 'parentResourceType', 'parentResourceId', 'parentResourceInternalId'],
- 'lengths' => [Database::LENGTH_KEY, 0, 64, Database::LENGTH_KEY, 0],
- 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC, Database::ORDER_ASC, Database::ORDER_ASC, Database::ORDER_ASC],
- ],
- ],
- ],
-
'certificates' => [
'$collection' => ID::custom(Database::METADATA),
'$id' => ID::custom('certificates'),
diff --git a/app/config/variables.php b/app/config/variables.php
index 8b4fa74bf9..b77d841aaf 100644
--- a/app/config/variables.php
+++ b/app/config/variables.php
@@ -79,15 +79,6 @@ return [
'question' => 'Choose a secret API key, make sure to make a backup of your key in a secure location',
'filter' => 'token'
],
- [
- 'name' => '_APP_NOTIFICATIONS_TRACKING_SECRET',
- 'description' => 'Secret key used to sign notification logo tracking tokens. This must be the same value for API containers and notification workers. Change it from the default value before running in production.',
- 'introduction' => '1.9.0',
- 'default' => 'your-secret-key',
- 'required' => true,
- 'question' => '',
- 'filter' => 'token'
- ],
[
'name' => '_APP_DOMAIN',
'description' => 'Your Appwrite domain address. When setting a public suffix domain, Appwrite will attempt to issue a valid SSL certificate automatically. When used with a dev domain, Appwrite will assign a self-signed SSL certificate. The default value is \'localhost\'. Multiple domains can be separated by commas.',
diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php
index 61a35761ca..13119ac2c6 100644
--- a/app/controllers/api/messaging.php
+++ b/app/controllers/api/messaging.php
@@ -3501,7 +3501,6 @@ Http::post('/v1/messaging/messages/email')
'resourceInternalId' => $message->getSequence(),
'resourceUpdatedAt' => DateTime::now(),
'projectId' => $project->getId(),
- 'projectInternalId' => $project->getSequence(),
'schedule' => $scheduledAt,
'active' => true,
]));
@@ -3648,7 +3647,6 @@ Http::post('/v1/messaging/messages/sms')
'resourceInternalId' => $message->getSequence(),
'resourceUpdatedAt' => DateTime::now(),
'projectId' => $project->getId(),
- 'projectInternalId' => $project->getSequence(),
'schedule' => $scheduledAt,
'active' => true,
]));
@@ -3871,7 +3869,6 @@ Http::post('/v1/messaging/messages/push')
'resourceInternalId' => $message->getSequence(),
'resourceUpdatedAt' => DateTime::now(),
'projectId' => $project->getId(),
- 'projectInternalId' => $project->getSequence(),
'schedule' => $scheduledAt,
'active' => true,
]));
@@ -4266,7 +4263,6 @@ Http::patch('/v1/messaging/messages/email/:messageId')
'resourceInternalId' => $message->getSequence(),
'resourceUpdatedAt' => DateTime::now(),
'projectId' => $project->getId(),
- 'projectInternalId' => $project->getSequence(),
'schedule' => $scheduledAt,
'active' => $status === MessageStatus::SCHEDULED,
]));
@@ -4283,7 +4279,6 @@ Http::patch('/v1/messaging/messages/email/:messageId')
}
$schedule
- ->setAttribute('projectInternalId', $project->getSequence())
->setAttribute('resourceUpdatedAt', DateTime::now())
->setAttribute('active', $scheduledStatus);
@@ -4492,7 +4487,6 @@ Http::patch('/v1/messaging/messages/sms/:messageId')
'resourceInternalId' => $message->getSequence(),
'resourceUpdatedAt' => DateTime::now(),
'projectId' => $project->getId(),
- 'projectInternalId' => $project->getSequence(),
'schedule' => $scheduledAt,
'active' => $status === MessageStatus::SCHEDULED,
]));
@@ -4509,7 +4503,6 @@ Http::patch('/v1/messaging/messages/sms/:messageId')
}
$schedule
- ->setAttribute('projectInternalId', $project->getSequence())
->setAttribute('resourceUpdatedAt', DateTime::now())
->setAttribute('active', $scheduledStatus);
@@ -4671,7 +4664,6 @@ Http::patch('/v1/messaging/messages/push/:messageId')
'resourceInternalId' => $message->getSequence(),
'resourceUpdatedAt' => DateTime::now(),
'projectId' => $project->getId(),
- 'projectInternalId' => $project->getSequence(),
'schedule' => $scheduledAt,
'active' => $status === MessageStatus::SCHEDULED,
]));
@@ -4688,7 +4680,6 @@ Http::patch('/v1/messaging/messages/push/:messageId')
}
$schedule
- ->setAttribute('projectInternalId', $project->getSequence())
->setAttribute('resourceUpdatedAt', DateTime::now())
->setAttribute('active', $scheduledStatus);
diff --git a/app/init/constants.php b/app/init/constants.php
index e905ed56b4..9efb6e3222 100644
--- a/app/init/constants.php
+++ b/app/init/constants.php
@@ -168,7 +168,6 @@ const SESSION_PROVIDER_SERVER = 'server';
const ACTOR_TYPE_USER = 'user';
const ACTOR_TYPE_ADMIN = 'admin';
const ACTOR_TYPE_GUEST = 'guest';
-const ACTOR_TYPE_HIDDEN = 'hidden';
const ACTOR_TYPE_KEY_PROJECT = 'keyProject';
const ACTOR_TYPE_KEY_ACCOUNT = 'keyAccount';
const ACTOR_TYPE_KEY_ORGANIZATION = 'keyOrganization';
@@ -279,13 +278,6 @@ const FUNCTION_ALLOWLIST_HEADERS_RESPONSE = ['content-type', 'content-length'];
const MESSAGE_TYPE_EMAIL = 'email';
const MESSAGE_TYPE_SMS = 'sms';
const MESSAGE_TYPE_PUSH = 'push';
-// Notification types
-const NOTIFICATION_TYPE_EMAIL = MESSAGE_TYPE_EMAIL;
-const NOTIFICATION_TYPE_SMS = MESSAGE_TYPE_SMS;
-const NOTIFICATION_TYPE_PUSH = MESSAGE_TYPE_PUSH;
-const NOTIFICATION_TYPE_CONSOLE = 'console';
-const NOTIFICATION_TYPE_WEBHOOK = 'webhook';
-const NOTIFICATION_TRACKING_JWT_TTL = 60 * 60 * 24 * 7;
const MAIL_TEMPLATE_CERTIFICATE_FAILED = 'certificate-failed';
const MAIL_TEMPLATE_DATA_EXPORT = 'data-export';
const MAIL_TEMPLATE_INVITATION = 'invitation';
@@ -471,8 +463,6 @@ const RESOURCE_TYPE_SUBSCRIBERS = 'subscribers';
const RESOURCE_TYPE_MESSAGES = 'messages';
const RESOURCE_TYPE_EXECUTIONS = 'executions';
const RESOURCE_TYPE_VCS = 'vcs';
-const RESOURCE_TYPE_USERS = 'users';
-const RESOURCE_TYPE_TEAMS = 'teams';
const RESOURCE_TYPE_EMBEDDINGS_TEXT = 'embeddingsText';
const RESOURCE_TYPE_INSIGHTS = 'insights';
const RESOURCE_TYPE_REPORTS = 'reports';
diff --git a/app/init/models.php b/app/init/models.php
index cdb2a9b9b6..efd2c13215 100644
--- a/app/init/models.php
+++ b/app/init/models.php
@@ -115,7 +115,6 @@ use Appwrite\Utopia\Response\Model\MigrationReport;
use Appwrite\Utopia\Response\Model\Mock;
use Appwrite\Utopia\Response\Model\MockNumber;
use Appwrite\Utopia\Response\Model\None;
-use Appwrite\Utopia\Response\Model\Notification;
use Appwrite\Utopia\Response\Model\OAuth2Amazon;
use Appwrite\Utopia\Response\Model\OAuth2Apple;
use Appwrite\Utopia\Response\Model\OAuth2Auth0;
@@ -251,7 +250,6 @@ Response::setModel(new BaseList('Column Indexes List', Response::MODEL_COLUMN_IN
Response::setModel(new BaseList('Users List', Response::MODEL_USER_LIST, 'users', Response::MODEL_USER));
Response::setModel(new BaseList('Sessions List', Response::MODEL_SESSION_LIST, 'sessions', Response::MODEL_SESSION));
Response::setModel(new BaseList('Identities List', Response::MODEL_IDENTITY_LIST, 'identities', Response::MODEL_IDENTITY));
-Response::setModel(new BaseList('Notifications List', Response::MODEL_NOTIFICATION_LIST, 'notifications', Response::MODEL_NOTIFICATION));
Response::setModel(new BaseList('Logs List', Response::MODEL_LOG_LIST, 'logs', Response::MODEL_LOG));
Response::setModel(new BaseList('Files List', Response::MODEL_FILE_LIST, 'files', Response::MODEL_FILE));
Response::setModel(new BaseList('Buckets List', Response::MODEL_BUCKET_LIST, 'buckets', Response::MODEL_BUCKET));
@@ -383,7 +381,6 @@ Response::setModel(new Account());
Response::setModel(new Preferences());
Response::setModel(new Session());
Response::setModel(new Identity());
-Response::setModel(new Notification());
Response::setModel(new Token());
Response::setModel(new JWT());
Response::setModel(new Locale());
diff --git a/app/init/resources.php b/app/init/resources.php
index 51d0b25f8a..34f66d3de7 100644
--- a/app/init/resources.php
+++ b/app/init/resources.php
@@ -12,7 +12,6 @@ use Appwrite\Event\Publisher\Func as FunctionPublisher;
use Appwrite\Event\Publisher\Mail as MailPublisher;
use Appwrite\Event\Publisher\Messaging as MessagingPublisher;
use Appwrite\Event\Publisher\Migration as MigrationPublisher;
-use Appwrite\Event\Publisher\Notification as NotificationPublisher;
use Appwrite\Event\Publisher\Screenshot as ScreenshotPublisher;
use Appwrite\Event\Publisher\StatsResources as StatsResourcesPublisher;
use Appwrite\Event\Publisher\Usage as UsagePublisher;
@@ -151,11 +150,6 @@ $container->set('publisherForMessaging', fn (Publisher $publisher) => new Messag
new Queue(System::getEnv('_APP_MESSAGING_QUEUE_NAME', Event::MESSAGING_QUEUE_NAME))
), ['publisher']);
-$container->set('publisherForNotifications', fn (Publisher $publisher) => new NotificationPublisher(
- $publisher,
- new Queue(System::getEnv('_APP_NOTIFICATIONS_QUEUE_NAME', Event::NOTIFICATIONS_QUEUE_NAME))
-), ['publisher']);
-
$container->set('databaseFactory', fn (Group $pools, Cache $cache, Authorization $authorization) => new DatabaseFactory(
$pools,
$cache,
diff --git a/app/init/worker/message.php b/app/init/worker/message.php
index a5838e9257..7cbfe19b0f 100644
--- a/app/init/worker/message.php
+++ b/app/init/worker/message.php
@@ -2,8 +2,6 @@
use Appwrite\Database\Factory as DatabaseFactory;
use Appwrite\Event\Event;
-use Appwrite\Event\Publisher\Func as FunctionPublisher;
-use Appwrite\Event\Publisher\Notification as NotificationPublisher;
use Appwrite\Event\Realtime;
use Appwrite\Event\Webhook;
use Appwrite\Usage\Context;
@@ -19,7 +17,6 @@ use Utopia\DI\Container;
use Utopia\Logger\Log;
use Utopia\Pools\Group;
use Utopia\Queue\Publisher;
-use Utopia\Queue\Queue;
use Utopia\Registry\Registry;
use Utopia\Span\Span;
use Utopia\Storage\Device\Telemetry as TelemetryDevice;
@@ -148,16 +145,6 @@ return function (Container $container): void {
return new Webhook($publisher);
}, ['publisher']);
- $container->set('publisherForNotifications', fn (Publisher $publisher) => new NotificationPublisher(
- $publisher,
- new Queue(System::getEnv('_APP_NOTIFICATIONS_QUEUE_NAME', Event::NOTIFICATIONS_QUEUE_NAME))
- ), ['publisher']);
-
- $container->set('publisherForFunctions', fn (Publisher $publisher) => new FunctionPublisher(
- $publisher,
- new Queue(System::getEnv('_APP_FUNCTIONS_QUEUE_NAME', Event::FUNCTIONS_QUEUE_NAME), 'utopia-queue', Event::FUNCTIONS_QUEUE_TTL)
- ), ['publisher']);
-
$container->set('queueForRealtime', function () {
return new Realtime();
}, []);
diff --git a/bin/worker-mails b/bin/worker-mails
index a28b1ddc67..3b1415f45f 100644
--- a/bin/worker-mails
+++ b/bin/worker-mails
@@ -1,3 +1,3 @@
#!/bin/sh
-exec php /usr/src/code/app/worker.php mails "$@"
+exec php /usr/src/code/app/worker.php mails "$@"
\ No newline at end of file
diff --git a/bin/worker-notifications b/bin/worker-notifications
deleted file mode 100755
index 1b7bf28745..0000000000
--- a/bin/worker-notifications
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-exec php /usr/src/code/app/worker.php notifications "$@"
diff --git a/docker-compose.yml b/docker-compose.yml
index 9a43dc1dad..7ad12e7ddf 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -99,7 +99,6 @@ services:
- _APP_OPTIONS_FORCE_HTTPS
- _APP_OPTIONS_ROUTER_FORCE_HTTPS
- _APP_OPENSSL_KEY_V1
- - _APP_NOTIFICATIONS_TRACKING_SECRET
- _APP_DOMAIN
- _APP_CONSOLE_DOMAIN
- _APP_CONSOLE_TRUSTED_PROJECTS
@@ -748,7 +747,6 @@ services:
- _APP_WORKER_PER_CORE
- _APP_POOL_ADAPTER
- _APP_OPENSSL_KEY_V1
- - _APP_NOTIFICATIONS_TRACKING_SECRET
- _APP_SYSTEM_EMAIL_NAME
- _APP_SYSTEM_EMAIL_ADDRESS
- _APP_REDIS_HOST
@@ -771,48 +769,6 @@ services:
- _APP_OPTIONS_FORCE_HTTPS
- _APP_DATABASE_SHARED_TABLES
- appwrite-worker-notifications:
- entrypoint: worker-notifications
- logging:
- driver: json-file
- options:
- max-file: "5"
- max-size: 10m
- container_name: appwrite-worker-notifications
- restart: unless-stopped
- image: ${_APP_IMAGE:-appwrite/appwrite}:${_APP_VERSION:-latest}
- networks:
- - appwrite
- depends_on:
- - redis
- - ${_APP_DB_HOST:-mariadb}
- environment:
- - _APP_ENV
- - _APP_WORKER_PER_CORE
- - _APP_POOL_ADAPTER
- - _APP_OPENSSL_KEY_V1
- - _APP_NOTIFICATIONS_TRACKING_SECRET
- - _APP_SYSTEM_EMAIL_NAME
- - _APP_SYSTEM_EMAIL_ADDRESS
- - _APP_REDIS_HOST
- - _APP_REDIS_PORT
- - _APP_REDIS_USER
- - _APP_REDIS_PASS
- - _APP_DB_HOST
- - _APP_DB_PORT
- - _APP_DB_SCHEMA
- - _APP_DB_USER
- - _APP_DB_PASS
- - _APP_DB_ADAPTER
- - _APP_SMTP_HOST
- - _APP_SMTP_PORT
- - _APP_SMTP_SECURE
- - _APP_SMTP_USERNAME
- - _APP_SMTP_PASSWORD
- - _APP_LOGGING_CONFIG
- - _APP_DOMAIN
- - _APP_OPTIONS_FORCE_HTTPS
- - _APP_DATABASE_SHARED_TABLES
appwrite-worker-messaging:
entrypoint: worker-messaging
logging:
diff --git a/docs/references/health/get-queue-notifications.md b/docs/references/health/get-queue-notifications.md
deleted file mode 100644
index 529d1056e9..0000000000
--- a/docs/references/health/get-queue-notifications.md
+++ /dev/null
@@ -1 +0,0 @@
-Get the number of jobs in the notifications queue.
diff --git a/docs/references/notifications/get-logo.md b/docs/references/notifications/get-logo.md
deleted file mode 100644
index eadc755c69..0000000000
--- a/docs/references/notifications/get-logo.md
+++ /dev/null
@@ -1 +0,0 @@
-Get the Appwrite logo SVG used in notification emails. When loaded with a valid tracking token, the related notification is marked as read and its view timestamps are updated.
diff --git a/docs/references/notifications/list-notifications.md b/docs/references/notifications/list-notifications.md
deleted file mode 100644
index 3d9f93789c..0000000000
--- a/docs/references/notifications/list-notifications.md
+++ /dev/null
@@ -1 +0,0 @@
-Get the list of notifications for the currently logged in console user. Use queries to filter the results by attributes such as read status, view timestamps, or creation date.
diff --git a/docs/references/notifications/update-notification.md b/docs/references/notifications/update-notification.md
deleted file mode 100644
index 220c79b70e..0000000000
--- a/docs/references/notifications/update-notification.md
+++ /dev/null
@@ -1 +0,0 @@
-Update a notification by its unique ID. Use the `read` parameter to mark the notification as read or unread.
diff --git a/phpunit.xml b/phpunit.xml
index 56953fdeaf..32e865fe35 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -37,7 +37,6 @@
./tests/e2e/Services/ProjectWebhooks
./tests/e2e/Services/Messaging
./tests/e2e/Services/Migrations
- ./tests/e2e/Services/Notifications
./tests/e2e/Services/Project
./tests/e2e/Services/Advisor
./tests/e2e/Services/Functions/FunctionsBase.php
diff --git a/src/Appwrite/Docker/Compose.php b/src/Appwrite/Docker/Compose.php
index f879ad7aec..9ea6420d2d 100644
--- a/src/Appwrite/Docker/Compose.php
+++ b/src/Appwrite/Docker/Compose.php
@@ -4,7 +4,6 @@ namespace Appwrite\Docker;
use Appwrite\Docker\Compose\Service;
use Exception;
-use Spyc;
class Compose
{
@@ -15,8 +14,7 @@ class Compose
public function __construct(string $data)
{
- $compose = \function_exists('yaml_parse') ? \yaml_parse($data) : Spyc::YAMLLoadString($data);
- $this->compose = \is_array($compose) ? $compose : [];
+ $this->compose = yaml_parse($data);
$this->compose['services'] = (isset($this->compose['services']) && is_array($this->compose['services']))
? $this->compose['services'] : [];
diff --git a/src/Appwrite/Docker/Compose/Service.php b/src/Appwrite/Docker/Compose/Service.php
index 0ea84c12f6..e7993d6927 100644
--- a/src/Appwrite/Docker/Compose/Service.php
+++ b/src/Appwrite/Docker/Compose/Service.php
@@ -54,11 +54,6 @@ class Service
return substr($image, ((int)strpos($image, ':')) + 1);
}
- public function getEntrypoint(): string
- {
- return (isset($this->service['entrypoint'])) ? $this->service['entrypoint'] : '';
- }
-
/**
* @return Env
*/
diff --git a/src/Appwrite/Event/Event.php b/src/Appwrite/Event/Event.php
index 54841343e7..357442a07c 100644
--- a/src/Appwrite/Event/Event.php
+++ b/src/Appwrite/Event/Event.php
@@ -21,9 +21,6 @@ class Event
public const MAILS_QUEUE_NAME = 'v1-mails';
public const MAILS_CLASS_NAME = 'MailsV1';
- public const NOTIFICATIONS_QUEUE_NAME = 'v1-notifications';
- public const NOTIFICATIONS_CLASS_NAME = 'NotificationsV1';
-
public const FUNCTIONS_QUEUE_NAME = 'v1-functions';
public const FUNCTIONS_CLASS_NAME = 'FunctionsV1';
public const FUNCTIONS_QUEUE_TTL = 60 * 60 * 24 * 7; // 7 days
diff --git a/src/Appwrite/Event/Message/Notification.php b/src/Appwrite/Event/Message/Notification.php
deleted file mode 100644
index 644d29d300..0000000000
--- a/src/Appwrite/Event/Message/Notification.php
+++ /dev/null
@@ -1,116 +0,0 @@
- $recipients
- * @param array $channels
- * @param array $templateParams
- * @param array $permissions
- * @param array $variables
- * @param array $attachment
- * @param array $events
- * @param array $params
- * @param array $platform
- */
- public function __construct(
- public readonly ?Document $project = null,
- public readonly string $recipient = '',
- public readonly array $recipients = [],
- public readonly array $channels = [],
- public readonly string $template = '',
- public readonly array $templateParams = [],
- public readonly string $deduplicationKey = '',
- public readonly array $permissions = [],
- public readonly string $name = '',
- public readonly string $subject = '',
- public readonly string $bodyTemplate = '',
- public readonly string $body = '',
- public readonly string $preview = '',
- public readonly array $variables = [],
- public readonly array $attachment = [],
- public readonly array $events = [],
- public readonly string $event = '',
- public readonly array $params = [],
- public readonly array $platform = [],
- ) {
- }
-
- public function toArray(): array
- {
- $recipients = $this->recipients;
- if (empty($recipients) && $this->recipient !== '') {
- $recipients = [[
- 'address' => $this->recipient,
- 'channel' => NOTIFICATION_TYPE_EMAIL,
- ]];
- }
-
- $platform = !empty($this->platform) ? $this->platform : Config::getParam('platform', []);
-
- return [
- 'project' => $this->project === null ? null : [
- '$id' => $this->project->getId(),
- '$sequence' => $this->project->getSequence(),
- 'database' => $this->project->getAttribute('database'),
- ],
- 'recipient' => $this->recipient,
- 'recipients' => $recipients,
- 'channels' => $this->channels,
- 'template' => $this->template,
- 'templateParams' => $this->templateParams,
- 'deduplicationKey' => $this->deduplicationKey,
- 'permissions' => $this->permissions,
- 'name' => $this->name,
- 'subject' => $this->subject,
- 'bodyTemplate' => $this->bodyTemplate,
- 'body' => $this->body,
- 'preview' => $this->preview,
- 'variables' => $this->variables,
- 'attachment' => $this->attachment,
- 'events' => !empty($this->events) ? $this->events : $this->generateEvents(),
- 'platform' => $platform,
- ];
- }
-
- public static function fromArray(array $data): static
- {
- return new self(
- project: !empty($data['project']) ? new Document($data['project']) : null,
- recipient: $data['recipient'] ?? '',
- recipients: $data['recipients'] ?? [],
- channels: $data['channels'] ?? [],
- template: $data['template'] ?? '',
- templateParams: $data['templateParams'] ?? [],
- deduplicationKey: $data['deduplicationKey'] ?? '',
- permissions: $data['permissions'] ?? [],
- name: $data['name'] ?? '',
- subject: $data['subject'] ?? '',
- bodyTemplate: $data['bodyTemplate'] ?? '',
- body: $data['body'] ?? '',
- preview: $data['preview'] ?? '',
- variables: $data['variables'] ?? [],
- attachment: $data['attachment'] ?? [],
- events: $data['events'] ?? [],
- platform: $data['platform'] ?? [],
- );
- }
-
- /**
- * @return array
- */
- private function generateEvents(): array
- {
- if ($this->event === '') {
- return [];
- }
-
- return Event::generateEvents($this->event, $this->params);
- }
-}
diff --git a/src/Appwrite/Event/Publisher/Notification.php b/src/Appwrite/Event/Publisher/Notification.php
deleted file mode 100644
index 2fe0353276..0000000000
--- a/src/Appwrite/Event/Publisher/Notification.php
+++ /dev/null
@@ -1,27 +0,0 @@
-publish($queue ?? $this->queue, $message);
- }
-
- public function getSize(bool $failed = false, ?Queue $queue = null): int
- {
- return $this->getQueueSize($queue ?? $this->queue, $failed);
- }
-}
diff --git a/src/Appwrite/Migration/Version/V19.php b/src/Appwrite/Migration/Version/V19.php
index 6f939b4ce4..2526d03009 100644
--- a/src/Appwrite/Migration/Version/V19.php
+++ b/src/Appwrite/Migration/Version/V19.php
@@ -736,7 +736,6 @@ class V19 extends Migration
'resourceInternalId' => $document->getSequence(),
'resourceUpdatedAt' => DateTime::now(),
'projectId' => $this->project->getId(),
- 'projectInternalId' => $this->project->getSequence(),
'schedule' => $document->getAttribute('schedule'),
'active' => !empty($document->getAttribute('schedule')) && !empty($document->getAttribute('deployment')),
]));
diff --git a/src/Appwrite/Migration/Version/V24.php b/src/Appwrite/Migration/Version/V24.php
index ea1cd2088e..82889f8d79 100644
--- a/src/Appwrite/Migration/Version/V24.php
+++ b/src/Appwrite/Migration/Version/V24.php
@@ -90,12 +90,6 @@ class V24 extends Migration
};
$collections = $this->collections[$collectionType];
- $notificationsCollectionExists = false;
-
- if ($collectionType === 'console') {
- $notificationsCollectionExists = !$this->dbForProject->getCollection('notifications')->isEmpty();
- $this->createCollection('notifications');
- }
foreach ($collections as $collection) {
$id = $collection['$id'];
@@ -159,42 +153,6 @@ class V24 extends Migration
$this->dbForProject->purgeCachedCollection($id);
break;
- case 'schedules':
- if ($collectionType === 'console') {
- try {
- $this->createAttributeFromCollection($this->dbForProject, $id, 'projectInternalId');
- } catch (Throwable $th) {
- Console::warning("Failed to create attribute \"projectInternalId\" in collection {$id}: {$th->getMessage()}");
- }
-
- $indexes = [
- '_key_region_resourceType_projectInternalId_resourceId',
- '_key_project_internal_id_region',
- ];
- foreach ($indexes as $index) {
- try {
- $this->createIndexFromCollection($this->dbForProject, $id, $index);
- } catch (Throwable $th) {
- Console::warning("Failed to create index \"{$index}\" from {$id}: {$th->getMessage()}");
- }
- }
- }
- $this->dbForProject->purgeCachedCollection($id);
- break;
-
- case 'notifications':
- if ($collectionType === 'console' && $notificationsCollectionExists) {
- foreach (['firstSeen', 'lastSeen'] as $attribute) {
- try {
- $this->createAttributeFromCollection($this->dbForProject, $id, $attribute);
- } catch (Throwable $th) {
- Console::warning("Failed to create attribute \"{$attribute}\" in collection {$id}: {$th->getMessage()}");
- }
- }
- }
- $this->dbForProject->purgeCachedCollection($id);
- break;
-
case 'rules':
if ($collectionType === 'console') {
try {
@@ -495,17 +453,6 @@ class V24 extends Migration
$document->setAttribute('resourceInternalId', $projectInternalId);
}
break;
- case 'schedules':
- if (empty($document->getAttribute('projectInternalId'))) {
- $projectId = $document->getAttribute('projectId', '');
- if ($projectId !== '') {
- $project = $this->dbForProject->getDocument('projects', $projectId);
- if (!$project->isEmpty()) {
- $document->setAttribute('projectInternalId', $project->getSequence());
- }
- }
- }
- break;
default:
break;
}
diff --git a/src/Appwrite/Platform/Appwrite.php b/src/Appwrite/Platform/Appwrite.php
index f402050391..4bf3ed4768 100644
--- a/src/Appwrite/Platform/Appwrite.php
+++ b/src/Appwrite/Platform/Appwrite.php
@@ -11,7 +11,6 @@ use Appwrite\Platform\Modules\Databases;
use Appwrite\Platform\Modules\Functions;
use Appwrite\Platform\Modules\Health;
use Appwrite\Platform\Modules\Migrations;
-use Appwrite\Platform\Modules\Notifications;
use Appwrite\Platform\Modules\Organization;
use Appwrite\Platform\Modules\Presences;
use Appwrite\Platform\Modules\Project;
@@ -37,7 +36,6 @@ class Appwrite extends Platform
$this->addModule(new Presences\Module());
$this->addModule(new Functions\Module());
$this->addModule(new Health\Module());
- $this->addModule(new Notifications\Module());
$this->addModule(new Sites\Module());
$this->addModule(new Console\Module());
$this->addModule(new Proxy\Module());
diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php
index 303bf1484b..639b9ae2aa 100644
--- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php
+++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php
@@ -325,7 +325,6 @@ class Create extends Base
'resourceInternalId' => $execution->getSequence(),
'resourceUpdatedAt' => DateTime::now(),
'projectId' => $project->getId(),
- 'projectInternalId' => $project->getSequence(),
'schedule' => $scheduledAt,
'data' => $data,
'active' => true,
diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php
index e674b935c9..5222cba0b0 100644
--- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php
+++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php
@@ -276,7 +276,6 @@ class Create extends Base
'resourceInternalId' => $function->getSequence(),
'resourceUpdatedAt' => DateTime::now(),
'projectId' => $project->getId(),
- 'projectInternalId' => $project->getSequence(),
'schedule' => $function->getAttribute('schedule'),
'active' => false,
]))
diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php
index 5a6f3f8045..f45a762708 100644
--- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php
+++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php
@@ -325,7 +325,6 @@ class Update extends Base
'resourceInternalId' => $function->getSequence(),
'resourceUpdatedAt' => DateTime::now(),
'projectId' => $project->getId(),
- 'projectInternalId' => $project->getSequence(),
'schedule' => $function->getAttribute('schedule'),
'active' => false,
]))
@@ -338,7 +337,6 @@ class Update extends Base
}
$schedule
- ->setAttribute('projectInternalId', $project->getSequence())
->setAttribute('resourceUpdatedAt', DateTime::now())
->setAttribute('schedule', $function->getAttribute('schedule'))
->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deploymentId')));
diff --git a/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Failed/Get.php b/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Failed/Get.php
index 2746886bee..f0dff0a811 100644
--- a/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Failed/Get.php
+++ b/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Failed/Get.php
@@ -12,7 +12,6 @@ use Appwrite\Event\Publisher\Func as FunctionPublisher;
use Appwrite\Event\Publisher\Mail as MailPublisher;
use Appwrite\Event\Publisher\Messaging as MessagingPublisher;
use Appwrite\Event\Publisher\Migration as MigrationPublisher;
-use Appwrite\Event\Publisher\Notification as NotificationPublisher;
use Appwrite\Event\Publisher\Screenshot;
use Appwrite\Event\Publisher\StatsResources as StatsResourcesPublisher;
use Appwrite\Event\Publisher\Usage as UsagePublisher;
@@ -73,7 +72,6 @@ class Get extends Base
System::getEnv('_APP_SCREENSHOTS_QUEUE_NAME', Event::SCREENSHOTS_QUEUE_NAME),
System::getEnv('_APP_MESSAGING_QUEUE_NAME', Event::MESSAGING_QUEUE_NAME),
System::getEnv('_APP_MIGRATIONS_QUEUE_NAME', Event::MIGRATIONS_QUEUE_NAME),
- System::getEnv('_APP_NOTIFICATIONS_QUEUE_NAME', Event::NOTIFICATIONS_QUEUE_NAME),
]), 'The name of the queue', enum: new Enum(name: 'HealthQueueName'))
->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true)
->inject('response')
@@ -90,7 +88,6 @@ class Get extends Base
->inject('publisherForMessaging')
->inject('publisherForMigrations')
->inject('publisherForScreenshots')
- ->inject('publisherForNotifications')
->callback($this->action(...));
}
@@ -111,7 +108,6 @@ class Get extends Base
MessagingPublisher $publisherForMessaging,
MigrationPublisher $publisherForMigrations,
Screenshot $publisherForScreenshots,
- NotificationPublisher $publisherForNotifications,
): void {
$threshold = (int) $threshold;
@@ -129,7 +125,6 @@ class Get extends Base
System::getEnv('_APP_SCREENSHOTS_QUEUE_NAME', Event::SCREENSHOTS_QUEUE_NAME) => $publisherForScreenshots,
System::getEnv('_APP_MESSAGING_QUEUE_NAME', Event::MESSAGING_QUEUE_NAME) => $publisherForMessaging,
System::getEnv('_APP_MIGRATIONS_QUEUE_NAME', Event::MIGRATIONS_QUEUE_NAME) => $publisherForMigrations,
- System::getEnv('_APP_NOTIFICATIONS_QUEUE_NAME', Event::NOTIFICATIONS_QUEUE_NAME) => $publisherForNotifications,
default => throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Unknown queue name: ' . $name),
};
$failed = $queue->getSize(failed: true);
diff --git a/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Notifications/Get.php b/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Notifications/Get.php
deleted file mode 100644
index 50337cf9d0..0000000000
--- a/src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Notifications/Get.php
+++ /dev/null
@@ -1,60 +0,0 @@
-setHttpMethod(Base::HTTP_REQUEST_METHOD_GET)
- ->setHttpPath('/v1/health/queue/notifications')
- ->desc('Get notifications queue')
- ->groups(['api', 'health'])
- ->label('scope', 'health.read')
- ->label('sdk', new Method(
- namespace: 'health',
- group: 'queue',
- name: 'getQueueNotifications',
- description: '/docs/references/health/get-queue-notifications.md',
- auth: [AuthType::ADMIN, AuthType::KEY],
- responses: [
- new SDKResponse(
- code: Response::STATUS_CODE_OK,
- model: Response::MODEL_HEALTH_QUEUE,
- )
- ],
- contentType: ContentType::JSON
- ))
- ->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true)
- ->inject('publisherForNotifications')
- ->inject('response')
- ->callback($this->action(...));
- }
-
- public function action(int|string $threshold, NotificationPublisher $publisherForNotifications, Response $response): void
- {
- $threshold = (int) $threshold;
-
- $size = $publisherForNotifications->getSize();
-
- $this->assertQueueThreshold($size, $threshold);
-
- $response->dynamic(new Document(['size' => $size]), Response::MODEL_HEALTH_QUEUE);
- }
-}
diff --git a/src/Appwrite/Platform/Modules/Health/Services/Http.php b/src/Appwrite/Platform/Modules/Health/Services/Http.php
index a6acbcb4d4..54c6f9ad6d 100644
--- a/src/Appwrite/Platform/Modules/Health/Services/Http.php
+++ b/src/Appwrite/Platform/Modules/Health/Services/Http.php
@@ -19,7 +19,6 @@ use Appwrite\Platform\Modules\Health\Http\Health\Queue\Logs\Get as GetQueueLogs;
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Mails\Get as GetQueueMails;
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Messaging\Get as GetQueueMessaging;
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Migrations\Get as GetQueueMigrations;
-use Appwrite\Platform\Modules\Health\Http\Health\Queue\Notifications\Get as GetQueueNotifications;
use Appwrite\Platform\Modules\Health\Http\Health\Queue\StatsResources\Get as GetQueueStatsResources;
use Appwrite\Platform\Modules\Health\Http\Health\Queue\StatsUsage\Get as GetQueueUsage;
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Webhooks\Get as GetQueueWebhooks;
@@ -57,7 +56,6 @@ class Http extends Service
$this->addAction(GetQueueMails::getName(), new GetQueueMails());
$this->addAction(GetQueueMessaging::getName(), new GetQueueMessaging());
$this->addAction(GetQueueMigrations::getName(), new GetQueueMigrations());
- $this->addAction(GetQueueNotifications::getName(), new GetQueueNotifications());
$this->addAction(GetQueueFunctions::getName(), new GetQueueFunctions());
$this->addAction(GetQueueStatsResources::getName(), new GetQueueStatsResources());
$this->addAction(GetQueueUsage::getName(), new GetQueueUsage());
diff --git a/src/Appwrite/Platform/Modules/Notifications/Http/Notifications/Logos/Appwrite/Get.php b/src/Appwrite/Platform/Modules/Notifications/Http/Notifications/Logos/Appwrite/Get.php
deleted file mode 100644
index 7bb99c7ceb..0000000000
--- a/src/Appwrite/Platform/Modules/Notifications/Http/Notifications/Logos/Appwrite/Get.php
+++ /dev/null
@@ -1,209 +0,0 @@
-setHttpMethod(Action::HTTP_REQUEST_METHOD_GET)
- ->setHttpPath('/v1/notifications/logos/appwrite')
- ->desc('Get notification logo')
- ->groups(['api', 'notifications'])
- ->label('scope', 'public')
- ->label('sdk', new Method(
- namespace: 'notifications',
- group: 'logos',
- name: 'getLogo',
- description: '/docs/references/notifications/get-logo.md',
- auth: [],
- type: MethodType::LOCATION,
- responses: [
- new SDKResponse(
- code: Response::STATUS_CODE_OK,
- model: Response::MODEL_NONE,
- ),
- ],
- contentType: ContentType::IMAGE_SVG,
- ))
- ->param('jwt', '', new Text(2048, 0), 'Tracking token.', true)
- ->param('theme', 'system', new WhiteList(['system', 'light', 'dark']), 'Logo color theme.', true)
- ->inject('request')
- ->inject('response')
- ->inject('dbForPlatform')
- ->inject('authorization')
- ->inject('publisherForAudits')
- ->callback($this->action(...));
- }
-
- public function action(
- string $jwt,
- string $theme,
- Request $request,
- Response $response,
- Database $dbForPlatform,
- Authorization $authorization,
- AuditPublisher $publisherForAudits,
- ): void {
- $secret = System::getEnv('_APP_NOTIFICATIONS_TRACKING_SECRET');
-
- if (!empty($secret) && $jwt !== '') {
- try {
- $decoder = new JWT($secret, 'HS256', NOTIFICATION_TRACKING_JWT_TTL, 0);
- $decoded = $decoder->decode($jwt);
-
- $result = $authorization->skip(fn () => $this->trackView($decoded, $dbForPlatform));
-
- if ($result !== null) {
- $this->logView(
- $result['notification'],
- $result['project'],
- $result['seenAt'],
- $request,
- $publisherForAudits,
- );
- }
- } catch (\Throwable) {
- // Always return the logo and avoid exposing token validity.
- }
- }
-
- $response
- ->setContentType('image/svg+xml')
- ->addHeader('Cache-Control', 'no-store')
- ->send($this->renderLogo($theme));
- }
-
- /**
- * @return array{notification: Document, project: Document, seenAt: string}|null
- */
- private function trackView(array $decoded, Database $dbForPlatform): ?array
- {
- if (
- !isset($decoded['messageId'], $decoded['recipientHash'], $decoded['channel'], $decoded['projectId'], $decoded['purpose'])
- || $decoded['purpose'] !== 'notification_track'
- ) {
- return null;
- }
-
- $notifications = $dbForPlatform->find('notifications', [
- Query::equal('messageId', [(string) $decoded['messageId']]),
- Query::equal('channel', [(string) $decoded['channel']]),
- Query::equal('recipientHash', [(string) $decoded['recipientHash']]),
- Query::limit(1),
- ]);
-
- if (empty($notifications)) {
- return null;
- }
-
- $notification = $notifications[0];
- if (
- $notification->getAttribute('projectId') !== (string) $decoded['projectId']
- || (isset($decoded['projectInternalId']) && $notification->getAttribute('projectInternalId') !== (string) $decoded['projectInternalId'])
- ) {
- return null;
- }
-
- $seenAt = DateTime::now();
- $updates = [
- 'read' => true,
- 'lastSeen' => $seenAt,
- ];
-
- if (empty($notification->getAttribute('firstSeen'))) {
- $updates['firstSeen'] = $seenAt;
- }
-
- $updated = $dbForPlatform->updateDocument('notifications', $notification->getId(), new Document($updates));
- $project = $dbForPlatform->getDocument('projects', $notification->getAttribute('projectId'));
-
- if ($project->isEmpty()) {
- $project = new Document([
- '$id' => 'console',
- '$sequence' => 'console',
- ]);
- }
-
- return [
- 'notification' => $updated,
- 'project' => $project,
- 'seenAt' => $seenAt,
- ];
- }
-
- private function logView(Document $notification, Document $project, string $seenAt, Request $request, AuditPublisher $publisherForAudits): void
- {
- $publisherForAudits->enqueue(new AuditMessage(
- event: 'notification.view',
- payload: [
- 'notificationId' => $notification->getId(),
- 'messageId' => $notification->getAttribute('messageId', ''),
- 'channel' => $notification->getAttribute('channel', ''),
- 'projectId' => $notification->getAttribute('projectId', ''),
- 'firstSeen' => $notification->getAttribute('firstSeen'),
- 'lastSeen' => $notification->getAttribute('lastSeen'),
- 'seenAt' => $seenAt,
- ],
- project: $project,
- user: new Document([
- '$id' => $notification->getAttribute('resourceId', ''),
- '$sequence' => $notification->getAttribute('resourceInternalId', ''),
- 'name' => '',
- 'email' => '',
- 'type' => ACTOR_TYPE_HIDDEN,
- ]),
- resource: 'notification/' . $notification->getId(),
- mode: APP_MODE_DEFAULT,
- ip: $request->getIP(),
- userAgent: $request->getUserAgent(''),
- hostname: $request->getHostname(),
- ));
- }
-
- private function renderLogo(string $theme): string
- {
- $style = match ($theme) {
- 'light' => '.wordmark { fill: #19191C; }',
- 'dark' => '.wordmark { fill: #F5F5F7; }',
- default => '.wordmark { fill: #19191C; } @media (prefers-color-scheme: dark) { .wordmark { fill: #F5F5F7; } }',
- };
-
- return <<
-SVG;
- }
-}
diff --git a/src/Appwrite/Platform/Modules/Notifications/Http/Notifications/Update.php b/src/Appwrite/Platform/Modules/Notifications/Http/Notifications/Update.php
deleted file mode 100644
index 9ca7b6b683..0000000000
--- a/src/Appwrite/Platform/Modules/Notifications/Http/Notifications/Update.php
+++ /dev/null
@@ -1,87 +0,0 @@
-setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH)
- ->setHttpPath('/v1/notifications/:notificationId')
- ->desc('Update notification')
- ->groups(['api', 'notifications'])
- ->label('scope', 'account')
- ->label('sdk', new Method(
- namespace: 'notifications',
- group: null,
- name: 'update',
- description: '/docs/references/notifications/update-notification.md',
- auth: [AuthType::SESSION, AuthType::JWT],
- responses: [
- new SDKResponse(
- code: Response::STATUS_CODE_OK,
- model: Response::MODEL_NOTIFICATION,
- )
- ]
- ))
- ->param('notificationId', '', new UID(), 'Notification ID.')
- ->param('read', null, new Boolean(), 'Notification read status.')
- ->inject('response')
- ->inject('dbForPlatform')
- ->inject('authorization')
- ->inject('project')
- ->inject('user')
- ->callback($this->action(...));
- }
-
- public function action(
- string $notificationId,
- bool $read,
- Response $response,
- Database $dbForPlatform,
- Authorization $authorization,
- Document $project,
- Document $user,
- ): void {
- if ($project->getId() !== 'console') {
- throw new Exception(Exception::USER_UNAUTHORIZED);
- }
-
- $notification = $dbForPlatform->getDocument('notifications', $notificationId);
-
- if ($notification->isEmpty()) {
- $exists = $authorization->skip(fn () => !$dbForPlatform->getDocument('notifications', $notificationId)->isEmpty());
- if ($exists) {
- throw new Exception(Exception::USER_UNAUTHORIZED);
- }
- throw new Exception(Exception::DOCUMENT_NOT_FOUND);
- }
-
- $updated = $dbForPlatform->updateDocument('notifications', $notificationId, new Document([
- 'read' => $read,
- ]));
-
- $response->dynamic($updated, Response::MODEL_NOTIFICATION);
- }
-}
diff --git a/src/Appwrite/Platform/Modules/Notifications/Http/Notifications/XList.php b/src/Appwrite/Platform/Modules/Notifications/Http/Notifications/XList.php
deleted file mode 100644
index 558190d99a..0000000000
--- a/src/Appwrite/Platform/Modules/Notifications/Http/Notifications/XList.php
+++ /dev/null
@@ -1,118 +0,0 @@
-setHttpMethod(Action::HTTP_REQUEST_METHOD_GET)
- ->setHttpPath('/v1/notifications')
- ->desc('List notifications')
- ->groups(['api', 'notifications'])
- ->label('scope', 'account')
- ->label('sdk', new Method(
- namespace: 'notifications',
- group: null,
- name: 'list',
- description: '/docs/references/notifications/list-notifications.md',
- auth: [AuthType::SESSION, AuthType::JWT],
- responses: [
- new SDKResponse(
- code: Response::STATUS_CODE_OK,
- model: Response::MODEL_NOTIFICATION_LIST,
- )
- ]
- ))
- ->param('queries', [], new NotificationQueries(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', NotificationQueries::ALLOWED_ATTRIBUTES), true)
- ->inject('response')
- ->inject('dbForPlatform')
- ->inject('project')
- ->inject('user')
- ->callback($this->action(...));
- }
-
- /**
- * @param array $queries
- */
- public function action(
- array $queries,
- Response $response,
- Database $dbForPlatform,
- Document $project,
- Document $user
- ): void {
- if ($project->getId() !== 'console') {
- throw new Exception(Exception::USER_UNAUTHORIZED);
- }
-
- try {
- $queries = Query::parseQueries($queries);
- } catch (QueryException $e) {
- throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage());
- }
-
- $cursor = \array_filter($queries, function ($query) {
- return \in_array($query->getMethod(), [Query::TYPE_CURSOR_AFTER, Query::TYPE_CURSOR_BEFORE]);
- });
- $cursor = reset($cursor);
- if ($cursor) {
- /** @var Query $cursor */
-
- $validator = new Cursor();
- if (!$validator->isValid($cursor)) {
- throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription());
- }
-
- $notificationId = $cursor->getValue();
- $cursorDocument = $dbForPlatform->getDocument('notifications', $notificationId);
-
- if ($cursorDocument->isEmpty()) {
- throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Notification '{$notificationId}' for the 'cursor' value not found.");
- }
-
- $cursor->setValue($cursorDocument);
- }
-
- $queries[] = Query::equal('channel', [NOTIFICATION_TYPE_CONSOLE]);
- $queries[] = Query::equal('resourceType', [RESOURCE_TYPE_USERS]);
- $queries[] = Query::equal('resourceId', [$user->getId()]);
-
- $filterQueries = Query::groupByType($queries)['filters'];
-
- try {
- $results = $dbForPlatform->find('notifications', $queries);
- $total = $dbForPlatform->count('notifications', $filterQueries, APP_LIMIT_COUNT);
- } catch (OrderException $e) {
- throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null.");
- }
-
- $response->dynamic(new Document([
- 'notifications' => $results,
- 'total' => $total,
- ]), Response::MODEL_NOTIFICATION_LIST);
- }
-}
diff --git a/src/Appwrite/Platform/Modules/Notifications/Module.php b/src/Appwrite/Platform/Modules/Notifications/Module.php
deleted file mode 100644
index f4e1c574cc..0000000000
--- a/src/Appwrite/Platform/Modules/Notifications/Module.php
+++ /dev/null
@@ -1,14 +0,0 @@
-addService('http', new Http());
- }
-}
diff --git a/src/Appwrite/Platform/Modules/Notifications/Services/Http.php b/src/Appwrite/Platform/Modules/Notifications/Services/Http.php
deleted file mode 100644
index 91700ca125..0000000000
--- a/src/Appwrite/Platform/Modules/Notifications/Services/Http.php
+++ /dev/null
@@ -1,21 +0,0 @@
-type = Service::TYPE_HTTP;
-
- $this
- ->addAction(ListNotifications::getName(), new ListNotifications())
- ->addAction(UpdateNotification::getName(), new UpdateNotification())
- ->addAction(GetAppwriteLogo::getName(), new GetAppwriteLogo());
- }
-}
diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Labels/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Labels/Update.php
index 76c47a32f8..8a3506eb13 100644
--- a/src/Appwrite/Platform/Modules/Project/Http/Project/Labels/Update.php
+++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Labels/Update.php
@@ -71,7 +71,6 @@ class Update extends Action
$labels = (array) \array_values(\array_unique($labels));
$project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document(['labels' => $labels])));
- $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId()));
$response->dynamic($project, Response::MODEL_PROJECT);
}
diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Create.php
index 759dd931c0..f4002c60ef 100644
--- a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Create.php
+++ b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Create.php
@@ -101,7 +101,6 @@ class Create extends Action
]);
$authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates));
- $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId()));
$queueForEvents->setParam('number', $number);
diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Delete.php b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Delete.php
index f65a955b3d..0fb23e1764 100644
--- a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Delete.php
+++ b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Delete.php
@@ -95,7 +95,6 @@ class Delete extends Action
]);
$authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates));
- $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId()));
$queueForEvents->setParam('number', $number);
diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Update.php
index f2b618c39e..48b90a1b97 100644
--- a/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Update.php
+++ b/src/Appwrite/Platform/Modules/Project/Http/Project/MockPhone/Update.php
@@ -97,7 +97,6 @@ class Update extends Action
]);
$authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates));
- $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId()));
$queueForEvents->setParam('number', $number);
diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Team/Update.php b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Team/Update.php
index d2f7d5a29d..ab92d1a15f 100644
--- a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Team/Update.php
+++ b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Team/Update.php
@@ -78,7 +78,6 @@ class Update extends Action
'teamInternalId' => $team->getSequence(),
'$permissions' => $permissions,
]));
- $dbForPlatform->purgeCachedDocument('projects', $project->getId());
$installations = $dbForPlatform->find('installations', [
Query::equal('projectInternalId', [$project->getSequence()]),
diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Update.php b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Update.php
index c633a7adbf..f6df843d07 100644
--- a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Update.php
+++ b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Update.php
@@ -72,7 +72,6 @@ class Update extends Action
->setAttribute('legalAddress', $legalAddress)
->setAttribute('legalTaxId', $legalTaxId)
->setAttribute('search', implode(' ', [$projectId, $name])));
- $dbForPlatform->purgeCachedDocument('projects', $project->getId());
$response->dynamic($project, Response::MODEL_PROJECT);
}
diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Schedules/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/Schedules/Create.php
index 0d433ab5d9..7cf13c5ca2 100644
--- a/src/Appwrite/Platform/Modules/Projects/Http/Schedules/Create.php
+++ b/src/Appwrite/Platform/Modules/Projects/Http/Schedules/Create.php
@@ -132,7 +132,6 @@ class Create extends Action
'resourceInternalId' => $resource->getSequence(),
'resourceUpdatedAt' => DateTime::now(),
'projectId' => $project->getId(),
- 'projectInternalId' => $project->getSequence(),
'schedule' => $schedule,
'active' => $active,
];
diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Schedules/Get.php b/src/Appwrite/Platform/Modules/Projects/Http/Schedules/Get.php
index 05c4a925db..d14d4c361d 100644
--- a/src/Appwrite/Platform/Modules/Projects/Http/Schedules/Get.php
+++ b/src/Appwrite/Platform/Modules/Projects/Http/Schedules/Get.php
@@ -67,12 +67,7 @@ class Get extends Action
throw new Exception(Exception::SCHEDULE_NOT_FOUND);
}
- $projectInternalId = $schedule->getAttribute('projectInternalId');
-
- if (
- $schedule->getAttribute('projectId') !== $project->getId()
- || ($projectInternalId !== null && $projectInternalId !== '' && $projectInternalId !== $project->getSequence())
- ) {
+ if ($schedule->getAttribute('projectId') !== $project->getId()) {
throw new Exception(Exception::SCHEDULE_NOT_FOUND);
}
diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Schedules/XList.php b/src/Appwrite/Platform/Modules/Projects/Http/Schedules/XList.php
index 7f82162a2c..66879f798f 100644
--- a/src/Appwrite/Platform/Modules/Projects/Http/Schedules/XList.php
+++ b/src/Appwrite/Platform/Modules/Projects/Http/Schedules/XList.php
@@ -77,10 +77,6 @@ class XList extends Action
}
$queries[] = Query::equal('projectId', [$project->getId()]);
- $queries[] = Query::or([
- Query::equal('projectInternalId', [$project->getSequence()]),
- Query::isNull('projectInternalId'),
- ]);
$cursor = Query::getCursorQueries($queries, false);
$cursor = \reset($cursor);
@@ -94,11 +90,7 @@ class XList extends Action
$scheduleId = $cursor->getValue();
$cursorDocument = $dbForPlatform->getDocument('schedules', $scheduleId);
- if (
- $cursorDocument->isEmpty()
- || $cursorDocument->getAttribute('projectId') !== $project->getId()
- || !$this->matchesProjectInternalId($cursorDocument, $project)
- ) {
+ if ($cursorDocument->isEmpty()) {
throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Schedule '{$scheduleId}' for the 'cursor' value not found.");
}
@@ -119,13 +111,4 @@ class XList extends Action
'total' => $total,
]), Response::MODEL_SCHEDULE_LIST);
}
-
- private function matchesProjectInternalId(Document $schedule, Document $project): bool
- {
- $projectInternalId = $schedule->getAttribute('projectInternalId');
-
- return $projectInternalId === null
- || $projectInternalId === ''
- || $projectInternalId === $project->getSequence();
- }
}
diff --git a/src/Appwrite/Platform/Services/Workers.php b/src/Appwrite/Platform/Services/Workers.php
index 5af3d078de..fa77725f7a 100644
--- a/src/Appwrite/Platform/Services/Workers.php
+++ b/src/Appwrite/Platform/Services/Workers.php
@@ -10,7 +10,6 @@ use Appwrite\Platform\Workers\Functions;
use Appwrite\Platform\Workers\Mails;
use Appwrite\Platform\Workers\Messaging;
use Appwrite\Platform\Workers\Migrations;
-use Appwrite\Platform\Workers\Notifications;
use Appwrite\Platform\Workers\StatsResources;
use Appwrite\Platform\Workers\StatsUsage;
use Appwrite\Platform\Workers\Webhooks;
@@ -29,7 +28,6 @@ class Workers extends Service
->addAction(Functions::getName(), new Functions())
->addAction(Mails::getName(), new Mails())
->addAction(Messaging::getName(), new Messaging())
- ->addAction(Notifications::getName(), new Notifications())
->addAction(Webhooks::getName(), new Webhooks())
->addAction(StatsUsage::getName(), new StatsUsage())
->addAction(Migrations::getName(), new Migrations())
diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php
index 403e695603..1ac808c682 100644
--- a/src/Appwrite/Platform/Workers/Deletes.php
+++ b/src/Appwrite/Platform/Workers/Deletes.php
@@ -788,17 +788,6 @@ class Deletes extends Action
Console::error('Failed to delete schedules: ' . $th->getMessage());
}
- // Delete Notifications
- try {
- $this->deleteByGroup('notifications', [
- Query::equal('projectId', [$projectId]),
- Query::equal('projectInternalId', [$projectInternalId]),
- Query::orderAsc()
- ], $dbForPlatform);
- } catch (Throwable $th) {
- Console::error('Failed to delete notifications: ' . $th->getMessage());
- }
-
// Delete Advisor insights
try {
$this->deleteByGroup('insights', [
diff --git a/src/Appwrite/Platform/Workers/Notifications.php b/src/Appwrite/Platform/Workers/Notifications.php
deleted file mode 100644
index 04f705e2d1..0000000000
--- a/src/Appwrite/Platform/Workers/Notifications.php
+++ /dev/null
@@ -1,661 +0,0 @@
-
- */
- protected array $richTextParams = [
- 'b' => '',
- '/b' => '',
- ];
-
- public static function getName(): string
- {
- return 'notifications';
- }
-
- public function __construct()
- {
- $this
- ->desc('Notifications worker')
- ->inject('message')
- ->inject('project')
- ->inject('register')
- ->inject('dbForPlatform')
- ->inject('log')
- ->callback($this->action(...));
- }
-
- public function action(Message $message, Document $project, Registry $register, Database $dbForPlatform, Log $log): void
- {
- if (\class_exists(Runtime::class)) {
- Runtime::setHookFlags(SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_TCP);
- }
- $payload = $message->getPayload();
-
- if (empty($payload)) {
- throw new Exception('Missing payload');
- }
-
- $deduplicationKey = $payload['deduplicationKey'] ?? '';
- $messageId = $deduplicationKey !== '' ? \md5($deduplicationKey) : '';
-
- $recipients = $this->resolveRecipients($payload);
- if (empty($recipients)) {
- throw new Exception('No recipients in payload');
- }
-
- $failure = null;
- foreach ($recipients as $recipient) {
- $recipient = $this->normalizeRecipient($recipient, $project);
- $channel = $recipient['channel'];
-
- if ($messageId !== '') {
- if ($channel === NOTIFICATION_TYPE_CONSOLE) {
- $this->validateConsoleRecipient($recipient);
- }
- $this->validateAlertResource($recipient);
- }
-
- if ($messageId !== '' && $this->alreadyDelivered($dbForPlatform, self::buildAlertId($messageId, $recipient))) {
- $log->addTag('dedup', 'hit');
- $log->addTag('channel', $channel);
- continue;
- }
-
- try {
- $alertId = $this->dispatch($recipient, $messageId, $payload, $project, $register, $dbForPlatform, $log);
- if ($messageId !== '' && $channel === NOTIFICATION_TYPE_WEBHOOK && $alertId === null) {
- $this->persistAlert($dbForPlatform, $messageId, $recipient, $payload, $project);
- }
- } catch (Throwable $error) {
- $log->addTag('channel', $channel);
- $log->addTag('error', $error->getMessage());
- $failure ??= $error;
- }
- }
-
- if ($failure !== null) {
- throw $failure;
- }
- }
-
- /**
- * @return array
- */
- private function resolveRecipients(array $payload): array
- {
- $recipients = $payload['recipients'] ?? [];
- if (!empty($recipients)) {
- return $recipients;
- }
-
- $address = $payload['recipient'] ?? '';
- if ($address === '') {
- return [];
- }
-
- return [['address' => $address, 'channel' => NOTIFICATION_TYPE_EMAIL]];
- }
-
- /**
- * @param array{address: string, channel: string, signatureKey?: string, resourceType?: string, resourceId?: string, resourceInternalId?: string, parentResourceType?: string, parentResourceId?: string, parentResourceInternalId?: string} $recipient
- * @return array{address: string, channel: string, signatureKey?: string, resourceType: string, resourceId: string, resourceInternalId: string, parentResourceType: string, parentResourceId: string, parentResourceInternalId: string}
- */
- private function normalizeRecipient(array $recipient, Document $project): array
- {
- $recipient['resourceType'] = $recipient['resourceType'] ?? '';
- $recipient['resourceId'] = $recipient['resourceId'] ?? '';
- $recipient['resourceInternalId'] = $recipient['resourceInternalId'] ?? '';
- $recipient['parentResourceType'] = $recipient['parentResourceType'] ?? RESOURCE_TYPE_PROJECTS;
- $recipient['parentResourceId'] = $recipient['parentResourceId'] ?? (string) $project->getId();
- $recipient['parentResourceInternalId'] = $recipient['parentResourceInternalId'] ?? (string) $project->getSequence();
-
- if (
- $recipient['channel'] === NOTIFICATION_TYPE_CONSOLE
- && $recipient['resourceId'] === ''
- ) {
- $recipient['resourceType'] = RESOURCE_TYPE_USERS;
- $recipient['resourceId'] = $recipient['address'];
- }
-
- foreach (['resourceType', 'resourceId', 'resourceInternalId', 'parentResourceType', 'parentResourceId', 'parentResourceInternalId'] as $key) {
- $recipient[$key] = (string) $recipient[$key];
- }
-
- return $recipient;
- }
-
- private function alreadyDelivered(Database $dbForPlatform, string $alertId): bool
- {
- return !$dbForPlatform->getDocument('notifications', $alertId)->isEmpty();
- }
-
- /**
- * Dispatch a single recipient through the channel-appropriate adapter.
- *
- * Returns the alertId when the dispatcher (or its adapter) has already
- * persisted an alert row, so the action loop knows to skip persistence.
- * Returns null when persistence is the caller's responsibility.
- *
- * @param array{address: string, channel: string, signatureKey?: string, resourceType: string, resourceId: string, resourceInternalId: string, parentResourceType: string, parentResourceId: string, parentResourceInternalId: string} $recipient
- */
- protected function dispatch(
- array $recipient,
- string $messageId,
- array $payload,
- Document $project,
- Registry $register,
- Database $dbForPlatform,
- Log $log,
- ): ?string {
- $channel = $recipient['channel'];
-
- return match ($channel) {
- NOTIFICATION_TYPE_EMAIL => $this->dispatchEmail($recipient, $messageId, $payload, $project, $register, $dbForPlatform, $log),
- NOTIFICATION_TYPE_CONSOLE => $this->dispatchConsole($recipient, $messageId, $payload, $project, $dbForPlatform),
- NOTIFICATION_TYPE_WEBHOOK => $this->dispatchWebhook($recipient, $payload, $log),
- default => throw new Exception('Unsupported notification channel: ' . $channel),
- };
- }
-
- /**
- * @param array{address: string, channel: string, signatureKey?: string, resourceType: string, resourceId: string, resourceInternalId: string, parentResourceType: string, parentResourceId: string, parentResourceInternalId: string} $recipient
- */
- protected function dispatchEmail(
- array $recipient,
- string $messageId,
- array $payload,
- Document $project,
- Registry $register,
- Database $dbForPlatform,
- Log $log,
- ): ?string {
- $address = $recipient['address'];
- $smtp = $this->resolveSmtpConfig($project, $payload);
-
- if (empty($smtp) && empty(System::getEnv('_APP_SMTP_HOST'))) {
- $log->addTag('email_skipped', 'no_smtp');
- throw new Exception('Skipped mail processing. No SMTP configuration has been set.');
- }
-
- $type = empty($smtp) ? 'cloud' : 'smtp';
- $log->addTag('type', $type);
-
- $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS', 'disabled') === 'disabled' ? 'http' : 'https';
- $consoleHostname = System::getEnv('_APP_CONSOLE_DOMAIN', System::getEnv('_APP_DOMAIN', 'localhost'));
-
- $subject = $payload['subject'] ?? '';
- $variables = $payload['variables'] ?? [];
- $variables = \array_merge($variables, $payload['templateParams'] ?? []);
- $variables['host'] = $protocol . '://' . $consoleHostname;
- $name = $payload['name'] ?? '';
- $body = $payload['body'] ?? '';
- $preview = $payload['preview'] ?? '';
-
- $variables['subject'] = $subject;
- $variables['heading'] = $variables['heading'] ?? $subject;
- $variables['year'] = \date('Y');
-
- $attachment = $payload['attachment'] ?? [];
- $bodyTemplate = $payload['bodyTemplate'] ?? '';
- if (empty($bodyTemplate)) {
- $bodyTemplate = $payload['template'] ?? '';
- }
- if (empty($bodyTemplate)) {
- $bodyTemplate = __DIR__ . '/../../../../app/config/locale/templates/email-base.tpl';
- }
-
- $bodyTemplate = Template::fromFile($bodyTemplate);
- $bodyTemplate->setParam('{{body}}', $body, escapeHtml: false);
- foreach ($variables as $key => $value) {
- $bodyTemplate->setParam('{{' . $key . '}}', $value, escapeHtml: $key !== 'redirect');
- }
- foreach ($this->richTextParams as $key => $value) {
- $bodyTemplate->setParam('{{' . $key . '}}', $value, escapeHtml: false);
- }
-
- $previewWhitespace = '';
- if (!empty($preview)) {
- $previewTemplate = Template::fromString($preview);
- foreach ($variables as $key => $value) {
- $previewTemplate->setParam('{{' . $key . '}}', $value);
- }
- $preview = \strip_tags($previewTemplate->render());
-
- $previewLen = \strlen($preview);
- if ($previewLen < $this->previewMaxLen) {
- $previewWhitespace = \str_repeat($this->whitespaceCodes, $this->previewMaxLen - $previewLen);
- }
- }
-
- $bodyTemplate->setParam('{{preview}}', $preview);
- $bodyTemplate->setParam('{{previewWhitespace}}', $previewWhitespace, false);
-
- $body = $bodyTemplate->render();
-
- $subjectTemplate = Template::fromString($subject);
- foreach ($variables as $key => $value) {
- $subjectTemplate->setParam('{{' . $key . '}}', $value);
- }
- $subject = \strip_tags($subjectTemplate->render());
-
- $recipientHash = self::buildRecipientHash($recipient);
- $trackingSecret = System::getEnv('_APP_NOTIFICATIONS_TRACKING_SECRET');
- if ($messageId !== '' && !empty($trackingSecret)) {
- $body = $this->injectTrackingLogo($body, $messageId, $recipient['channel'], $recipientHash, $project, $trackingSecret);
- }
-
- /** @var EmailAdapter $adapter */
- $adapter = empty($smtp)
- ? $register->get('smtp')
- : new SMTP(
- host: $smtp['host'],
- port: (int) $smtp['port'],
- username: $smtp['username'] ?? '',
- password: $smtp['password'] ?? '',
- smtpSecure: $smtp['secure'] ?? '',
- smtpAutoTLS: false,
- xMailer: 'Appwrite Mailer',
- timeout: 10,
- keepAlive: true,
- timelimit: 30,
- );
-
- $defaultFromEmail = System::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM);
- $defaultFromName = \urldecode(System::getEnv('_APP_SYSTEM_EMAIL_NAME', APP_NAME . ' Server'));
-
- $fromEmail = !empty($smtp) ? ($smtp['senderEmail'] ?? $defaultFromEmail) : $defaultFromEmail;
- $fromName = !empty($smtp) ? ($smtp['senderName'] ?? $defaultFromName) : $defaultFromName;
- $replyTo = $defaultFromEmail;
- $replyToName = $defaultFromName;
-
- $customMailOptions = $payload['customMailOptions'] ?? [];
- if (!\is_array($customMailOptions)) {
- $customMailOptions = [];
- }
-
- if (!empty($customMailOptions['senderEmail'])) {
- $fromEmail = (string) $customMailOptions['senderEmail'];
- }
- if (!empty($customMailOptions['senderName'])) {
- $fromName = (string) $customMailOptions['senderName'];
- }
-
- if (!empty($customMailOptions['replyToEmail']) || !empty($customMailOptions['replyToName'])) {
- $replyTo = (string) ($customMailOptions['replyToEmail'] ?? $replyTo);
- $replyToName = (string) ($customMailOptions['replyToName'] ?? $replyToName);
- } elseif (!empty($smtp)) {
- $smtpReplyToEmail = $smtp['replyToEmail'] ?? $smtp['replyTo'] ?? '';
- $replyTo = !empty($smtpReplyToEmail) ? $smtpReplyToEmail : ($smtp['senderEmail'] ?? $replyTo);
- $replyToName = !empty($smtp['replyToName']) ? $smtp['replyToName'] : ($smtp['senderName'] ?? $replyToName);
- }
-
- $attachments = null;
- if (!empty($attachment['content'] ?? '')) {
- $attachments = [
- new Attachment(
- name: $attachment['filename'] ?? 'unknown.file',
- path: '',
- type: $attachment['type'] ?? 'plain/text',
- content: \base64_decode($attachment['content']),
- ),
- ];
- }
-
- $emailMessage = new EmailMessage(
- to: [['email' => $address, 'name' => $name]],
- subject: $subject,
- content: $body,
- fromName: $fromName,
- fromEmail: $fromEmail,
- replyToName: $replyToName,
- replyToEmail: $replyTo,
- attachments: $attachments,
- html: true,
- );
-
- try {
- $adapter->send($emailMessage);
- } catch (Throwable $error) {
- throw new Exception('Error sending notification: ' . $error->getMessage(), $type === 'smtp' ? 401 : 500);
- }
-
- if ($messageId !== '') {
- return $this->persistAlert($dbForPlatform, $messageId, $recipient, $payload, $project);
- }
-
- return null;
- }
-
- /**
- * @param array{address: string, channel: string, signatureKey?: string, resourceType: string, resourceId: string, resourceInternalId: string, parentResourceType: string, parentResourceId: string, parentResourceInternalId: string} $recipient
- */
- protected function dispatchConsole(array $recipient, string $messageId, array $payload, Document $project, Database $dbForPlatform): ?string
- {
- $this->validateConsoleRecipient($recipient);
-
- $params = $payload['templateParams'] ?? ($payload['variables'] ?? []);
- $title = self::renderText($payload['subject'] ?? '', $params);
- $body = self::renderText($payload['preview'] ?? '', $params);
- if ($body === '') {
- $body = self::renderText($payload['body'] ?? '', $params);
- }
-
- $alertId = $messageId !== '' ? self::buildAlertId($messageId, $recipient) : null;
- $recipientHash = $messageId !== '' ? self::buildRecipientHash($recipient) : null;
-
- $consoleRecipient = [
- 'address' => $recipient['address'],
- 'resourceType' => $recipient['resourceType'],
- 'resourceId' => $recipient['resourceId'],
- 'resourceInternalId' => $recipient['resourceInternalId'],
- 'parentResourceType' => $recipient['parentResourceType'],
- 'parentResourceId' => $recipient['parentResourceId'],
- 'parentResourceInternalId' => $recipient['parentResourceInternalId'],
- ];
- if ($alertId !== null) {
- $consoleRecipient['alertId'] = $alertId;
- $consoleRecipient['recipientHash'] = $recipientHash;
- }
-
- $consoleMessage = new ConsoleMessage(
- recipients: [$consoleRecipient],
- title: $title,
- body: $body,
- type: $payload['type'] ?? 'info',
- messageId: $messageId !== '' ? $messageId : null,
- projectId: $project->getId(),
- projectInternalId: $project->getSequence(),
- );
-
- $adapter = new ConsoleAdapter($dbForPlatform);
- $result = $adapter->send($consoleMessage);
-
- if (($result['deliveredTo'] ?? 0) === 0) {
- $error = $result['results'][0]['error'] ?? 'unknown error';
- throw new Exception('Console alert delivery failed: ' . $error);
- }
-
- return $alertId;
- }
-
- /**
- * @param array{address: string, channel: string, signatureKey?: string, resourceType: string, resourceId: string, resourceInternalId: string, parentResourceType: string, parentResourceId: string, parentResourceInternalId: string} $recipient
- */
- protected function dispatchWebhook(array $recipient, array $payload, Log $log): ?string
- {
- $address = $recipient['address'];
- $signatureKey = $recipient['signatureKey'] ?? null;
-
- $body = [
- 'subject' => $payload['subject'] ?? '',
- 'body' => $payload['body'] ?? '',
- 'template' => $payload['template'] ?? '',
- 'params' => $payload['templateParams'] ?? [],
- 'project' => \is_array($payload['project'] ?? null) ? ($payload['project']['$id'] ?? null) : null,
- 'deduplicationKey' => $payload['deduplicationKey'] ?? '',
- 'events' => $payload['events'] ?? [],
- ];
-
- if ($signatureKey === null || $signatureKey === '') {
- $log->addTag('webhook_signed', 'false');
- }
-
- $message = new WebhookMessage(
- urls: [$address],
- payload: $body,
- signingSecret: $signatureKey,
- );
-
- $adapter = new WebhookAdapter();
- $result = $adapter->send($message);
-
- if (($result['deliveredTo'] ?? 0) === 0) {
- $error = $result['results'][0]['error'] ?? 'Unknown error';
- throw new Exception('Webhook delivery failed: ' . $error);
- }
-
- // Caller persists the alert AFTER successful dispatch.
- return null;
- }
-
- /**
- * Persist an alert row. Returns the alertId so callers can reference the row.
- *
- * Idempotent: on a duplicate composite-key violation the existing
- * row's id is returned.
- *
- * @param array{address: string, channel: string, signatureKey?: string, resourceType?: string, resourceId?: string, resourceInternalId?: string, parentResourceType?: string, parentResourceId?: string, parentResourceInternalId?: string} $recipient
- */
- protected function persistAlert(Database $dbForPlatform, string $messageId, array $recipient, array $payload, Document $project): string
- {
- $recipient = $this->normalizeRecipient($recipient, $project);
-
- $channel = $recipient['channel'];
-
- $alertId = self::buildAlertId($messageId, $recipient);
- $recipientHash = self::buildRecipientHash($recipient);
-
- $permissions = $this->buildAlertPermissions($recipient['resourceType'], $recipient['resourceId'], $project->getId());
- if (empty($permissions)) {
- $permissions = $payload['permissions'] ?? [];
- }
-
- $params = $payload['templateParams'] ?? ($payload['variables'] ?? []);
- $body = self::renderText($payload['preview'] ?? '', $params);
- if ($body === '') {
- $body = self::renderText($payload['body'] ?? '', $params);
- }
-
- $document = new Document([
- '$id' => $alertId,
- '$permissions' => $permissions,
- 'messageId' => $messageId,
- 'recipientHash' => $recipientHash,
- 'type' => $payload['type'] ?? 'info',
- 'channel' => $channel,
- 'projectId' => $project->getId(),
- 'projectInternalId' => $project->getSequence(),
- 'resourceType' => $recipient['resourceType'],
- 'resourceId' => $recipient['resourceId'],
- 'resourceInternalId' => $recipient['resourceInternalId'],
- 'parentResourceType' => $recipient['parentResourceType'],
- 'parentResourceId' => $recipient['parentResourceId'],
- 'parentResourceInternalId' => $recipient['parentResourceInternalId'],
- 'title' => self::renderText($payload['subject'] ?? '', $params),
- 'body' => $body,
- 'read' => false,
- ]);
-
- try {
- $dbForPlatform->createDocument('notifications', $document);
- return $alertId;
- } catch (DuplicateException) {
- $existing = $dbForPlatform->getDocument('notifications', $alertId);
- return $existing->isEmpty() ? $alertId : $existing->getId();
- }
- }
-
- /**
- * Build the deterministic alertId composed of the messageId plus a
- * recipient hash.
- *
- * @param array{address: string, channel: string, signatureKey?: string, resourceType: string, resourceId: string, resourceInternalId: string, parentResourceType: string, parentResourceId: string, parentResourceInternalId: string} $recipient
- */
- private static function buildAlertId(string $messageId, array $recipient): string
- {
- return \substr($messageId, 0, 19) . '_' . self::buildRecipientHash($recipient);
- }
-
- /**
- * @param array{address: string, channel: string, signatureKey?: string, resourceType: string, resourceId: string, resourceInternalId: string, parentResourceType: string, parentResourceId: string, parentResourceInternalId: string} $recipient
- */
- private static function buildRecipientHash(array $recipient): string
- {
- $channel = $recipient['channel'];
- $address = $recipient['address'];
-
- return \substr(\md5(
- $channel
- . ':' . $address
- . ':' . $recipient['resourceType']
- . ':' . $recipient['resourceId']
- . ':' . $recipient['resourceInternalId']
- . ':' . $recipient['parentResourceType']
- . ':' . $recipient['parentResourceId']
- . ':' . $recipient['parentResourceInternalId']
- ), 0, 16);
- }
-
- /**
- * @return array
- */
- private function buildAlertPermissions(string $resourceType, string $resourceId, string $projectId): array
- {
- $permissions = [];
- if ($resourceType === RESOURCE_TYPE_USERS) {
- $permissions[] = Permission::read(Role::user($resourceId));
- $permissions[] = Permission::update(Role::user($resourceId));
- $permissions[] = Permission::delete(Role::user($resourceId));
- }
- if ($resourceType === RESOURCE_TYPE_TEAMS) {
- $permissions[] = Permission::read(Role::team($resourceId));
- $permissions[] = Permission::update(Role::team($resourceId, 'owner'));
- $permissions[] = Permission::delete(Role::team($resourceId, 'owner'));
- if ($projectId !== '') {
- $permissions[] = Permission::read(Role::team($resourceId, 'project-' . $projectId . '-owner'));
- $permissions[] = Permission::update(Role::team($resourceId, 'project-' . $projectId . '-owner'));
- $permissions[] = Permission::delete(Role::team($resourceId, 'project-' . $projectId . '-owner'));
- }
- }
- return $permissions;
- }
-
- /**
- * @param array $payload
- * @return array
- */
- private function resolveSmtpConfig(Document $project, array $payload): array
- {
- $payloadSmtp = $payload['smtp'] ?? [];
- if (\is_array($payloadSmtp) && !empty($payloadSmtp)) {
- return $payloadSmtp;
- }
-
- $smtp = $project->getAttribute('smtp', []);
- if (!\is_array($smtp) || empty($smtp['enabled'] ?? false)) {
- return [];
- }
-
- return [
- 'host' => $smtp['host'] ?? '',
- 'port' => $smtp['port'] ?? '',
- 'username' => $smtp['username'] ?? '',
- 'password' => $smtp['password'] ?? '',
- 'secure' => $smtp['secure'] ?? '',
- 'senderEmail' => $smtp['senderEmail'] ?? '',
- 'senderName' => $smtp['senderName'] ?? '',
- 'replyToEmail' => $smtp['replyToEmail'] ?? $smtp['replyTo'] ?? '',
- 'replyToName' => $smtp['replyToName'] ?? '',
- ];
- }
-
- private function validateConsoleRecipient(array $recipient): void
- {
- $validator = new UID();
-
- if (!$validator->isValid($recipient['resourceId'])) {
- throw new Exception('Invalid console alert resourceId: ' . $validator->getDescription());
- }
- }
-
- /**
- * @param array{address: string, channel: string, signatureKey?: string, resourceType: string, resourceId: string, resourceInternalId: string, parentResourceType: string, parentResourceId: string, parentResourceInternalId: string} $recipient
- */
- private function validateAlertResource(array $recipient): void
- {
- foreach (['resourceType', 'resourceId', 'resourceInternalId', 'parentResourceType', 'parentResourceId', 'parentResourceInternalId'] as $key) {
- if ($recipient[$key] === '') {
- throw new Exception('Missing notification ' . $key);
- }
- }
- }
-
- private static function renderText(string $value, array $params): string
- {
- if ($value !== '' && !empty($params)) {
- $template = Template::fromString($value);
- foreach ($params as $key => $param) {
- $template->setParam('{{' . $key . '}}', (string) $param);
- }
- $value = $template->render();
- }
-
- return \trim(\strip_tags($value));
- }
-
- /**
- * Splice a visible tracking logo before the last `