mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
Merge pull request #9348 from ChiragAgg5k/pla-2470
Fix resend team invite if already accepted
This commit is contained in:
commit
27d2cc9f00
4 changed files with 15 additions and 24 deletions
|
|
@ -356,7 +356,7 @@ return [
|
||||||
],
|
],
|
||||||
Exception::TEAM_INVALID_SECRET => [
|
Exception::TEAM_INVALID_SECRET => [
|
||||||
'name' => Exception::TEAM_INVALID_SECRET,
|
'name' => Exception::TEAM_INVALID_SECRET,
|
||||||
'description' => 'The team invitation secret is invalid. Please request a new invitation and try again.',
|
'description' => 'The team invitation secret is invalid. Please request a new invitation and try again.',
|
||||||
'code' => 401,
|
'code' => 401,
|
||||||
],
|
],
|
||||||
Exception::TEAM_MEMBERSHIP_MISMATCH => [
|
Exception::TEAM_MEMBERSHIP_MISMATCH => [
|
||||||
|
|
|
||||||
|
|
@ -588,9 +588,8 @@ App::post('/v1/teams/:teamId/memberships')
|
||||||
Query::equal('teamInternalId', [$team->getInternalId()]),
|
Query::equal('teamInternalId', [$team->getInternalId()]),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$secret = Auth::tokenGenerator();
|
||||||
if ($membership->isEmpty()) {
|
if ($membership->isEmpty()) {
|
||||||
$secret = Auth::tokenGenerator();
|
|
||||||
|
|
||||||
$membershipId = ID::unique();
|
$membershipId = ID::unique();
|
||||||
$membership = new Document([
|
$membership = new Document([
|
||||||
'$id' => $membershipId,
|
'$id' => $membershipId,
|
||||||
|
|
@ -618,7 +617,8 @@ App::post('/v1/teams/:teamId/memberships')
|
||||||
$dbForProject->createDocument('memberships', $membership);
|
$dbForProject->createDocument('memberships', $membership);
|
||||||
Authorization::skip(fn () => $dbForProject->increaseDocumentAttribute('teams', $team->getId(), 'total', 1));
|
Authorization::skip(fn () => $dbForProject->increaseDocumentAttribute('teams', $team->getId(), 'total', 1));
|
||||||
|
|
||||||
} else {
|
} elseif ($membership->getAttribute('confirm') === false) {
|
||||||
|
$membership->setAttribute('secret', Auth::hash($secret));
|
||||||
$membership->setAttribute('invited', DateTime::now());
|
$membership->setAttribute('invited', DateTime::now());
|
||||||
|
|
||||||
if ($isPrivilegedUser || $isAppUser) {
|
if ($isPrivilegedUser || $isAppUser) {
|
||||||
|
|
@ -629,9 +629,10 @@ App::post('/v1/teams/:teamId/memberships')
|
||||||
$membership = ($isPrivilegedUser || $isAppUser) ?
|
$membership = ($isPrivilegedUser || $isAppUser) ?
|
||||||
Authorization::skip(fn () => $dbForProject->updateDocument('memberships', $membership->getId(), $membership)) :
|
Authorization::skip(fn () => $dbForProject->updateDocument('memberships', $membership->getId(), $membership)) :
|
||||||
$dbForProject->updateDocument('memberships', $membership->getId(), $membership);
|
$dbForProject->updateDocument('memberships', $membership->getId(), $membership);
|
||||||
|
} else {
|
||||||
|
throw new Exception(Exception::MEMBERSHIP_ALREADY_CONFIRMED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($isPrivilegedUser || $isAppUser) {
|
if ($isPrivilegedUser || $isAppUser) {
|
||||||
$dbForProject->purgeCachedDocument('users', $invitee->getId());
|
$dbForProject->purgeCachedDocument('users', $invitee->getId());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -226,10 +226,6 @@ trait TeamsBaseClient
|
||||||
$this->assertEquals($response['body']['teamId'], substr($lastEmail['text'], strpos($lastEmail['text'], '&teamId=', 0) + 8, 20));
|
$this->assertEquals($response['body']['teamId'], substr($lastEmail['text'], strpos($lastEmail['text'], '&teamId=', 0) + 8, 20));
|
||||||
$this->assertEquals($teamName, substr($lastEmail['text'], strpos($lastEmail['text'], '&teamName=', 0) + 10, 7));
|
$this->assertEquals($teamName, substr($lastEmail['text'], strpos($lastEmail['text'], '&teamName=', 0) + 10, 7));
|
||||||
|
|
||||||
$secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256);
|
|
||||||
$membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 14, 20);
|
|
||||||
$userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 20);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test with UserId
|
* Test with UserId
|
||||||
* Create user
|
* Create user
|
||||||
|
|
@ -308,6 +304,11 @@ trait TeamsBaseClient
|
||||||
|
|
||||||
$this->assertEquals(201, $response['headers']['status-code']);
|
$this->assertEquals(201, $response['headers']['status-code']);
|
||||||
|
|
||||||
|
$lastEmail = $this->getLastEmail();
|
||||||
|
$membershipUid = substr($lastEmail['text'], strpos($lastEmail['text'], '?membershipId=', 0) + 14, 20);
|
||||||
|
$userUid = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 20);
|
||||||
|
$secret = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for FAILURE
|
* Test for FAILURE
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -175,17 +175,10 @@ trait TeamsBaseServer
|
||||||
$userUid = $response['body']['userId'];
|
$userUid = $response['body']['userId'];
|
||||||
$membershipUid = $response['body']['$id'];
|
$membershipUid = $response['body']['$id'];
|
||||||
|
|
||||||
// $response = $this->client->call(Client::METHOD_GET, '/users/'.$userUid, array_merge([
|
/**
|
||||||
// 'content-type' => 'application/json',
|
* Test for FAILURE
|
||||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
*/
|
||||||
// ], $this->getHeaders()), []);
|
|
||||||
|
|
||||||
// $this->assertEquals($userUid, $response['body']['$id']);
|
|
||||||
// $this->assertContains('team:'.$teamUid, $response['body']['roles']);
|
|
||||||
// $this->assertContains('team:'.$teamUid.'/admin', $response['body']['roles']);
|
|
||||||
// $this->assertContains('team:'.$teamUid.'/editor', $response['body']['roles']);
|
|
||||||
|
|
||||||
// test for resending invitation
|
|
||||||
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
|
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
|
@ -196,11 +189,7 @@ trait TeamsBaseServer
|
||||||
'url' => 'http://localhost:5000/join-us#title'
|
'url' => 'http://localhost:5000/join-us#title'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(201, $response['headers']['status-code']);
|
$this->assertEquals(409, $response['headers']['status-code']); // membership already created
|
||||||
|
|
||||||
/**
|
|
||||||
* Test for FAILURE
|
|
||||||
*/
|
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
|
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue