mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-05 04:06:31 +00:00
Add new api key actions
This commit is contained in:
@ -137,6 +137,14 @@ impl HeedAuthStore {
|
|||||||
Action::ChatsSettingsAll => {
|
Action::ChatsSettingsAll => {
|
||||||
actions.extend([Action::ChatsSettingsGet, Action::ChatsSettingsUpdate]);
|
actions.extend([Action::ChatsSettingsGet, Action::ChatsSettingsUpdate]);
|
||||||
}
|
}
|
||||||
|
Action::WebhooksAll => {
|
||||||
|
actions.extend([
|
||||||
|
Action::WebhooksGet,
|
||||||
|
Action::WebhooksUpdate,
|
||||||
|
Action::WebhooksDelete,
|
||||||
|
Action::WebhooksCreate,
|
||||||
|
]);
|
||||||
|
}
|
||||||
other => {
|
other => {
|
||||||
actions.insert(*other);
|
actions.insert(*other);
|
||||||
}
|
}
|
||||||
|
@ -371,6 +371,15 @@ pub enum Action {
|
|||||||
#[serde(rename = "webhooks.update")]
|
#[serde(rename = "webhooks.update")]
|
||||||
#[deserr(rename = "webhooks.update")]
|
#[deserr(rename = "webhooks.update")]
|
||||||
WebhooksUpdate,
|
WebhooksUpdate,
|
||||||
|
#[serde(rename = "webhooks.delete")]
|
||||||
|
#[deserr(rename = "webhooks.delete")]
|
||||||
|
WebhooksDelete,
|
||||||
|
#[serde(rename = "webhooks.create")]
|
||||||
|
#[deserr(rename = "webhooks.create")]
|
||||||
|
WebhooksCreate,
|
||||||
|
#[serde(rename = "webhooks.*")]
|
||||||
|
#[deserr(rename = "webhooks.*")]
|
||||||
|
WebhooksAll,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action {
|
impl Action {
|
||||||
@ -436,7 +445,9 @@ impl Action {
|
|||||||
match self {
|
match self {
|
||||||
// Any action that expands to others must return false, as it wouldn't be able to expand recursively.
|
// Any action that expands to others must return false, as it wouldn't be able to expand recursively.
|
||||||
All | AllGet | DocumentsAll | IndexesAll | ChatsAll | TasksAll | SettingsAll
|
All | AllGet | DocumentsAll | IndexesAll | ChatsAll | TasksAll | SettingsAll
|
||||||
| StatsAll | MetricsAll | DumpsAll | SnapshotsAll | ChatsSettingsAll => false,
|
| StatsAll | MetricsAll | DumpsAll | SnapshotsAll | ChatsSettingsAll | WebhooksAll => {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
Search => true,
|
Search => true,
|
||||||
DocumentsAdd => false,
|
DocumentsAdd => false,
|
||||||
@ -473,6 +484,8 @@ impl Action {
|
|||||||
ChatsSettingsUpdate => false,
|
ChatsSettingsUpdate => false,
|
||||||
WebhooksGet => true,
|
WebhooksGet => true,
|
||||||
WebhooksUpdate => false,
|
WebhooksUpdate => false,
|
||||||
|
WebhooksDelete => false,
|
||||||
|
WebhooksCreate => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -535,6 +548,9 @@ pub mod actions {
|
|||||||
|
|
||||||
pub const WEBHOOKS_GET: u8 = WebhooksGet.repr();
|
pub const WEBHOOKS_GET: u8 = WebhooksGet.repr();
|
||||||
pub const WEBHOOKS_UPDATE: u8 = WebhooksUpdate.repr();
|
pub const WEBHOOKS_UPDATE: u8 = WebhooksUpdate.repr();
|
||||||
|
pub const WEBHOOKS_DELETE: u8 = WebhooksDelete.repr();
|
||||||
|
pub const WEBHOOKS_CREATE: u8 = WebhooksCreate.repr();
|
||||||
|
pub const WEBHOOKS_ALL: u8 = WebhooksAll.repr();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -592,6 +608,9 @@ pub(crate) mod test {
|
|||||||
assert!(AllGet.repr() == 44 && ALL_GET == 44);
|
assert!(AllGet.repr() == 44 && ALL_GET == 44);
|
||||||
assert!(WebhooksGet.repr() == 45 && WEBHOOKS_GET == 45);
|
assert!(WebhooksGet.repr() == 45 && WEBHOOKS_GET == 45);
|
||||||
assert!(WebhooksUpdate.repr() == 46 && WEBHOOKS_UPDATE == 46);
|
assert!(WebhooksUpdate.repr() == 46 && WEBHOOKS_UPDATE == 46);
|
||||||
|
assert!(WebhooksDelete.repr() == 47 && WEBHOOKS_DELETE == 47);
|
||||||
|
assert!(WebhooksCreate.repr() == 48 && WEBHOOKS_CREATE == 48);
|
||||||
|
assert!(WebhooksAll.repr() == 49 && WEBHOOKS_ALL == 49);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -269,7 +269,7 @@ async fn get_webhook(
|
|||||||
|
|
||||||
let webhook = webhooks.webhooks.remove(&uuid).ok_or(WebhookNotFound(uuid))?;
|
let webhook = webhooks.webhooks.remove(&uuid).ok_or(WebhookNotFound(uuid))?;
|
||||||
let webhook = WebhookWithMetadata::from(uuid, webhook);
|
let webhook = WebhookWithMetadata::from(uuid, webhook);
|
||||||
|
|
||||||
debug!(returns = ?webhook, "Get webhook");
|
debug!(returns = ?webhook, "Get webhook");
|
||||||
Ok(HttpResponse::Ok().json(webhook))
|
Ok(HttpResponse::Ok().json(webhook))
|
||||||
}
|
}
|
||||||
@ -294,7 +294,7 @@ async fn get_webhook(
|
|||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
async fn post_webhook(
|
async fn post_webhook(
|
||||||
index_scheduler: GuardedData<ActionPolicy<{ actions::WEBHOOKS_UPDATE }>, Data<IndexScheduler>>,
|
index_scheduler: GuardedData<ActionPolicy<{ actions::WEBHOOKS_CREATE }>, Data<IndexScheduler>>,
|
||||||
webhook_settings: AwebJson<WebhookSettings, DeserrJsonError>,
|
webhook_settings: AwebJson<WebhookSettings, DeserrJsonError>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
analytics: Data<Analytics>,
|
analytics: Data<Analytics>,
|
||||||
@ -400,7 +400,7 @@ async fn patch_webhook(
|
|||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
async fn delete_webhook(
|
async fn delete_webhook(
|
||||||
index_scheduler: GuardedData<ActionPolicy<{ actions::WEBHOOKS_UPDATE }>, Data<IndexScheduler>>,
|
index_scheduler: GuardedData<ActionPolicy<{ actions::WEBHOOKS_DELETE }>, Data<IndexScheduler>>,
|
||||||
uuid: Path<Uuid>,
|
uuid: Path<Uuid>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
analytics: Data<Analytics>,
|
analytics: Data<Analytics>,
|
||||||
|
Reference in New Issue
Block a user