mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-27 15:10:05 +01:00
Merge #3383
3383: Fix api key patch r=irevoire a=irevoire This was introduced in the previous rc Fix https://github.com/meilisearch/meilisearch/issues/3374 Co-authored-by: Tamo <tamo@meilisearch.com>
This commit is contained in:
commit
f857d9c2df
@ -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)]
|
||||
|
@ -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]",
|
||||
@ -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]",
|
||||
@ -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": [
|
||||
@ -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": [
|
||||
@ -1302,13 +1302,13 @@ 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###"
|
||||
{
|
||||
"name": null,
|
||||
"description": null,
|
||||
"description": "The doggoscription",
|
||||
"key": "[ignored]",
|
||||
"uid": "[ignored]",
|
||||
"actions": [
|
||||
|
Loading…
x
Reference in New Issue
Block a user