From 048e8e81ba3ae59a2152ddad58ade4f3cdcc4107 Mon Sep 17 00:00:00 2001 From: prateek banga Date: Fri, 25 Aug 2023 02:59:06 +0530 Subject: [PATCH] removes permission from provider controllers --- app/controllers/api/messaging.php | 90 ++++--------------- .../Messaging/MessagingServerTest.php | 5 +- 2 files changed, 20 insertions(+), 75 deletions(-) diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index c08d772ef4..f391eef5ba 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -104,19 +104,13 @@ App::post('/v1/messaging/providers/mailgun') ->param('name', '', new Text(128), 'Provider name.') ->param('apiKey', '', new Text(0), 'Mailgun API Key.') ->param('domain', '', new Text(0), 'Mailgun Domain.') - ->inject('user') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $apiKey, string $domain, Document $user, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, string $apiKey, string $domain, Database $dbForProject, Response $response) { $id = $id == 'unique()' ? ID::unique() : $id; $provider = $dbForProject->createDocument('providers', new Document([ '$id' => $id, - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), - ], - 'name' => $name, + 'name' => $name, 'provider' => 'mailgun', 'type' => 'email', 'credentials' => [ @@ -200,19 +194,13 @@ App::post('/v1/messaging/providers/sendgrid') ->param('id', '', 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('apiKey', '', new Text(0), 'Sendgrid API key.') - ->inject('user') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $apiKey, Document $user, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, string $apiKey, Database $dbForProject, Response $response) { $id = $id == 'unique()' ? ID::unique() : $id; $provider = $dbForProject->createDocument('providers', new Document([ '$id' => $id, - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), - ], - 'name' => $name, + 'name' => $name, 'provider' => 'sendgrid', 'type' => 'email', 'credentials' => [ @@ -291,19 +279,13 @@ App::post('/v1/messaging/providers/msg91') ->param('name', '', new Text(128), 'Provider name.') ->param('senderId', '', new Text(0), 'Msg91 Sender ID.') ->param('authKey', '', new Text(0), 'Msg91 Auth Key.') - ->inject('user') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $senderId, string $authKey, Document $user, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, string $senderId, string $authKey, Database $dbForProject, Response $response) { $id = $id == 'unique()' ? ID::unique() : $id; $provider = $dbForProject->createDocument('providers', new Document([ '$id' => $id, - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), - ], - 'name' => $name, + 'name' => $name, 'provider' => 'msg91', 'type' => 'sms', 'credentials' => [ @@ -388,19 +370,13 @@ App::post('/v1/messaging/providers/telesign') ->param('name', '', new Text(128), 'Provider name.') ->param('username', '', new Text(0), 'Telesign username.') ->param('password', '', new Text(0), 'Telesign password.') - ->inject('user') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $username, string $password, Document $user, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, string $username, string $password, Database $dbForProject, Response $response) { $id = $id == 'unique()' ? ID::unique() : $id; $provider = $dbForProject->createDocument('providers', new Document([ '$id' => $id, - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), - ], - 'name' => $name, + 'name' => $name, 'provider' => 'telesign', 'type' => 'sms', 'credentials' => [ @@ -485,19 +461,13 @@ App::post('/v1/messaging/providers/textmagic') ->param('name', '', new Text(128), 'Provider name.') ->param('username', '', new Text(0), 'Textmagic username.') ->param('apiKey', '', new Text(0), 'Textmagic apiKey.') - ->inject('user') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $username, string $apiKey, Document $user, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, string $username, string $apiKey, Database $dbForProject, Response $response) { $id = $id == 'unique()' ? ID::unique() : $id; $provider = $dbForProject->createDocument('providers', new Document([ '$id' => $id, - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), - ], - 'name' => $name, + 'name' => $name, 'provider' => 'text-magic', 'type' => 'sms', 'credentials' => [ @@ -582,19 +552,13 @@ App::post('/v1/messaging/providers/twilio') ->param('name', '', new Text(128), 'Provider name.') ->param('accountSid', '', new Text(0), 'Twilio account secret ID.') ->param('authToken', '', new Text(0), 'Twilio authentication token.') - ->inject('user') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $accountSid, string $authToken, Document $user, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, string $accountSid, string $authToken, Database $dbForProject, Response $response) { $id = $id == 'unique()' ? ID::unique() : $id; $provider = $dbForProject->createDocument('providers', new Document([ '$id' => $id, - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), - ], - 'name' => $name, + 'name' => $name, 'provider' => 'twilio', 'type' => 'sms', 'credentials' => [ @@ -679,19 +643,13 @@ App::post('/v1/messaging/providers/vonage') ->param('name', '', new Text(128), 'Provider name.') ->param('apiKey', '', new Text(0), 'Vonage API key.') ->param('apiSecret', '', new Text(0), 'Vonage API secret.') - ->inject('user') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $apiKey, string $apiSecret, Document $user, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, string $apiKey, string $apiSecret, Database $dbForProject, Response $response) { $id = $id == 'unique()' ? ID::unique() : $id; $provider = $dbForProject->createDocument('providers', new Document([ '$id' => $id, - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), - ], - 'name' => $name, + 'name' => $name, 'provider' => 'vonage', 'type' => 'sms', 'credentials' => [ @@ -778,19 +736,13 @@ App::post('/v1/messaging/providers/fcm') ->param('id', '', 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('serverKey', '', new Text(0), 'FCM Server Key.') - ->inject('user') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $serverKey, Document $user, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, string $serverKey, Database $dbForProject, Response $response) { $id = $id == 'unique()' ? ID::unique() : $id; $provider = $dbForProject->createDocument('providers', new Document([ '$id' => $id, - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), - ], - 'name' => $name, + 'name' => $name, 'provider' => 'fcm', 'type' => 'push', 'credentials' => [ @@ -867,19 +819,13 @@ App::post('/v1/messaging/providers/apns') ->param('teamId', '', new Text(0), 'APNS team ID.') ->param('bundleId', '', new Text(0), 'APNS bundle ID.') ->param('endpoint', '', new Text(0), 'APNS endpoint.') - ->inject('user') ->inject('dbForProject') ->inject('response') - ->action(function (string $id, string $name, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Document $user, Database $dbForProject, Response $response) { + ->action(function (string $id, string $name, string $authKey, string $authKeyId, string $teamId, string $bundleId, string $endpoint, Database $dbForProject, Response $response) { $id = $id == 'unique()' ? ID::unique() : $id; $provider = $dbForProject->createDocument('providers', new Document([ '$id' => $id, - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::user($user->getId())), - Permission::delete(Role::user($user->getId())), - ], - 'name' => $name, + 'name' => $name, 'provider' => 'apns', 'type' => 'push', 'credentials' => [ diff --git a/tests/e2e/Services/Messaging/MessagingServerTest.php b/tests/e2e/Services/Messaging/MessagingServerTest.php index 0724b6dd2c..74855bc4a6 100644 --- a/tests/e2e/Services/Messaging/MessagingServerTest.php +++ b/tests/e2e/Services/Messaging/MessagingServerTest.php @@ -5,12 +5,12 @@ namespace Tests\E2E\Services\Messaging; use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; -use Tests\E2E\Scopes\SideConsole; +use Tests\E2E\Scopes\SideServer; class MessagingServerTest extends Scope { use ProjectCustom; - use SideConsole; + use SideServer; public function testCreateProviders(): array { @@ -77,7 +77,6 @@ class MessagingServerTest extends Scope $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'], ],$this->getHeaders()), $providersParams[$key]); \array_push($providers, $response['body']); $this->assertEquals(201, $response['headers']['status-code']);