From f128cd9578480c99c23f25dc0f87c88163a6f90c Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 7 May 2021 21:19:23 +0530 Subject: [PATCH 1/4] feat: refactor inviteId to membershipId --- app/controllers/api/teams.php | 18 +++++++++--------- app/views/console/settings/index.phtml | 4 ++-- app/views/console/users/team.phtml | 2 +- app/views/home/auth/join.phtml | 2 +- tests/e2e/Services/Teams/TeamsBaseClient.php | 2 +- tests/e2e/Services/Webhooks/WebhooksBase.php | 2 +- .../Webhooks/WebhooksCustomClientTest.php | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 910427da1..62836ea42 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -419,7 +419,7 @@ App::post('/v1/teams/:teamId/memberships') } $url = Template::parseURL($url); - $url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['inviteId' => $membership->getId(), 'teamId' => $team->getId(), 'userId' => $invitee->getId(), 'secret' => $secret, 'teamId' => $teamId]); + $url['query'] = Template::mergeQuery(((isset($url['query'])) ? $url['query'] : ''), ['membershipId' => $membership->getId(), 'teamId' => $team->getId(), 'userId' => $invitee->getId(), 'secret' => $secret, 'teamId' => $teamId]); $url = Template::unParseURL($url); $body = new Template(__DIR__.'/../../config/locale/templates/email-base.tpl'); @@ -524,7 +524,7 @@ App::get('/v1/teams/:teamId/memberships') $response->dynamic(new Document(['sum' => $projectDB->getSum(), 'memberships' => $users]), Response::MODEL_MEMBERSHIP_LIST); }); -App::patch('/v1/teams/:teamId/memberships/:inviteId/status') +App::patch('/v1/teams/:teamId/memberships/:membershipId/status') ->desc('Update Team Membership Status') ->groups(['api', 'teams']) ->label('event', 'teams.memberships.update.status') @@ -537,7 +537,7 @@ App::patch('/v1/teams/:teamId/memberships/:inviteId/status') ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_MEMBERSHIP) ->param('teamId', '', new UID(), 'Team unique ID.') - ->param('inviteId', '', new UID(), 'Invite unique ID.') + ->param('membershipId', '', new UID(), 'Membership ID.') ->param('userId', '', new UID(), 'User unique ID.') ->param('secret', '', new Text(256), 'Secret key.') ->inject('request') @@ -546,7 +546,7 @@ App::patch('/v1/teams/:teamId/memberships/:inviteId/status') ->inject('projectDB') ->inject('geodb') ->inject('audits') - ->action(function ($teamId, $inviteId, $userId, $secret, $request, $response, $user, $projectDB, $geodb, $audits) { + ->action(function ($teamId, $membershipId, $userId, $secret, $request, $response, $user, $projectDB, $geodb, $audits) { /** @var Utopia\Swoole\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ @@ -555,7 +555,7 @@ App::patch('/v1/teams/:teamId/memberships/:inviteId/status') /** @var Appwrite\Event\Event $audits */ $protocol = $request->getProtocol(); - $membership = $projectDB->getDocument($inviteId); + $membership = $projectDB->getDocument($membershipId); if (empty($membership->getId()) || Database::SYSTEM_COLLECTION_MEMBERSHIPS != $membership->getCollection()) { throw new Exception('Invite not found', 404); @@ -671,7 +671,7 @@ App::patch('/v1/teams/:teamId/memberships/:inviteId/status') ])), Response::MODEL_MEMBERSHIP); }); -App::delete('/v1/teams/:teamId/memberships/:inviteId') +App::delete('/v1/teams/:teamId/memberships/:membershipId') ->desc('Delete Team Membership') ->groups(['api', 'teams']) ->label('event', 'teams.memberships.delete') @@ -683,18 +683,18 @@ App::delete('/v1/teams/:teamId/memberships/:inviteId') ->label('sdk.response.code', Response::STATUS_CODE_NOCONTENT) ->label('sdk.response.model', Response::MODEL_NONE) ->param('teamId', '', new UID(), 'Team unique ID.') - ->param('inviteId', '', new UID(), 'Invite unique ID.') + ->param('membershipId', '', new UID(), 'Membership ID.') ->inject('response') ->inject('projectDB') ->inject('audits') ->inject('events') - ->action(function ($teamId, $inviteId, $response, $projectDB, $audits, $events) { + ->action(function ($teamId, $membershipId, $response, $projectDB, $audits, $events) { /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $audits */ /** @var Appwrite\Event\Event $events */ - $membership = $projectDB->getDocument($inviteId); + $membership = $projectDB->getDocument($membershipId); if (empty($membership->getId()) || Database::SYSTEM_COLLECTION_MEMBERSHIPS != $membership->getCollection()) { throw new Exception('Invite not found', 404); diff --git a/app/views/console/settings/index.phtml b/app/views/console/settings/index.phtml index 8cefd580c..8af3d6e53 100644 --- a/app/views/console/settings/index.phtml +++ b/app/views/console/settings/index.phtml @@ -415,7 +415,7 @@ $smtpEnabled = $this->getParam('smtpEnabled', false); data-failure-param-alert-classname="error"> - + @@ -437,7 +437,7 @@ $smtpEnabled = $this->getParam('smtpEnabled', false); data-failure-param-alert-classname="error"> - + diff --git a/app/views/console/users/team.phtml b/app/views/console/users/team.phtml index ad6d263fa..912d12306 100644 --- a/app/views/console/users/team.phtml +++ b/app/views/console/users/team.phtml @@ -105,7 +105,7 @@ data-failure-param-alert-classname="error"> - + diff --git a/app/views/home/auth/join.phtml b/app/views/home/auth/join.phtml index a857a29d5..481e8dcc3 100644 --- a/app/views/home/auth/join.phtml +++ b/app/views/home/auth/join.phtml @@ -9,7 +9,7 @@ data-scope="console" data-event="submit" data-param-team-id="{{router.params.teamId}}" - data-param-invite-id="{{router.params.inviteId}}" + data-param-invite-id="{{router.params.membershipId}}" data-param-user-id="{{router.params.userId}}" data-param-secret="{{router.params.secret}}" data-success="redirect,alert,trigger" diff --git a/tests/e2e/Services/Teams/TeamsBaseClient.php b/tests/e2e/Services/Teams/TeamsBaseClient.php index 72fc99d88..1b44e8cf2 100644 --- a/tests/e2e/Services/Teams/TeamsBaseClient.php +++ b/tests/e2e/Services/Teams/TeamsBaseClient.php @@ -72,7 +72,7 @@ trait TeamsBaseClient $this->assertEquals('Invitation to '.$teamName.' Team at '.$this->getProject()['name'], $lastEmail['subject']); $secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256); - $inviteUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?inviteId=', 0) + 10, 13); + $inviteUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 10, 13); $userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13); /** diff --git a/tests/e2e/Services/Webhooks/WebhooksBase.php b/tests/e2e/Services/Webhooks/WebhooksBase.php index 5dc6cfafe..29367ba53 100644 --- a/tests/e2e/Services/Webhooks/WebhooksBase.php +++ b/tests/e2e/Services/Webhooks/WebhooksBase.php @@ -464,7 +464,7 @@ trait WebhooksBase $lastEmail = $this->getLastEmail(); $secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256); - $inviteUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?inviteId=', 0) + 10, 13); + $inviteUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 10, 13); $userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13); $webhook = $this->getLastRequest(); diff --git a/tests/e2e/Services/Webhooks/WebhooksCustomClientTest.php b/tests/e2e/Services/Webhooks/WebhooksCustomClientTest.php index f4ed81ac0..3e3d44bed 100644 --- a/tests/e2e/Services/Webhooks/WebhooksCustomClientTest.php +++ b/tests/e2e/Services/Webhooks/WebhooksCustomClientTest.php @@ -714,7 +714,7 @@ class WebhooksCustomClientTest extends Scope { $teamUid = $data['teamId'] ?? ''; $secret = $data['secret'] ?? ''; - $inviteUid = $data['inviteId'] ?? ''; + $inviteUid = $data['membershipId'] ?? ''; $userUid = $data['userId'] ?? ''; /** From 391ff2419246ef64aa1f127506ff662f45690d3a Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 7 May 2021 21:22:14 +0530 Subject: [PATCH 2/4] feat: refactor inviteId to membershipId --- tests/e2e/Services/Webhooks/WebhooksBase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/Services/Webhooks/WebhooksBase.php b/tests/e2e/Services/Webhooks/WebhooksBase.php index 29367ba53..76dc17099 100644 --- a/tests/e2e/Services/Webhooks/WebhooksBase.php +++ b/tests/e2e/Services/Webhooks/WebhooksBase.php @@ -464,7 +464,7 @@ trait WebhooksBase $lastEmail = $this->getLastEmail(); $secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256); - $inviteUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 10, 13); + $membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 10, 13); $userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13); $webhook = $this->getLastRequest(); @@ -490,7 +490,7 @@ trait WebhooksBase return [ 'teamId' => $teamUid, 'secret' => $secret, - 'inviteId' => $inviteUid, + 'membershipId' => $membershipUid, 'userId' => $webhook['data']['userId'], ]; } From 18e12ee6ad3abfb70f0cde473c9d529f69310bc2 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 7 May 2021 22:24:56 +0530 Subject: [PATCH 3/4] feat: fix tests --- tests/e2e/Services/Teams/TeamsBaseClient.php | 22 +++++++++---------- .../Webhooks/WebhooksCustomClientTest.php | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/e2e/Services/Teams/TeamsBaseClient.php b/tests/e2e/Services/Teams/TeamsBaseClient.php index 1b44e8cf2..0e6484fdc 100644 --- a/tests/e2e/Services/Teams/TeamsBaseClient.php +++ b/tests/e2e/Services/Teams/TeamsBaseClient.php @@ -72,7 +72,7 @@ trait TeamsBaseClient $this->assertEquals('Invitation to '.$teamName.' Team at '.$this->getProject()['name'], $lastEmail['subject']); $secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256); - $inviteUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 10, 13); + $membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 10, 13); $userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13); /** @@ -117,7 +117,7 @@ trait TeamsBaseClient return [ 'teamUid' => $teamUid, 'secret' => $secret, - 'inviteUid' => $inviteUid, + 'membershipUid' => $membershipUid, 'userUid' => $userUid, ]; } @@ -129,13 +129,13 @@ trait TeamsBaseClient { $teamUid = $data['teamUid'] ?? ''; $secret = $data['secret'] ?? ''; - $inviteUid = $data['inviteUid'] ?? ''; + $membershipUid = $data['membershipUid'] ?? ''; $userUid = $data['userUid'] ?? ''; /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$inviteUid.'/status', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -155,7 +155,7 @@ trait TeamsBaseClient /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$inviteUid.'/status', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -166,7 +166,7 @@ trait TeamsBaseClient $this->assertEquals(401, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$inviteUid.'/status', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -177,7 +177,7 @@ trait TeamsBaseClient $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$inviteUid.'/status', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -188,7 +188,7 @@ trait TeamsBaseClient $this->assertEquals(401, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$inviteUid.'/status', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -208,12 +208,12 @@ trait TeamsBaseClient public function testDeleteTeamMembership($data):array { $teamUid = $data['teamUid'] ?? ''; - $inviteUid = $data['inviteUid'] ?? ''; + $membershipUid = $data['membershipUid'] ?? ''; /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamUid.'/memberships/'.$inviteUid, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -225,7 +225,7 @@ trait TeamsBaseClient /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships/'.$inviteUid, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], diff --git a/tests/e2e/Services/Webhooks/WebhooksCustomClientTest.php b/tests/e2e/Services/Webhooks/WebhooksCustomClientTest.php index 3e3d44bed..3328c71f1 100644 --- a/tests/e2e/Services/Webhooks/WebhooksCustomClientTest.php +++ b/tests/e2e/Services/Webhooks/WebhooksCustomClientTest.php @@ -714,13 +714,13 @@ class WebhooksCustomClientTest extends Scope { $teamUid = $data['teamId'] ?? ''; $secret = $data['secret'] ?? ''; - $inviteUid = $data['membershipId'] ?? ''; + $membershipUid = $data['membershipId'] ?? ''; $userUid = $data['userId'] ?? ''; /** * Test for SUCCESS */ - $team = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$inviteUid.'/status', array_merge([ + $team = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid.'/status', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], From c97dcbf9c9c4a7ab43d2526f2e558cbf4a7f5e9c Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 10 May 2021 09:55:52 +0530 Subject: [PATCH 4/4] feat: fix tests and update changelog --- CHANGES.md | 3 ++- tests/e2e/Services/Teams/TeamsBaseClient.php | 2 +- tests/e2e/Services/Webhooks/WebhooksBase.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b8867b0e5..89f460919 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -38,8 +38,9 @@ - Function execution environment variable `APPWRITE_FUNCTION_EVENT_PAYLOAD` renamed to `APPWRITE_FUNCTION_EVENT_DATA` (#1045) - Function execution environment variable `APPWRITE_FUNCTION_ENV_NAME` renamed to `APPWRITE_FUNCTION_RUNTIME_NAME` (#1101) - Function execution environment variable `APPWRITE_FUNCTION_ENV_VERSION` renamed to `APPWRITE_FUNCTION_RUNTIME_VERSION` (#1101) -- Introdcues rate limits for: +- Introduces rate limits for: - Team invite (10 requests in every 60 minutes per IP address) (#1088) +- Rename param `inviteId` to the more accurate `membershipId` in the Teams API (#1129) # Version 0.7.2 diff --git a/tests/e2e/Services/Teams/TeamsBaseClient.php b/tests/e2e/Services/Teams/TeamsBaseClient.php index 0e6484fdc..e41e5531f 100644 --- a/tests/e2e/Services/Teams/TeamsBaseClient.php +++ b/tests/e2e/Services/Teams/TeamsBaseClient.php @@ -72,7 +72,7 @@ trait TeamsBaseClient $this->assertEquals('Invitation to '.$teamName.' Team at '.$this->getProject()['name'], $lastEmail['subject']); $secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256); - $membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 10, 13); + $membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 14, 13); $userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13); /** diff --git a/tests/e2e/Services/Webhooks/WebhooksBase.php b/tests/e2e/Services/Webhooks/WebhooksBase.php index 76dc17099..060e8ad0a 100644 --- a/tests/e2e/Services/Webhooks/WebhooksBase.php +++ b/tests/e2e/Services/Webhooks/WebhooksBase.php @@ -464,7 +464,7 @@ trait WebhooksBase $lastEmail = $this->getLastEmail(); $secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256); - $membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 10, 13); + $membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 14, 13); $userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 13); $webhook = $this->getLastRequest();