Merge branch 'feat-schedule-execution-improvements' of https://github.com/appwrite/appwrite into feat-schedule-execution-improvements
This commit is contained in:
commit
1024c98bb2
4 changed files with 70 additions and 4 deletions
|
@ -177,6 +177,12 @@ $createSession = function (string $userId, string $secret, Request $request, Res
|
||||||
default => throw new Exception(Exception::USER_INVALID_TOKEN)
|
default => throw new Exception(Exception::USER_INVALID_TOKEN)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$sendAlert = (match ($verifiedToken->getAttribute('type')) {
|
||||||
|
Auth::TOKEN_TYPE_MAGIC_URL,
|
||||||
|
Auth::TOKEN_TYPE_EMAIL => false,
|
||||||
|
default => true
|
||||||
|
});
|
||||||
|
|
||||||
$session = new Document(array_merge(
|
$session = new Document(array_merge(
|
||||||
[
|
[
|
||||||
'$id' => ID::unique(),
|
'$id' => ID::unique(),
|
||||||
|
@ -223,7 +229,7 @@ $createSession = function (string $userId, string $secret, Request $request, Res
|
||||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed saving user to DB');
|
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed saving user to DB');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($project->getAttribute('auths', [])['sessionAlerts'] ?? false) {
|
if (($project->getAttribute('auths', [])['sessionAlerts'] ?? false) && $sendAlert) {
|
||||||
if ($dbForProject->count('sessions', [
|
if ($dbForProject->count('sessions', [
|
||||||
Query::equal('userId', [$user->getId()]),
|
Query::equal('userId', [$user->getId()]),
|
||||||
]) !== 1) {
|
]) !== 1) {
|
||||||
|
|
|
@ -110,6 +110,13 @@ class TemplateFunction extends Model
|
||||||
'default' => [],
|
'default' => [],
|
||||||
'example' => [],
|
'example' => [],
|
||||||
'array' => true
|
'array' => true
|
||||||
|
])
|
||||||
|
->addRule('scopes', [
|
||||||
|
'type' => self::TYPE_STRING,
|
||||||
|
'description' => 'Function scopes.',
|
||||||
|
'default' => [],
|
||||||
|
'example' => 'users.read',
|
||||||
|
'array' => true,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -620,9 +620,9 @@ class AccountCustomClientTest extends Scope
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
]), [
|
]), [
|
||||||
'userId' => ID::unique(),
|
'userId' => ID::unique(),
|
||||||
'email' => $data['email'],
|
'email' => $data['email'],
|
||||||
'password' => $data['password'],
|
'password' => $data['password'],
|
||||||
'name' => $data['name'],
|
'name' => $data['name'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(201, $response['headers']['status-code']);
|
$this->assertEquals(201, $response['headers']['status-code']);
|
||||||
|
@ -1258,6 +1258,56 @@ class AccountCustomClientTest extends Scope
|
||||||
$this->assertStringContainsString($response['body']['ip'], $lastEmail['text']); // IP Address
|
$this->assertStringContainsString($response['body']['ip'], $lastEmail['text']); // IP Address
|
||||||
$this->assertStringContainsString('Unknown', $lastEmail['text']); // Country
|
$this->assertStringContainsString('Unknown', $lastEmail['text']); // Country
|
||||||
$this->assertStringContainsString($response['body']['clientName'], $lastEmail['text']); // Client name
|
$this->assertStringContainsString($response['body']['clientName'], $lastEmail['text']); // Client name
|
||||||
|
|
||||||
|
// Verify no alert sent in OTP login
|
||||||
|
$response = $this->client->call(Client::METHOD_POST, '/account/tokens/email', array_merge([
|
||||||
|
'origin' => 'http://localhost',
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
]), [
|
||||||
|
'userId' => ID::unique(),
|
||||||
|
'email' => 'otpuser2@appwrite.io'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals($response['headers']['status-code'], 201);
|
||||||
|
$this->assertNotEmpty($response['body']['$id']);
|
||||||
|
$this->assertNotEmpty($response['body']['$createdAt']);
|
||||||
|
$this->assertNotEmpty($response['body']['userId']);
|
||||||
|
$this->assertNotEmpty($response['body']['expire']);
|
||||||
|
$this->assertEmpty($response['body']['secret']);
|
||||||
|
$this->assertEmpty($response['body']['phrase']);
|
||||||
|
|
||||||
|
$userId = $response['body']['userId'];
|
||||||
|
|
||||||
|
$lastEmail = $this->getLastEmail();
|
||||||
|
|
||||||
|
$this->assertEquals('otpuser2@appwrite.io', $lastEmail['to'][0]['address']);
|
||||||
|
$this->assertEquals('OTP for ' . $this->getProject()['name'] . ' Login', $lastEmail['subject']);
|
||||||
|
|
||||||
|
// FInd 6 concurrent digits in email text - OTP
|
||||||
|
preg_match_all("/\b\d{6}\b/", $lastEmail['text'], $matches);
|
||||||
|
$code = ($matches[0] ?? [])[0] ?? '';
|
||||||
|
|
||||||
|
$this->assertNotEmpty($code);
|
||||||
|
|
||||||
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/token', array_merge([
|
||||||
|
'origin' => 'http://localhost',
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
]), [
|
||||||
|
'userId' => $userId,
|
||||||
|
'secret' => $code
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $response['headers']['status-code']);
|
||||||
|
$this->assertEquals($userId, $response['body']['userId']);
|
||||||
|
$this->assertNotEmpty($response['body']['$id']);
|
||||||
|
$this->assertNotEmpty($response['body']['expire']);
|
||||||
|
$this->assertEmpty($response['body']['secret']);
|
||||||
|
|
||||||
|
$lastEmailId = $lastEmail['id'];
|
||||||
|
$lastEmail = $this->getLastEmail();
|
||||||
|
$this->assertEquals($lastEmailId, $lastEmail['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -861,6 +861,9 @@ class FunctionsCustomClientTest extends Scope
|
||||||
$this->assertEquals($expectedTemplates[$i]['vcsProvider'], $templates['body']['templates'][$i]['vcsProvider']);
|
$this->assertEquals($expectedTemplates[$i]['vcsProvider'], $templates['body']['templates'][$i]['vcsProvider']);
|
||||||
$this->assertEquals($expectedTemplates[$i]['runtimes'], $templates['body']['templates'][$i]['runtimes']);
|
$this->assertEquals($expectedTemplates[$i]['runtimes'], $templates['body']['templates'][$i]['runtimes']);
|
||||||
$this->assertEquals($expectedTemplates[$i]['variables'], $templates['body']['templates'][$i]['variables']);
|
$this->assertEquals($expectedTemplates[$i]['variables'], $templates['body']['templates'][$i]['variables']);
|
||||||
|
if (array_key_exists('scopes', $expectedTemplates[$i])) {
|
||||||
|
$this->assertEquals($expectedTemplates[$i]['scopes'], $templates['body']['templates'][$i]['scopes']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$templates_offset = $this->client->call(Client::METHOD_GET, '/functions/templates', array_merge([
|
$templates_offset = $this->client->call(Client::METHOD_GET, '/functions/templates', array_merge([
|
||||||
|
|
Loading…
Reference in a new issue