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

Function update_user

chirpstack/src/storage/tenant.rs:411–511  ·  view source on GitHub ↗
(
    tu: TenantUser,
    device_profiles: &[TenantUserDeviceProfile],
    applications: &[TenantUserApplication],
)

Source from the content-addressed store, hash-verified

409}
410
411pub async fn update_user(
412 tu: TenantUser,
413 device_profiles: &[TenantUserDeviceProfile],
414 applications: &[TenantUserApplication],
415) -> Result<TenantUser, Error> {
416 let mut c = get_async_db_conn().await?;
417 let tu: TenantUser = c
418 .transaction::<TenantUser, Error, _>(async |c| {
419 let tu: TenantUser = diesel::update(
420 tenant_user::dsl::tenant_user
421 .filter(tenant_user::dsl::tenant_id.eq(&tu.tenant_id))
422 .filter(tenant_user::dsl::user_id.eq(&tu.user_id)),
423 )
424 .set(&tu)
425 .get_result(c)
426 .await
427 .map_err(|e| Error::from_diesel(e, tu.user_id.to_string()))?;
428
429 // delete device-profile links
430 diesel::delete(
431 tenant_user_device_profile::table.filter(
432 tenant_user_device_profile::user_id.eq(&tu.user_id).and(
433 tenant_user_device_profile::device_profile_id.eq_any(
434 device_profile::table
435 .filter(device_profile::tenant_id.eq(&tu.tenant_id))
436 .select(device_profile::id),
437 ),
438 ),
439 ),
440 )
441 .execute(c)
442 .await
443 .map_err(|e| Error::from_diesel(e, tu.user_id.to_string()))?;
444
445 // delete application links
446 diesel::delete(
447 tenant_user_application::table.filter(
448 tenant_user_application::user_id.eq(&tu.user_id).and(
449 tenant_user_application::application_id.eq_any(
450 application::table
451 .filter(application::tenant_id.eq(&tu.tenant_id))
452 .select(application::id),
453 ),
454 ),
455 ),
456 )
457 .execute(c)
458 .await
459 .map_err(|e| Error::from_diesel(e, tu.user_id.to_string()))?;
460
461 // re-create device-profiles
462 for dp in device_profiles {
463 // make sure dp exists under same tenant
464 let _: storage::device_profile::DeviceProfile = device_profile::table
465 .filter(
466 device_profile::id
467 .eq(dp.device_profile_id)
468 .and(device_profile::tenant_id.eq(&tu.tenant_id)),

Callers 1

update_userMethod · 0.85

Calls 5

setMethod · 0.80
to_stringMethod · 0.80
get_async_db_connFunction · 0.70
updateFunction · 0.70
deleteFunction · 0.70

Tested by

no test coverage detected