From 5dcb920fb44895caf823d532a706fd2080b462d4 Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 18 Jan 2023 18:27:00 +0100 Subject: [PATCH 1/2] improve the tests --- meilisearch/tests/auth/api_keys.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/meilisearch/tests/auth/api_keys.rs b/meilisearch/tests/auth/api_keys.rs index 03910c0a9..9065b615a 100644 --- a/meilisearch/tests/auth/api_keys.rs +++ b/meilisearch/tests/auth/api_keys.rs @@ -1080,14 +1080,14 @@ async fn patch_api_key_description() { let uid = response["uid"].as_str().unwrap(); - // Add a description - let content = json!({ "description": "Indexing API key" }); + // Add a description and a name + let content = json!({ "description": "Indexing API key", "name": "bob" }); thread::sleep(time::Duration::new(1, 0)); 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": "Indexing API key", "key": "[ignored]", "uid": "[ignored]", @@ -1233,15 +1233,15 @@ async fn patch_api_key_name() { let created_at = response["createdAt"].as_str().unwrap(); let updated_at = response["updatedAt"].as_str().unwrap(); - // Add a name - let content = json!({ "name": "Indexing API key" }); + // Add a name and description + let content = json!({ "name": "Indexing API key", "description": "The doggoscription" }); thread::sleep(time::Duration::new(1, 0)); 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": "Indexing API key", - "description": null, + "description": "The doggoscription", "key": "[ignored]", "uid": "[ignored]", "actions": [ @@ -1302,7 +1302,7 @@ async fn patch_api_key_name() { meili_snap::snapshot!(code, @"200 OK"); // Remove the name - let content = json!({ "name": serde_json::Value::Null }); + let content = json!({ "name": null }); 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###" From d0988e115f61d9bf0d6d90162256bc996029c0ad Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 18 Jan 2023 19:07:26 +0100 Subject: [PATCH 2/2] fix the patch of description and name for the api-key --- meilisearch-auth/src/lib.rs | 11 +++++++++-- meilisearch-types/src/keys.rs | 5 +++-- meilisearch/tests/auth/api_keys.rs | 8 ++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/meilisearch-auth/src/lib.rs b/meilisearch-auth/src/lib.rs index 072b87dad..609409cf7 100644 --- a/meilisearch-auth/src/lib.rs +++ b/meilisearch-auth/src/lib.rs @@ -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 { 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) } diff --git a/meilisearch-types/src/keys.rs b/meilisearch-types/src/keys.rs index 655af9b31..7f81e39ac 100644 --- a/meilisearch-types/src/keys.rs +++ b/meilisearch-types/src/keys.rs @@ -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)] - pub description: Option, + pub description: Setting, #[deserr(default, error = DeserrJsonError)] - pub name: Option, + pub name: Setting, } #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] diff --git a/meilisearch/tests/auth/api_keys.rs b/meilisearch/tests/auth/api_keys.rs index 9065b615a..aa829448b 100644 --- a/meilisearch/tests/auth/api_keys.rs +++ b/meilisearch/tests/auth/api_keys.rs @@ -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": [