mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-29 16:24:26 +01:00
fix the patch of description and name for the api-key
This commit is contained in:
parent
5dcb920fb4
commit
d0988e115f
@ -8,6 +8,7 @@ use std::sync::Arc;
|
||||
|
||||
use error::{AuthControllerError, Result};
|
||||
use meilisearch_types::keys::{Action, CreateApiKey, Key, PatchApiKey};
|
||||
use meilisearch_types::milli::update::Setting;
|
||||
use meilisearch_types::star_or::StarOr;
|
||||
use serde::{Deserialize, Serialize};
|
||||
pub use store::open_auth_store_env;
|
||||
@ -41,8 +42,14 @@ impl AuthController {
|
||||
|
||||
pub fn update_key(&self, uid: Uuid, patch: PatchApiKey) -> Result<Key> {
|
||||
let mut key = self.get_key(uid)?;
|
||||
key.description = patch.description;
|
||||
key.name = patch.name;
|
||||
match patch.description {
|
||||
Setting::NotSet => (),
|
||||
description => key.description = description.set(),
|
||||
};
|
||||
match patch.name {
|
||||
Setting::NotSet => (),
|
||||
name => key.name = name.set(),
|
||||
};
|
||||
key.updated_at = OffsetDateTime::now_utc();
|
||||
self.store.put_api_key(key)
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ use std::str::FromStr;
|
||||
|
||||
use deserr::{DeserializeError, DeserializeFromValue, ValuePointerRef};
|
||||
use enum_iterator::Sequence;
|
||||
use milli::update::Setting;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use time::format_description::well_known::Rfc3339;
|
||||
use time::macros::{format_description, time};
|
||||
@ -78,9 +79,9 @@ fn deny_immutable_fields_api_key(
|
||||
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields = deny_immutable_fields_api_key)]
|
||||
pub struct PatchApiKey {
|
||||
#[deserr(default, error = DeserrJsonError<InvalidApiKeyDescription>)]
|
||||
pub description: Option<String>,
|
||||
pub description: Setting<String>,
|
||||
#[deserr(default, error = DeserrJsonError<InvalidApiKeyName>)]
|
||||
pub name: Option<String>,
|
||||
pub name: Setting<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
|
||||
|
@ -1119,7 +1119,7 @@ async fn patch_api_key_description() {
|
||||
let (response, code) = server.patch_api_key(&uid, content).await;
|
||||
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
|
||||
{
|
||||
"name": null,
|
||||
"name": "bob",
|
||||
"description": "Product API key",
|
||||
"key": "[ignored]",
|
||||
"uid": "[ignored]",
|
||||
@ -1151,7 +1151,7 @@ async fn patch_api_key_description() {
|
||||
let (response, code) = server.patch_api_key(&uid, content).await;
|
||||
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
|
||||
{
|
||||
"name": null,
|
||||
"name": "bob",
|
||||
"description": null,
|
||||
"key": "[ignored]",
|
||||
"uid": "[ignored]",
|
||||
@ -1276,7 +1276,7 @@ async fn patch_api_key_name() {
|
||||
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
|
||||
{
|
||||
"name": "Product API key",
|
||||
"description": null,
|
||||
"description": "The doggoscription",
|
||||
"key": "[ignored]",
|
||||
"uid": "[ignored]",
|
||||
"actions": [
|
||||
@ -1308,7 +1308,7 @@ async fn patch_api_key_name() {
|
||||
meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###"
|
||||
{
|
||||
"name": null,
|
||||
"description": null,
|
||||
"description": "The doggoscription",
|
||||
"key": "[ignored]",
|
||||
"uid": "[ignored]",
|
||||
"actions": [
|
||||
|
Loading…
Reference in New Issue
Block a user