Skip to content

Server: Add 'expunge' parameter to event-type deletion route #1467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions server/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -6991,6 +6991,17 @@
"type": "string"
},
"style": "simple"
},
{
"description": "By default event types are archived when \"deleted\". Passing this to `true` deletes them entirely.",
"in": "query",
"name": "expunge",
"schema": {
"default": false,
"description": "By default event types are archived when \"deleted\". Passing this to `true` deletes them entirely.",
"type": "boolean"
},
"style": "form"
}
],
"responses": {
Expand Down
20 changes: 18 additions & 2 deletions server/svix-server/src/v1/endpoints/event_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@ async fn patch_event_type(
Ok(Json(ret.into()))
}

#[derive(Debug, Deserialize, Serialize, Validate, JsonSchema)]
struct DeleteEventTypeQueryParams {
/// By default event types are archived when "deleted". Passing this to `true` deletes them
/// entirely.
#[serde(default)]
expunge: bool,
}

/// Archive an event type.
///
/// Endpoints already configured to filter on an event type will continue to do so after archival.
Expand All @@ -412,6 +420,9 @@ async fn patch_event_type(
async fn delete_event_type(
State(AppState { ref db, .. }): State<AppState>,
Path(EventTypeNamePath { event_type_name }): Path<EventTypeNamePath>,
ValidatedQuery(DeleteEventTypeQueryParams { expunge }): ValidatedQuery<
DeleteEventTypeQueryParams,
>,
permissions::Organization { org_id }: permissions::Organization,
) -> Result<NoContent> {
let evtype = eventtype::Entity::secure_find_by_name(org_id, event_type_name)
Expand All @@ -420,8 +431,13 @@ async fn delete_event_type(
.ok_or_else(|| HttpError::not_found(None, None))?;

let mut evtype: eventtype::ActiveModel = evtype.into();
evtype.deleted = Set(true);
evtype.update(db).await?;

if expunge {
evtype.delete(db).await?;
} else {
evtype.deleted = Set(true);
evtype.update(db).await?;
}
Ok(NoContent)
}

Expand Down