-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4165 from systeminit/feat-sdf-dal-Add-ability-to-…
…delete-unlocked-schema-variants feat(sdf, dal): Add ability to delete unlocked schema variants
- Loading branch information
Showing
5 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
mod clone_variant; | ||
mod create_variant; | ||
mod delete_unlocked_variant; | ||
mod save_variant; | ||
mod unlock_and_edit_variant; | ||
mod update_variant; |
66 changes: 66 additions & 0 deletions
66
lib/dal/tests/integration_test/schema/variant/authoring/delete_unlocked_variant.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use dal::schema::variant::authoring::VariantAuthoringClient; | ||
use dal::{DalContext, Func, SchemaVariant}; | ||
use dal_test::helpers::ChangeSetTestHelpers; | ||
use dal_test::test; | ||
|
||
#[test] | ||
async fn delete_unlocked_variant(ctx: &mut DalContext) { | ||
let asset_name = "chainsawVariant".to_string(); | ||
let description = None; | ||
let link = None; | ||
let category = "Integration Tests".to_string(); | ||
let color = "#00b0b0".to_string(); | ||
let variant = VariantAuthoringClient::create_schema_and_variant( | ||
ctx, | ||
asset_name.clone(), | ||
description.clone(), | ||
link.clone(), | ||
category.clone(), | ||
color.clone(), | ||
) | ||
.await | ||
.expect("Unable to create new asset"); | ||
|
||
let variant_id = variant.id(); | ||
|
||
ChangeSetTestHelpers::commit_and_update_snapshot_to_visibility(ctx) | ||
.await | ||
.expect("unable to commit"); | ||
|
||
let asset_func = Func::get_by_id_or_error( | ||
ctx, | ||
variant | ||
.asset_func_id() | ||
.expect("unable to get asset func id from variant"), | ||
) | ||
.await | ||
.expect("unable to get asset authoring func"); | ||
|
||
assert!(!asset_func.is_locked); | ||
|
||
let locked_variant = variant | ||
.lock(ctx) | ||
.await | ||
.expect("unable to lock the schema variant"); | ||
asset_func | ||
.lock(ctx) | ||
.await | ||
.expect("unable to lock the asset func"); | ||
|
||
ChangeSetTestHelpers::commit_and_update_snapshot_to_visibility(ctx) | ||
.await | ||
.expect("unable to commit"); | ||
|
||
// We can't delete the variant in a locked format | ||
let res = SchemaVariant::cleanup_unlocked_variant(ctx, locked_variant.id).await; | ||
assert!(res.is_err()); | ||
|
||
// let's create an unlocked copy to ensure we can remove it | ||
let unlocked_schema_variant = | ||
VariantAuthoringClient::create_unlocked_variant_copy(ctx, variant_id) | ||
.await | ||
.expect("unable to create an unlocked copy of a schema variant"); | ||
|
||
let res = SchemaVariant::cleanup_unlocked_variant(ctx, unlocked_schema_variant.id).await; | ||
assert!(res.is_ok()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
lib/sdf-server/src/server/service/v2/variant/delete_unlocked_variant.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use axum::{ | ||
extract::{OriginalUri, Path}, | ||
response::IntoResponse, | ||
}; | ||
use dal::{ChangeSet, ChangeSetId, SchemaVariant, SchemaVariantId, WorkspacePk}; | ||
|
||
use crate::server::{ | ||
extract::{AccessBuilder, HandlerContext, PosthogClient}, | ||
tracking::track, | ||
}; | ||
|
||
use super::SchemaVariantsAPIResult; | ||
|
||
pub async fn delete_unlocked_variant( | ||
HandlerContext(builder): HandlerContext, | ||
AccessBuilder(access_builder): AccessBuilder, | ||
PosthogClient(posthog_client): PosthogClient, | ||
OriginalUri(original_uri): OriginalUri, | ||
Path((_workspace_pk, change_set_id, schema_variant_id)): Path<( | ||
WorkspacePk, | ||
ChangeSetId, | ||
SchemaVariantId, | ||
)>, | ||
) -> SchemaVariantsAPIResult<impl IntoResponse> { | ||
let mut ctx = builder | ||
.build(access_builder.build(change_set_id.into())) | ||
.await?; | ||
let force_change_set_id = ChangeSet::force_new(&mut ctx).await?; | ||
let schema_variant = SchemaVariant::get_by_id_or_error(&ctx, schema_variant_id).await?; | ||
|
||
SchemaVariant::cleanup_unlocked_variant(&ctx, schema_variant_id).await?; | ||
|
||
track( | ||
&posthog_client, | ||
&ctx, | ||
&original_uri, | ||
"delete_unlocked_variant", | ||
serde_json::json!({ | ||
"schema_variant_id": schema_variant_id, | ||
"schema_variant_name": schema_variant.display_name(), | ||
"schema_variant_version": schema_variant.version(), | ||
}), | ||
); | ||
ctx.commit().await?; | ||
|
||
let mut response = axum::response::Response::builder(); | ||
response = response.header("Content-Type", "application/json"); | ||
if let Some(force_change_set_id) = force_change_set_id { | ||
response = response.header("force_change_set_id", force_change_set_id.to_string()); | ||
} | ||
|
||
Ok(response.body(serde_json::to_string(&schema_variant_id)?)?) | ||
} |