tmail-backend icon indicating copy to clipboard operation
tmail-backend copied to clipboard

Implement callback for update PublicAsset when remove IdentityId

Open vttranlina opened this issue 9 months ago • 0 comments

Why?

When I remove an identity, other identity ids shall be removed in the background original: https://github.com/linagora/tmail-backend/issues/1050#issuecomment-2113360165

How

  • Requirement: https://github.com/linagora/james-project/issues/5198
  • Create a class PublicAssetIdentityCallback extends IdentityCallback, The code looks like this:
class PublicAssetIdentityCallback @Inject()(publicAssetRepository: PublicAssetRepository) extends IdentityCallback {

  override def identityRemoved(username: Username, identityId: IdentityId): Publisher[Void] = {
    // get all public assets for the user
    // then filter the public assets that have the identityId
    // then remove the identityId from the public asset
    SFlux(publicAssetRepository.list(username))
      .flatMap(publicAsset => {
        val updatedIdentityIds: Seq[IdentityId] = publicAsset.identityIds.filterNot(_ == identityId)
        publicAssetRepository.update(username, publicAsset.id, updatedIdentityIds.toSet)
      })
      .`then`()
  }
}

Dod

  • Unit test
  • jmap integration test

vttranlina avatar May 22 '24 04:05 vttranlina