mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge branch 'feat-mailgun-provider' into feat-topics-controller
This commit is contained in:
@@ -108,10 +108,10 @@ App::post('/v1/messaging/providers/mailgun')
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $providerId, string $name, string $apiKey, string $domain, Database $dbForProject, Response $response) {
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
'provider' => 'mailgun',
|
||||
'type' => 'email',
|
||||
'credentials' => [
|
||||
@@ -198,10 +198,10 @@ App::post('/v1/messaging/providers/sendgrid')
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $providerId, string $name, string $apiKey, Database $dbForProject, Response $response) {
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
'provider' => 'sendgrid',
|
||||
'type' => 'email',
|
||||
'credentials' => [
|
||||
@@ -276,17 +276,17 @@ App::post('/v1/messaging/providers/msg91')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_CREATED)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_PROVIDER)
|
||||
->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.')
|
||||
->param('providerId', '', new CustomId(), 'Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.')
|
||||
->param('name', '', new Text(128), 'Provider name.')
|
||||
->param('senderId', '', new Text(0), 'Msg91 Sender ID.')
|
||||
->param('authKey', '', new Text(0), 'Msg91 Auth Key.')
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $providerId, string $name, string $senderId, string $authKey, Database $dbForProject, Response $response) {
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
'provider' => 'msg91',
|
||||
'type' => 'sms',
|
||||
'credentials' => [
|
||||
@@ -374,10 +374,10 @@ App::post('/v1/messaging/providers/telesign')
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $providerId, string $name, string $username, string $password, Database $dbForProject, Response $response) {
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
'provider' => 'telesign',
|
||||
'type' => 'sms',
|
||||
'credentials' => [
|
||||
@@ -465,10 +465,10 @@ App::post('/v1/messaging/providers/textmagic')
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $providerId, string $name, string $username, string $apiKey, Database $dbForProject, Response $response) {
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
'provider' => 'text-magic',
|
||||
'type' => 'sms',
|
||||
'credentials' => [
|
||||
@@ -556,10 +556,10 @@ App::post('/v1/messaging/providers/twilio')
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $providerId, string $name, string $accountSid, string $authToken, Database $dbForProject, Response $response) {
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
'provider' => 'twilio',
|
||||
'type' => 'sms',
|
||||
'credentials' => [
|
||||
@@ -647,10 +647,10 @@ App::post('/v1/messaging/providers/vonage')
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $providerId, string $name, string $apiKey, string $apiSecret, Database $dbForProject, Response $response) {
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
'provider' => 'vonage',
|
||||
'type' => 'sms',
|
||||
'credentials' => [
|
||||
@@ -740,10 +740,10 @@ App::post('/v1/messaging/providers/fcm')
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $providerId, string $name, string $serverKey, Database $dbForProject, Response $response) {
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
'provider' => 'fcm',
|
||||
'type' => 'push',
|
||||
'credentials' => [
|
||||
@@ -823,10 +823,10 @@ App::post('/v1/messaging/providers/apns')
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $providerId, string $name, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Database $dbForProject, Response $response) {
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
$provider = $dbForProject->createDocument('providers', new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
'provider' => 'apns',
|
||||
'type' => 'push',
|
||||
'credentials' => [
|
||||
|
||||
+4
-4
@@ -567,8 +567,8 @@ Database::addFilter(
|
||||
->find('subscribers', [
|
||||
Query::equal('targetInternalId', [$document->getInternalId()]),
|
||||
Query::limit(APP_LIMIT_SUBQUERY),
|
||||
]))
|
||||
);
|
||||
])
|
||||
));
|
||||
if (\count($topicIds) > 0) {
|
||||
return $database->find('topics', [Query::equal('$id', $topicIds)]);
|
||||
}
|
||||
@@ -588,8 +588,8 @@ Database::addFilter(
|
||||
->find('subscribers', [
|
||||
Query::equal('topicInternalId', [$document->getInternalId()]),
|
||||
Query::limit(APP_LIMIT_SUBQUERY),
|
||||
]))
|
||||
);
|
||||
])
|
||||
));
|
||||
if (\count($targetIds) > 0) {
|
||||
return $database->find('targets', [Query::equal('$id', $targetIds)]);
|
||||
}
|
||||
|
||||
@@ -193,49 +193,49 @@ trait MessagingBase
|
||||
|
||||
public function testCreateTopic(): string
|
||||
{
|
||||
$provider = $this->client->call(Client::METHOD_POST, '/messaging/providers/sendgrid', \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
]), [
|
||||
'id' => 'unique()',
|
||||
'name' => 'Sengrid1',
|
||||
'apiKey' => 'my-apikey',
|
||||
]);
|
||||
$this->assertEquals(201, $provider['headers']['status-code']);
|
||||
$provider = $this->client->call(Client::METHOD_POST, '/messaging/providers/sendgrid', \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
]), [
|
||||
'id' => 'unique()',
|
||||
'name' => 'Sengrid1',
|
||||
'apiKey' => 'my-apikey',
|
||||
]);
|
||||
$this->assertEquals(201, $provider['headers']['status-code']);
|
||||
$response = $this->client->call(Client::METHOD_POST, '/messaging/topics', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'providerId' => $provider['body']['$id'],
|
||||
'topicId' => 'unique()',
|
||||
'name' => 'my-app',
|
||||
'description' => 'web app'
|
||||
'topicId' => 'unique()',
|
||||
'name' => 'my-app',
|
||||
'description' => 'web app'
|
||||
]);
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$this->assertEquals('my-app', $response['body']['name']);
|
||||
$this->assertEquals('my-app', $response['body']['name']);
|
||||
|
||||
return $response['body']['$id'];
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @depends testCreateTopic
|
||||
*/
|
||||
public function testUpdateTopic(string $topicId): string
|
||||
{
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/messaging/topics/' . $topicId, [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'name' => 'android-app',
|
||||
'description' => 'updated-description'
|
||||
]);
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals('android-app', $response['body']['name']);
|
||||
$this->assertEquals('updated-description', $response['body']['description']);
|
||||
return $topicId;
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
], [
|
||||
'name' => 'android-app',
|
||||
'description' => 'updated-description'
|
||||
]);
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals('android-app', $response['body']['name']);
|
||||
$this->assertEquals('updated-description', $response['body']['description']);
|
||||
return $topicId;
|
||||
}
|
||||
|
||||
public function testListTopic()
|
||||
@@ -249,27 +249,27 @@ trait MessagingBase
|
||||
$this->assertEquals(1, \count($response['body']['topics']));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @depends testUpdateTopic
|
||||
*/
|
||||
public function testGetTopic(string $topicId)
|
||||
{
|
||||
$response = $this->client->call(Client::METHOD_GET, '/messaging/topics/' .$topicId, [
|
||||
$response = $this->client->call(Client::METHOD_GET, '/messaging/topics/' . $topicId, [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
]);
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals('android-app', $response['body']['name']);
|
||||
$this->assertEquals('updated-description', $response['body']['description']);
|
||||
$this->assertEquals('android-app', $response['body']['name']);
|
||||
$this->assertEquals('updated-description', $response['body']['description']);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @depends testUpdateTopic
|
||||
*/
|
||||
public function testDeleteTopic(string $topicId)
|
||||
{
|
||||
$response = $this->client->call(Client::METHOD_DELETE, '/messaging/topics/' .$topicId, [
|
||||
$response = $this->client->call(Client::METHOD_DELETE, '/messaging/topics/' . $topicId, [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
|
||||
@@ -11,5 +11,4 @@ class MessagingConsoleClientTest extends Scope
|
||||
use MessagingBase;
|
||||
use ProjectCustom;
|
||||
use SideConsole;
|
||||
|
||||
}
|
||||
|
||||
@@ -11,5 +11,4 @@ class MessagingCustomClientTest extends Scope
|
||||
use MessagingBase;
|
||||
use ProjectCustom;
|
||||
use SideClient;
|
||||
|
||||
}
|
||||
|
||||
@@ -11,5 +11,4 @@ class MessagingCustomServerTest extends Scope
|
||||
use MessagingBase;
|
||||
use ProjectCustom;
|
||||
use SideServer;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user