diff --git a/meilisearch-auth/src/store.rs b/meilisearch-auth/src/store.rs index ef992e836..237570522 100644 --- a/meilisearch-auth/src/store.rs +++ b/meilisearch-auth/src/store.rs @@ -105,7 +105,7 @@ impl HeedAuthStore { let mut actions = HashSet::new(); for action in &key.actions { - match action { + match *action { Action::All => actions.extend(enum_iterator::all::()), Action::DocumentsAll => { actions.extend( diff --git a/meilisearch-types/src/keys.rs b/meilisearch-types/src/keys.rs index 459fdf8ca..537567e5c 100644 --- a/meilisearch-types/src/keys.rs +++ b/meilisearch-types/src/keys.rs @@ -4,8 +4,9 @@ use std::str::FromStr; use bitflags::bitflags; use deserr::{take_cf_content, DeserializeError, Deserr, MergeWithError, ValuePointerRef}; +use enum_iterator::Sequence; use milli::update::Setting; -use serde::{Deserialize, Deserializer, Serialize}; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; use time::format_description::well_known::Rfc3339; use time::macros::{format_description, time}; use time::{Date, OffsetDateTime, PrimitiveDateTime}; @@ -180,7 +181,7 @@ fn parse_expiration_date( } bitflags! { - #[derive(Copy, Clone, Serialize, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)] + #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)] #[repr(transparent)] pub struct Action: u8 { const All = 0; @@ -361,6 +362,20 @@ impl<'de> Deserialize<'de> for Action { } } +impl Serialize for Action { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + Self::SERIALIZATION_MAP + .iter() + .find(|(_, action)| self == action) + .map(|(serialized, _)| serializer.serialize_str(serialized)) + // should always be found, so unwrap is safe to use + .unwrap() + } +} + pub mod actions { use super::Action as A;