-
Notifications
You must be signed in to change notification settings - Fork 271
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
Instrument more audit log events #5151
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,9 @@ use axum::{ | |
}; | ||
use dal::{ | ||
func::binding::{attribute::AttributeBinding, EventualParent}, | ||
ChangeSet, ChangeSetId, Func, FuncId, SchemaVariant, WorkspacePk, WsEvent, | ||
ChangeSet, ChangeSetId, Component, Func, FuncId, SchemaVariant, WorkspacePk, WsEvent, | ||
}; | ||
use si_events::audit_log::AuditLogKind; | ||
use si_frontend_types as frontend_types; | ||
|
||
use crate::{ | ||
|
@@ -51,15 +52,42 @@ pub async fn reset_attribute_binding( | |
) | ||
.await?; | ||
|
||
if let EventualParent::SchemaVariant(schema_variant_id) = eventual_parent { | ||
let schema = | ||
SchemaVariant::schema_id_for_schema_variant_id(&ctx, schema_variant_id).await?; | ||
let schema_variant = SchemaVariant::get_by_id_or_error(&ctx, schema_variant_id).await?; | ||
|
||
WsEvent::schema_variant_updated(&ctx, schema, schema_variant) | ||
.await? | ||
.publish_on_commit(&ctx) | ||
match eventual_parent { | ||
EventualParent::SchemaVariant(schema_variant_id) => { | ||
let schema = | ||
SchemaVariant::schema_id_for_schema_variant_id(&ctx, schema_variant_id).await?; | ||
let schema_variant = | ||
SchemaVariant::get_by_id_or_error(&ctx, schema_variant_id).await?; | ||
ctx.write_audit_log( | ||
AuditLogKind::DetachFunc { | ||
func_id, | ||
func_display_name: func.display_name.clone(), | ||
schema_variant_id: Some(schema_variant_id), | ||
component_id: None, | ||
subject_name: schema_variant.display_name().to_owned(), | ||
}, | ||
func.name.clone(), | ||
) | ||
.await?; | ||
WsEvent::schema_variant_updated(&ctx, schema, schema_variant) | ||
.await? | ||
.publish_on_commit(&ctx) | ||
.await?; | ||
} | ||
EventualParent::Component(component_id) => { | ||
let component = Component::get_by_id(&ctx, component_id).await?; | ||
ctx.write_audit_log( | ||
AuditLogKind::DetachFunc { | ||
func_id, | ||
func_display_name: func.display_name.clone(), | ||
schema_variant_id: None, | ||
component_id: Some(component_id), | ||
subject_name: component.name(&ctx).await?.to_owned(), | ||
}, | ||
func.name.clone(), | ||
) | ||
.await?; | ||
} | ||
Comment on lines
+77
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great use of breaking out an enum MyEnum {
One
Two
Three
}
impl MyEnum {
pub fn name(&self) -> &'static str {
match self {
One => "one"
Two => "one"
Three => "one"
}
}
} By using a If that function instead used I bring this all up since this is a great example of a sneaky |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit for the future: I like to use
Self
when possible for readability and suppleness for refactoring. So the first one would beSelf::Prop
instead ofAttributeFuncDestination::Prop
.