mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Add custom delete restricted error
This commit is contained in:
@@ -413,6 +413,11 @@ return [
|
||||
'description' => 'Remote document is newer than local.',
|
||||
'code' => 409,
|
||||
],
|
||||
Exception::DOCUMENT_DELETE_RESTRICTED => [
|
||||
'name' => Exception::DOCUMENT_DELETE_RESTRICTED,
|
||||
'description' => 'Document cannot be deleted because it is referenced by another document.',
|
||||
'code' => 403,
|
||||
],
|
||||
|
||||
/** Attributes */
|
||||
Exception::ATTRIBUTE_NOT_FOUND => [
|
||||
|
||||
@@ -30,6 +30,7 @@ use Utopia\Database\Validator\UID;
|
||||
use Utopia\Database\Exception\Authorization as AuthorizationException;
|
||||
use Utopia\Database\Exception\Duplicate as DuplicateException;
|
||||
use Utopia\Database\Exception\Limit as LimitException;
|
||||
use Utopia\Database\Exception\Restricted as RestrictedException;
|
||||
use Utopia\Database\Exception\Structure as StructureException;
|
||||
use Utopia\Locale\Locale;
|
||||
use Appwrite\Auth\Auth;
|
||||
@@ -2273,7 +2274,7 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/attributes/:key
|
||||
}
|
||||
|
||||
if ($relatedAttribute->getAttribute('status') === 'available') {
|
||||
$relatedAttribute = $dbForProject->updateDocument('attributes', $relatedAttribute->getId(), $relatedAttribute->setAttribute('status', 'deleting'));
|
||||
$dbForProject->updateDocument('attributes', $relatedAttribute->getId(), $relatedAttribute->setAttribute('status', 'deleting'));
|
||||
}
|
||||
|
||||
$dbForProject->deleteCachedDocument('database_' . $db->getInternalId(), $options['relatedCollection']);
|
||||
@@ -3538,11 +3539,16 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/documents/:docu
|
||||
|
||||
$checkPermissions($collection, $document);
|
||||
|
||||
Authorization::skip(fn () => $dbForProject->withRequestTimestamp($requestTimestamp, fn() =>
|
||||
$dbForProject->deleteDocument(
|
||||
'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(),
|
||||
$documentId
|
||||
)));
|
||||
Authorization::skip(fn () => $dbForProject->withRequestTimestamp($requestTimestamp, function () use ($dbForProject, $database, $collection, $documentId) {
|
||||
try {
|
||||
$dbForProject->deleteDocument(
|
||||
'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(),
|
||||
$documentId
|
||||
);
|
||||
} catch (RestrictedException) {
|
||||
throw new Exception(Exception::DOCUMENT_DELETE_RESTRICTED);
|
||||
}
|
||||
}));
|
||||
|
||||
$dbForProject->deleteCachedDocument(
|
||||
'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(),
|
||||
|
||||
Generated
+4
-4
@@ -2116,12 +2116,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/database.git",
|
||||
"reference": "280d9da9421f5b5648260bb31ea8ee3ed3679685"
|
||||
"reference": "2f9c43c0b907f6134a6f0213057a40588439c10e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/280d9da9421f5b5648260bb31ea8ee3ed3679685",
|
||||
"reference": "280d9da9421f5b5648260bb31ea8ee3ed3679685",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/2f9c43c0b907f6134a6f0213057a40588439c10e",
|
||||
"reference": "2f9c43c0b907f6134a6f0213057a40588439c10e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -2166,7 +2166,7 @@
|
||||
"issues": "https://github.com/utopia-php/database/issues",
|
||||
"source": "https://github.com/utopia-php/database/tree/feat-relationships"
|
||||
},
|
||||
"time": "2023-04-05T09:08:19+00:00"
|
||||
"time": "2023-04-05T12:42:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/domains",
|
||||
|
||||
@@ -136,6 +136,7 @@ class Exception extends \Exception
|
||||
public const DOCUMENT_MISSING_PAYLOAD = 'document_missing_payload';
|
||||
public const DOCUMENT_ALREADY_EXISTS = 'document_already_exists';
|
||||
public const DOCUMENT_UPDATE_CONFLICT = 'document_update_conflict';
|
||||
public const DOCUMENT_DELETE_RESTRICTED = 'document_delete_restricted';
|
||||
|
||||
/** Attribute */
|
||||
public const ATTRIBUTE_NOT_FOUND = 'attribute_not_found';
|
||||
|
||||
Reference in New Issue
Block a user