mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge pull request #7645 from appwrite/feat-dev-apns
Allow setting APNS to sandbox mode
This commit is contained in:
@@ -766,11 +766,12 @@ App::post('/v1/messaging/providers/apns')
|
||||
->param('authKeyId', '', new Text(0), 'APNS authentication key ID.', true)
|
||||
->param('teamId', '', new Text(0), 'APNS team ID.', true)
|
||||
->param('bundleId', '', new Text(0), 'APNS bundle ID.', true)
|
||||
->param('sandbox', false, new Boolean(), 'Use APNS sandbox environment.', true)
|
||||
->param('enabled', null, new Boolean(), 'Set as enabled.', true)
|
||||
->inject('queueForEvents')
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $providerId, string $name, string $authKey, string $authKeyId, string $teamId, string $bundleId, ?bool $enabled, Event $queueForEvents, Database $dbForProject, Response $response) {
|
||||
->action(function (string $providerId, string $name, string $authKey, string $authKeyId, string $teamId, string $bundleId, bool $sandbox, ?bool $enabled, Event $queueForEvents, Database $dbForProject, Response $response) {
|
||||
$providerId = $providerId == 'unique()' ? ID::unique() : $providerId;
|
||||
|
||||
$credentials = [];
|
||||
@@ -803,6 +804,10 @@ App::post('/v1/messaging/providers/apns')
|
||||
$enabled = false;
|
||||
}
|
||||
|
||||
$options = [
|
||||
'sandbox' => $sandbox
|
||||
];
|
||||
|
||||
$provider = new Document([
|
||||
'$id' => $providerId,
|
||||
'name' => $name,
|
||||
@@ -810,6 +815,7 @@ App::post('/v1/messaging/providers/apns')
|
||||
'type' => MESSAGE_TYPE_PUSH,
|
||||
'enabled' => $enabled,
|
||||
'credentials' => $credentials,
|
||||
'options' => $options
|
||||
]);
|
||||
|
||||
try {
|
||||
@@ -1808,10 +1814,11 @@ App::patch('/v1/messaging/providers/apns/:providerId')
|
||||
->param('authKeyId', '', new Text(0), 'APNS authentication key ID.', true)
|
||||
->param('teamId', '', new Text(0), 'APNS team ID.', true)
|
||||
->param('bundleId', '', new Text(0), 'APNS bundle ID.', true)
|
||||
->param('sandbox', null, new Boolean(), 'Use APNS sandbox environment.', true)
|
||||
->inject('queueForEvents')
|
||||
->inject('dbForProject')
|
||||
->inject('response')
|
||||
->action(function (string $providerId, string $name, ?bool $enabled, string $authKey, string $authKeyId, string $teamId, string $bundleId, Event $queueForEvents, Database $dbForProject, Response $response) {
|
||||
->action(function (string $providerId, string $name, ?bool $enabled, string $authKey, string $authKeyId, string $teamId, string $bundleId, ?bool $sandbox, Event $queueForEvents, Database $dbForProject, Response $response) {
|
||||
$provider = $dbForProject->getDocument('providers', $providerId);
|
||||
|
||||
if ($provider->isEmpty()) {
|
||||
@@ -1847,6 +1854,14 @@ App::patch('/v1/messaging/providers/apns/:providerId')
|
||||
|
||||
$provider->setAttribute('credentials', $credentials);
|
||||
|
||||
$options = $provider->getAttribute('options');
|
||||
|
||||
if (!\is_null($sandbox)) {
|
||||
$options['sandbox'] = $sandbox;
|
||||
}
|
||||
|
||||
$provider->setAttribute('options', $options);
|
||||
|
||||
if (!\is_null($enabled)) {
|
||||
if ($enabled) {
|
||||
if (
|
||||
|
||||
@@ -469,6 +469,7 @@ class Messaging extends Action
|
||||
private function getPushAdapter(Document $provider): ?PushAdapter
|
||||
{
|
||||
$credentials = $provider->getAttribute('credentials');
|
||||
$options = $provider->getAttribute('options');
|
||||
|
||||
return match ($provider->getAttribute('provider')) {
|
||||
'mock' => new Mock('username', 'password'),
|
||||
@@ -477,6 +478,7 @@ class Messaging extends Action
|
||||
$credentials['authKeyId'],
|
||||
$credentials['teamId'],
|
||||
$credentials['bundleId'],
|
||||
$options['sandbox']
|
||||
),
|
||||
'fcm' => new FCM(\json_encode($credentials['serviceAccountJSON'])),
|
||||
default => null
|
||||
|
||||
@@ -98,16 +98,22 @@ trait MessagingBase
|
||||
];
|
||||
$providers = [];
|
||||
|
||||
foreach (\array_keys($providersParams) as $key) {
|
||||
foreach ($providersParams as $key => $params) {
|
||||
$response = $this->client->call(Client::METHOD_POST, '/messaging/providers/' . $key, \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
]), $providersParams[$key]);
|
||||
]), $params);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$this->assertEquals($providersParams[$key]['name'], $response['body']['name']);
|
||||
\array_push($providers, $response['body']);
|
||||
$this->assertEquals($params['name'], $response['body']['name']);
|
||||
$providers[] = $response['body'];
|
||||
|
||||
switch ($key) {
|
||||
case 'apns':
|
||||
$this->assertEquals(false, $response['body']['options']['sandbox']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $providers;
|
||||
|
||||
Reference in New Issue
Block a user