3334: Add specific error codes `immutable_...` r=irevoire a=loiclec

Add the following error codes:

When an immutable field of API key is sent to the `PATCH /keys` route: 
- `ImmutableApiKeyUid` 
- `ImmutableApiKeyKey`
- `ImmutableApiKeyActions`
- `ImmutableApiKeyIndexes`
- `ImmutableApiKeyExpiresAt`
- `ImmutableApiKeyCreatedAt`
- `ImmutableApiKeyUpdatedAt`

When an immutable field of Index is sent to the `PATCH /indexes/{uid}` route:
- `ImmutableIndexUid`
- `ImmutableIndexCreatedAt`
- `ImmutableIndexUpdatedAt`

Co-authored-by: Loïc Lecrenier <loic.lecrenier@me.com>
Co-authored-by: Tamo <tamo@meilisearch.com>
This commit is contained in:
bors[bot] 2023-01-12 15:31:38 +00:00 committed by GitHub
commit a5c4fbbcea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 18 deletions

View file

@ -181,7 +181,19 @@ DumpAlreadyProcessing , invalid , CONFLICT;
DumpNotFound , invalid , NOT_FOUND;
DumpProcessFailed , internal , INTERNAL_SERVER_ERROR;
DuplicateIndexFound , invalid , BAD_REQUEST;
ImmutableField , invalid , BAD_REQUEST;
ImmutableApiKeyUid , invalid , BAD_REQUEST;
ImmutableApiKeyKey , invalid , BAD_REQUEST;
ImmutableApiKeyActions , invalid , BAD_REQUEST;
ImmutableApiKeyIndexes , invalid , BAD_REQUEST;
ImmutableApiKeyExpiresAt , invalid , BAD_REQUEST;
ImmutableApiKeyCreatedAt , invalid , BAD_REQUEST;
ImmutableApiKeyUpdatedAt , invalid , BAD_REQUEST;
ImmutableIndexUid , invalid , BAD_REQUEST;
ImmutableIndexCreatedAt , invalid , BAD_REQUEST;
ImmutableIndexUpdatedAt , invalid , BAD_REQUEST;
IndexAlreadyExists , invalid , CONFLICT ;
IndexCreationFailed , internal , INTERNAL_SERVER_ERROR;
IndexNotFound , invalid , NOT_FOUND;

View file

@ -80,12 +80,12 @@ fn deny_immutable_fields_api_key(
));
error.code = match field {
"uid" => Code::ImmutableField,
"actions" => Code::ImmutableField,
"indexes" => Code::ImmutableField,
"expiresAt" => Code::ImmutableField,
"createdAt" => Code::ImmutableField,
"updatedAt" => Code::ImmutableField,
"uid" => Code::ImmutableApiKeyUid,
"actions" => Code::ImmutableApiKeyActions,
"indexes" => Code::ImmutableApiKeyIndexes,
"expiresAt" => Code::ImmutableApiKeyExpiresAt,
"createdAt" => Code::ImmutableApiKeyCreatedAt,
"updatedAt" => Code::ImmutableApiKeyUpdatedAt,
_ => Code::BadRequest,
};
error