From d037c0df23ef68528928f2ba0e7135963deb24cd Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 19 Jul 2021 12:20:49 +0545 Subject: [PATCH] team and membership custom id support --- app/controllers/api/teams.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 39ced4b747..2c6c4041ea 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -1,6 +1,7 @@ label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_TEAM) + ->param('teamId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string `unique()` to auto generate it. Valid chars are a-z, A-Z, 0-9, and underscore. Can\'t start with a leading underscore. Max length is 36 chars.') ->param('name', null, new Text(128), 'Team name. Max length: 128 chars.') ->param('roles', ['owner'], new ArrayList(new Key()), 'Array of strings. Use this param to set the roles in the team for the user who created it. The default role is **owner**. A role can be any string. Learn more about [roles and permissions](/docs/permissions). Max length for each role is 32 chars.', true) ->inject('response') ->inject('user') ->inject('dbForInternal') - ->action(function ($name, $roles, $response, $user, $dbForInternal) { + ->action(function ($teamId, $name, $roles, $response, $user, $dbForInternal) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Document $user */ /** @var Utopia\Database\Database $dbForInternal */ @@ -47,7 +49,7 @@ App::post('/v1/teams') $isPrivilegedUser = Auth::isPrivilegedUser(Authorization::$roles); $isAppUser = Auth::isAppUser(Authorization::$roles); - $teamId = $dbForInternal->getId(); + $teamId = $teamId == 'unique()' ? $dbForInternal->getId() : $teamId; $team = $dbForInternal->createDocument('teams', new Document([ '$id' => $teamId , '$read' => ['team:'.$teamId], @@ -242,6 +244,7 @@ App::post('/v1/teams/:teamId/memberships') ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_MEMBERSHIP) ->label('abuse-limit', 10) + ->param('membershipId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string `unique()` to auto generate it. Valid chars are a-z, A-Z, 0-9, and underscore. Can\'t start with a leading underscore. Max length is 36 chars.') ->param('teamId', '', new UID(), 'Team unique ID.') ->param('email', '', new Email(), 'New team member email.') ->param('name', '', new Text(128), 'New team member name. Max length: 128 chars.', true) @@ -254,7 +257,7 @@ App::post('/v1/teams/:teamId/memberships') ->inject('locale') ->inject('audits') ->inject('mails') - ->action(function ($teamId, $email, $name, $roles, $url, $response, $project, $user, $dbForInternal, $locale, $audits, $mails) { + ->action(function ($membershipId, $teamId, $email, $name, $roles, $url, $response, $project, $user, $dbForInternal, $locale, $audits, $mails) { /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Document $user */ @@ -329,7 +332,7 @@ App::post('/v1/teams/:teamId/memberships') $secret = Auth::tokenGenerator(); $membership = new Document([ - '$id' => $dbForInternal->getId(), + '$id' => $membershipId == 'unique()' ? $dbForInternal->getId() : $membershipId, '$read' => ['role:all'], '$write' => ['user:'.$invitee->getId(), 'team:'.$team->getId().'/owner'], 'userId' => $invitee->getId(),