From b89fd49d632098297c81a2171e4c6ceb3e741ef0 Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:12:47 +0300 Subject: [PATCH] Fix some 'all' flags making problems --- dump/src/reader/compat/v5_to_v6.rs | 6 +++--- meilisearch-auth/src/store.rs | 20 ++++---------------- meilisearch-types/src/keys.rs | 19 ++----------------- 3 files changed, 9 insertions(+), 36 deletions(-) diff --git a/dump/src/reader/compat/v5_to_v6.rs b/dump/src/reader/compat/v5_to_v6.rs index 40a055465..2f6f52937 100644 --- a/dump/src/reader/compat/v5_to_v6.rs +++ b/dump/src/reader/compat/v5_to_v6.rs @@ -405,11 +405,11 @@ impl From for v6::Action { v5::Action::SettingsAll => v6::Action::SettingsAll, v5::Action::SettingsGet => v6::Action::SettingsGet, v5::Action::SettingsUpdate => v6::Action::SettingsUpdate, - v5::Action::StatsAll => v6::Action::StatsAll, + v5::Action::StatsAll => v6::Action::StatsGet, v5::Action::StatsGet => v6::Action::StatsGet, - v5::Action::MetricsAll => v6::Action::MetricsAll, + v5::Action::MetricsAll => v6::Action::MetricsGet, v5::Action::MetricsGet => v6::Action::MetricsGet, - v5::Action::DumpsAll => v6::Action::DumpsAll, + v5::Action::DumpsAll => v6::Action::DumpsCreate, v5::Action::DumpsCreate => v6::Action::DumpsCreate, v5::Action::Version => v6::Action::Version, v5::Action::KeysAdd => v6::Action::KeysAdd, diff --git a/meilisearch-auth/src/store.rs b/meilisearch-auth/src/store.rs index 1bcee31e8..62aa445fa 100644 --- a/meilisearch-auth/src/store.rs +++ b/meilisearch-auth/src/store.rs @@ -128,21 +128,9 @@ impl HeedAuthStore { Action::SettingsAll => { actions.extend([Action::SettingsGet, Action::SettingsUpdate].iter()); } - Action::DumpsAll => { - actions.insert(Action::DumpsCreate); - } - Action::SnapshotsAll => { - actions.insert(Action::SnapshotsCreate); - } Action::TasksAll => { actions.extend([Action::TasksGet, Action::TasksDelete, Action::TasksCancel]); } - Action::StatsAll => { - actions.insert(Action::StatsGet); - } - Action::MetricsAll => { - actions.insert(Action::MetricsGet); - } other => { actions.insert(other); } @@ -294,8 +282,8 @@ impl HeedAuthStore { pub struct KeyIdActionCodec; impl KeyIdActionCodec { - fn action_parts_to_repr([p1, p2, p3, p4]: &[u8; 4]) -> u32 { - ((p1 << 24) | (p2 << 16) | (p3 << 8) | p4) as u32 + fn action_parts_to_32bits([p1, p2, p3, p4]: &[u8; 4]) -> u32 { + ((*p1 as u32) << 24) | ((*p2 as u32) << 16) | ((*p3 as u32) << 8) | (*p4 as u32) } } @@ -306,8 +294,8 @@ impl<'a> milli::heed::BytesDecode<'a> for KeyIdActionCodec { let (key_id_bytes, action_bytes) = try_split_array_at(bytes).ok_or(SliceTooShortError)?; let (action_bits, index) = match try_split_array_at::(action_bytes).ok_or(SliceTooShortError)? { - (action_parts, []) => (Self::action_parts_to_repr(action_parts), None), - (action_parts, index) => (Self::action_parts_to_repr(action_parts), Some(index)), + (action_parts, []) => (Self::action_parts_to_32bits(action_parts), None), + (action_parts, index) => (Self::action_parts_to_32bits(action_parts), Some(index)), }; let key_id = Uuid::from_bytes(*key_id_bytes); let action = Action::from_bits(action_bits).ok_or(InvalidActionError { action_bits })?; diff --git a/meilisearch-types/src/keys.rs b/meilisearch-types/src/keys.rs index a6343999f..b33a6f26a 100644 --- a/meilisearch-types/src/keys.rs +++ b/meilisearch-types/src/keys.rs @@ -206,18 +206,10 @@ bitflags! { const SettingsGet = 1 << 12; const SettingsUpdate = 1 << 13; const SettingsAll = Self::SettingsGet.bits() | Self::SettingsUpdate.bits(); - // Stats const StatsGet = 1 << 14; - const StatsAll = Self::StatsGet.bits(); - // Metrics const MetricsGet = 1 << 15; - const MetricsAll = Self::MetricsGet.bits(); - // Dumps const DumpsCreate = 1 << 16; - const DumpsAll = Self::DumpsCreate.bits(); - // Snapshots const SnapshotsCreate = 1 << 17; - const SnapshotsAll = Self::SnapshotsCreate.bits(); const Version = 1 << 18; const KeysAdd = 1 << 19; const KeysGet = 1 << 20; @@ -240,7 +232,7 @@ bitflags! { } impl Action { - const SERDE_MAP_ARR: [(&'static str, Self); 34] = [ + const SERDE_MAP_ARR: [(&'static str, Self); 30] = [ ("search", Self::Search), ("documents.add", Self::DocumentsAdd), ("documents.get", Self::DocumentsGet), @@ -260,13 +252,9 @@ impl Action { ("settings.update", Self::SettingsUpdate), ("settings.*", Self::SettingsAll), ("stats.get", Self::StatsGet), - ("stats.*", Self::StatsAll), ("metrics.get", Self::MetricsGet), - ("metrics.*", Self::MetricsAll), ("dumps.create", Self::DumpsCreate), - ("dumps.*", Self::DumpsAll), ("snapshots.create", Self::SnapshotsCreate), - ("snapshots.*", Self::SnapshotsAll), ("version", Self::Version), ("keys.create", Self::KeysAdd), ("keys.get", Self::KeysGet), @@ -315,11 +303,8 @@ pub mod actions { pub const SETTINGS_UPDATE: u32 = A::SettingsUpdate.bits(); pub const SETTINGS_ALL: u32 = A::SettingsAll.bits(); pub const STATS_GET: u32 = A::StatsGet.bits(); - pub const STATS_ALL: u32 = A::StatsAll.bits(); pub const METRICS_GET: u32 = A::MetricsGet.bits(); - pub const METRICS_ALL: u32 = A::MetricsAll.bits(); pub const DUMPS_CREATE: u32 = A::DumpsCreate.bits(); - pub const DUMPS_ALL: u32 = A::DumpsAll.bits(); pub const SNAPSHOTS_CREATE: u32 = A::SnapshotsCreate.bits(); pub const VERSION: u32 = A::Version.bits(); pub const KEYS_CREATE: u32 = A::KeysAdd.bits(); @@ -411,7 +396,7 @@ impl Sequence for Action { } } - Non + None } fn previous(&self) -> Option {