Browse Source

OrganizationUnitManager delete update

Internally remove members and roles of deleting organization unit
pull/4186/head
Galip Tolga Erdem 6 years ago
parent
commit
d82f472dba
  1. 4
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/OrganizationUnitManager.cs
  2. 13
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs

4
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/OrganizationUnitManager.cs

@ -80,6 +80,10 @@ namespace Volo.Abp.Identity
await OrganizationUnitRepository.DeleteAsync(child);
}
var organizationUnit = await OrganizationUnitRepository.GetAsync(id);
await OrganizationUnitRepository.RemoveAllMembersAsync(organizationUnit);
await OrganizationUnitRepository.RemoveAllRolesAsync(organizationUnit);
await OrganizationUnitRepository.DeleteAsync(id);
}

13
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs

@ -151,17 +151,12 @@ namespace Volo.Abp.Identity.MongoDB
var users = await DbContext.Users.AsQueryable()
.Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id))
.As<IMongoQueryable<IdentityUser>>()
.ToListAsync(GetCancellationToken(cancellationToken))
;
//var filter = Builders<IdentityUser>.Filter.Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id));
.ToListAsync(GetCancellationToken(cancellationToken));
//var update = Builders<IdentityUser>.Update.PullFilter(y => y.OrganizationUnits, iou=> iou);
//var result = await DbContext.Users.UpdateManyAsync(filter, update);
//TODO: gterdem - Not working, not saving/updating the user. Fix
for (int i = 0; i < users.Count; i++)
foreach (var user in users)
{
users[i].RemoveOrganizationUnit(organizationUnit.Id);
user.RemoveOrganizationUnit(organizationUnit.Id);
DbContext.Users.ReplaceOne(u => u.Id == user.Id, user);
}
}
}

Loading…
Cancel
Save