MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / delete_user

Function delete_user

chirpstack/src/storage/tenant.rs:598–645  ·  view source on GitHub ↗
(tenant_id: &Uuid, user_id: &Uuid)

Source from the content-addressed store, hash-verified

596}
597
598pub async fn delete_user(tenant_id: &Uuid, user_id: &Uuid) -> Result<(), Error> {
599 // delete device-profile admin references
600 diesel::delete(
601 tenant_user_device_profile::table
602 .filter(tenant_user_device_profile::user_id.eq(&fields::Uuid::from(user_id)))
603 .filter(
604 tenant_user_device_profile::device_profile_id.eq_any(
605 device_profile::table
606 .filter(device_profile::tenant_id.eq(&fields::Uuid::from(tenant_id)))
607 .select(device_profile::id),
608 ),
609 ),
610 )
611 .execute(&mut get_async_db_conn().await?)
612 .await?;
613
614 // delete application admin references
615 diesel::delete(
616 tenant_user_application::table
617 .filter(tenant_user_application::user_id.eq(&fields::Uuid::from(user_id)))
618 .filter(
619 tenant_user_application::application_id.eq_any(
620 application::table
621 .filter(application::tenant_id.eq(&fields::Uuid::from(tenant_id)))
622 .select(application::id),
623 ),
624 ),
625 )
626 .execute(&mut get_async_db_conn().await?)
627 .await?;
628
629 let ra = diesel::delete(
630 tenant_user::dsl::tenant_user
631 .filter(tenant_user::dsl::tenant_id.eq(&fields::Uuid::from(tenant_id)))
632 .filter(tenant_user::dsl::user_id.eq(&fields::Uuid::from(user_id))),
633 )
634 .execute(&mut get_async_db_conn().await?)
635 .await?;
636 if ra == 0 {
637 return Err(Error::NotFound(user_id.to_string()));
638 }
639 info!(
640 tenant_id = %tenant_id,
641 user_id = %user_id,
642 "Tenant user deleted"
643 );
644 Ok(())
645}
646
647pub async fn get_tenant_users_for_user(user_id: &Uuid) -> Result<Vec<TenantUser>, Error> {
648 let items = tenant_user::dsl::tenant_user

Callers 2

test_tenant_userFunction · 0.85
delete_userMethod · 0.85

Calls 3

to_stringMethod · 0.80
deleteFunction · 0.70
get_async_db_connFunction · 0.70

Tested by 1

test_tenant_userFunction · 0.68