From c251b527b00304c3c0691d186b26fdbdbb5c216e Mon Sep 17 00:00:00 2001 From: Phillip Davis Date: Mon, 4 Jul 2022 21:07:47 -0400 Subject: [PATCH] Add iterators over * for stats, dumps, tasks, settings, and indexes; change documents impl to prevent duplication --- meilisearch-auth/src/store.rs | 78 +++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/meilisearch-auth/src/store.rs b/meilisearch-auth/src/store.rs index f9d6e7728..13515ca7c 100644 --- a/meilisearch-auth/src/store.rs +++ b/meilisearch-auth/src/store.rs @@ -92,13 +92,77 @@ impl HeedAuthStore { Action::into_enum_iter().collect() } else if key.actions.contains(&Action::DocumentsAll) { // if key.actions.contains.DocumentsAll add all actions related to documents. - let mut actions = key.actions.clone(); - actions.append(&mut vec![ - Action::DocumentsAdd, - Action::DocumentsGet, - Action::DocumentsDelete, - ]); - actions + key.actions.iter() + .cloned() + .filter(|action|{ // Prevents duplicate entries in the actions vector + *action != Action::DocumentsAdd && + *action != Action::DocumentsDelete && + *action != Action::DocumentsGet + }) + .chain(vec![ + Action::DocumentsAdd, + Action::DocumentsDelete, + Action::DocumentsGet + ]) + .collect() + } else if key.actions.contains(&Action::IndexesAll) { + key.actions.iter() + .cloned() + .filter(|action|{ + *action != Action::IndexesAdd && + *action != Action::IndexesGet && + *action != Action::IndexesDelete && + *action != Action::IndexesUpdate + }) + .chain(vec![ + Action::IndexesAdd, + Action::IndexesGet, + Action::IndexesDelete, + Action::IndexesUpdate + ]) + .collect() + } else if key.actions.contains(&Action::SettingsAll) { + key.actions.iter() + .cloned() + .filter(|action|{ + *action != Action::SettingsGet && + *action != Action::SettingsUpdate + }) + .chain(vec![ + Action::SettingsGet, + Action::SettingsUpdate + ]) + .collect() + } else if key.actions.contains(&Action::TasksAll) { + key.actions.iter() + .cloned() + .filter(|action|{ + *action != Action::TasksGet + }) + .chain(vec![ + Action::TasksGet + ]) + .collect() + } else if key.actions.contains(&Action::DumpsAll) { + key.actions.iter() + .cloned() + .filter(|action|{ + *action != Action::DumpsCreate + }) + .chain(vec![ + Action::DumpsCreate + ]) + .collect() + } else if key.actions.contains(&Action::StatsAll) { + key.actions.iter() + .cloned() + .filter(|action|{ + *action != Action::StatsGet + }) + .chain(vec![ + Action::StatsGet + ]) + .collect() } else { key.actions.clone() };