mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
feat: use arrow functions on authorization skip method
This commit is contained in:
@@ -669,26 +669,24 @@ App::post('/v1/account/sessions/magic-url')
|
||||
|
||||
$userId = $userId == 'unique()' ? $dbForInternal->getId() : $userId;
|
||||
|
||||
$user = Authorization::skip(function () use ($dbForInternal, $userId, $email) {
|
||||
return $dbForInternal->createDocument('users', new Document([
|
||||
'$id' => $userId,
|
||||
'$read' => ['role:all'],
|
||||
'$write' => ['user:' . $userId],
|
||||
'email' => $email,
|
||||
'emailVerification' => false,
|
||||
'status' => true,
|
||||
'password' => null,
|
||||
'passwordUpdate' => \time(),
|
||||
'registration' => \time(),
|
||||
'reset' => false,
|
||||
'prefs' => [],
|
||||
'sessions' => [],
|
||||
'tokens' => [],
|
||||
'memberships' => [],
|
||||
'search' => implode(' ', [$userId, $email]),
|
||||
'deleted' => false
|
||||
]));
|
||||
});
|
||||
$user = Authorization::skip(fn () => $dbForInternal->createDocument('users', new Document([
|
||||
'$id' => $userId,
|
||||
'$read' => ['role:all'],
|
||||
'$write' => ['user:' . $userId],
|
||||
'email' => $email,
|
||||
'emailVerification' => false,
|
||||
'status' => true,
|
||||
'password' => null,
|
||||
'passwordUpdate' => \time(),
|
||||
'registration' => \time(),
|
||||
'reset' => false,
|
||||
'prefs' => [],
|
||||
'sessions' => [],
|
||||
'tokens' => [],
|
||||
'memberships' => [],
|
||||
'search' => implode(' ', [$userId, $email]),
|
||||
'deleted' => false
|
||||
])));
|
||||
|
||||
$mails->setParam('event', 'users.create');
|
||||
$audits->setParam('event', 'users.create');
|
||||
|
||||
@@ -1645,9 +1645,7 @@ App::post('/v1/database/collections/:collectionId/documents')
|
||||
try {
|
||||
if ($collection->getAttribute('permission') === 'collection') {
|
||||
/** @var Document $document */
|
||||
$document = Authorization::skip(function() use ($dbForExternal, $collectionId, $data) {
|
||||
return $dbForExternal->createDocument($collectionId, new Document($data));
|
||||
});
|
||||
$document = Authorization::skip(fn() => $dbForExternal->createDocument($collectionId, new Document($data)));
|
||||
} else {
|
||||
$document = $dbForExternal->createDocument($collectionId, new Document($data));
|
||||
}
|
||||
@@ -1739,9 +1737,7 @@ App::get('/v1/database/collections/:collectionId/documents')
|
||||
|
||||
if ($collection->getAttribute('permission') === 'collection') {
|
||||
/** @var Document[] $documents */
|
||||
$documents = Authorization::skip(function() use ($dbForExternal, $collectionId, $queries, $limit, $offset, $orderAttributes, $orderTypes, $cursorDocument, $cursorDirection) {
|
||||
return $dbForExternal->find($collectionId, $queries, $limit, $offset, $orderAttributes, $orderTypes, $cursorDocument ?? null, $cursorDirection);
|
||||
});
|
||||
$documents = Authorization::skip(fn() => $dbForExternal->find($collectionId, $queries, $limit, $offset, $orderAttributes, $orderTypes, $cursorDocument ?? null, $cursorDirection));
|
||||
} else {
|
||||
$documents = $dbForExternal->find($collectionId, $queries, $limit, $offset, $orderAttributes, $orderTypes, $cursorDocument ?? null, $cursorDirection);
|
||||
}
|
||||
@@ -1795,9 +1791,7 @@ App::get('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
|
||||
if ($collection->getAttribute('permission') === 'collection') {
|
||||
/** @var Document $document */
|
||||
$document = Authorization::skip(function() use ($dbForExternal, $collectionId, $documentId) {
|
||||
return $dbForExternal->getDocument($collectionId, $documentId);
|
||||
});
|
||||
$document = Authorization::skip(fn() => $dbForExternal->getDocument($collectionId, $documentId));
|
||||
} else {
|
||||
$document = $dbForExternal->getDocument($collectionId, $documentId);
|
||||
}
|
||||
@@ -1993,9 +1987,7 @@ App::patch('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
try {
|
||||
if ($collection->getAttribute('permission') === 'collection') {
|
||||
/** @var Document $document */
|
||||
$document = Authorization::skip(function() use ($dbForExternal, $collection, $document, $data) {
|
||||
return $dbForExternal->updateDocument($collection->getId(), $document->getId(), new Document($data));
|
||||
});
|
||||
$document = Authorization::skip(fn() => $dbForExternal->updateDocument($collection->getId(), $document->getId(), new Document($data)));
|
||||
} else {
|
||||
$document = $dbForExternal->updateDocument($collection->getId(), $document->getId(), new Document($data));
|
||||
}
|
||||
@@ -2066,9 +2058,7 @@ App::delete('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
|
||||
if ($collection->getAttribute('permission') === 'collection') {
|
||||
/** @var Document $document */
|
||||
$document = Authorization::skip(function() use ($dbForExternal, $collectionId, $documentId) {
|
||||
return $dbForExternal->getDocument($collectionId, $documentId);
|
||||
});
|
||||
$document = Authorization::skip(fn() => $dbForExternal->getDocument($collectionId, $documentId));
|
||||
} else {
|
||||
$document = $dbForExternal->getDocument($collectionId, $documentId);
|
||||
}
|
||||
|
||||
@@ -807,9 +807,7 @@ App::get('/v1/functions/:functionId/executions')
|
||||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Utopia\Database\Database $dbForInternal */
|
||||
|
||||
$function = Authorization::skip(function() use ($dbForInternal, $functionId) {
|
||||
return $dbForInternal->getDocument('functions', $functionId);
|
||||
});
|
||||
$function = Authorization::skip(fn() => $dbForInternal->getDocument('functions', $functionId));
|
||||
|
||||
if ($function->isEmpty()) {
|
||||
throw new Exception('Function not found', 404);
|
||||
|
||||
+4
-10
@@ -87,9 +87,7 @@ $server->onStart(function () use ($stats, $register, $containerId, &$statsDocume
|
||||
'timestamp' => time(),
|
||||
'value' => '{}'
|
||||
]);
|
||||
$statsDocument = Authorization::skip(function () use ($database, $document) {
|
||||
return $database->createDocument('realtime', $document);
|
||||
});
|
||||
$statsDocument = Authorization::skip(fn() => $database->createDocument('realtime', $document));
|
||||
} catch (\Throwable $th) {
|
||||
Console::error('[Error] Type: ' . get_class($th));
|
||||
Console::error('[Error] Message: ' . $th->getMessage());
|
||||
@@ -141,9 +139,7 @@ $server->onStart(function () use ($stats, $register, $containerId, &$statsDocume
|
||||
->setAttribute('timestamp', time())
|
||||
->setAttribute('value', json_encode($payload));
|
||||
|
||||
Authorization::skip(function () use ($database, $statsDocument) {
|
||||
$database->updateDocument('realtime', $statsDocument->getId(), $statsDocument);
|
||||
});
|
||||
Authorization::skip(fn() => $database->updateDocument('realtime', $statsDocument->getId(), $statsDocument));
|
||||
} catch (\Throwable $th) {
|
||||
Console::error('[Error] Type: ' . get_class($th));
|
||||
Console::error('[Error] Message: ' . $th->getMessage());
|
||||
@@ -171,11 +167,9 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats,
|
||||
|
||||
$payload = [];
|
||||
|
||||
$list = Authorization::skip(function () use ($database) {
|
||||
return $database->find('realtime', [
|
||||
$list = Authorization::skip(fn() => $database->find('realtime', [
|
||||
new Query('timestamp', Query::TYPE_GREATER, [(time() - 15)])
|
||||
]);
|
||||
});
|
||||
]));
|
||||
|
||||
/**
|
||||
* Aggregate stats across containers.
|
||||
|
||||
@@ -481,16 +481,14 @@ class FunctionsV1 extends Worker
|
||||
|
||||
Console::info('Function executed in ' . ($executionEnd - $executionStart) . ' seconds, status: ' . $functionStatus);
|
||||
|
||||
$execution = Authorization::skip(function() use ($database, $execution, $tag, $functionStatus, $exitCode, $stdout, $stderr, $executionTime) {
|
||||
return $database->updateDocument('executions', $execution->getId(), new Document(array_merge($execution->getArrayCopy(), [
|
||||
$execution = Authorization::skip(fn() => $database->updateDocument('executions', $execution->getId(), new Document(array_merge($execution->getArrayCopy(), [
|
||||
'tagId' => $tag->getId(),
|
||||
'status' => $functionStatus,
|
||||
'exitCode' => $exitCode,
|
||||
'stdout' => \utf8_encode(\mb_substr($stdout, -8000)), // log last 8000 chars output
|
||||
'stderr' => \utf8_encode(\mb_substr($stderr, -8000)), // log last 8000 chars output
|
||||
'time' => (float)$executionTime,
|
||||
])));
|
||||
});
|
||||
]))));
|
||||
|
||||
$executionModel = new Execution();
|
||||
$executionUpdate = new Event('v1-webhooks', 'WebhooksV1');
|
||||
|
||||
Reference in New Issue
Block a user