Browse Source

Refactor

pull/3732/head
Halil İbrahim Kalkan 7 years ago
parent
commit
fef2488e9d
  1. 1
      modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserCreateOrUpdateDtoBase.cs
  2. 36
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentitySettingDefinitionProvider.cs
  3. 25
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs
  4. 47
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs
  5. 14
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserOrganizationUnit.cs

1
modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserCreateOrUpdateDtoBase.cs

@ -32,6 +32,7 @@ namespace Volo.Abp.Identity
[CanBeNull]
public string[] RoleNames { get; set; }
[CanBeNull]
public Guid[] OrganizationUnits { get; set; }
}
}

36
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentitySettingDefinitionProvider.cs

@ -33,71 +33,83 @@ namespace Volo.Abp.Identity
new SettingDefinition(
IdentitySettingNames.Password.RequireLowercase,
true.ToString(), L("DisplayName:Abp.Identity.Password.RequireLowercase"),
true.ToString(),
L("DisplayName:Abp.Identity.Password.RequireLowercase"),
L("Description:Abp.Identity.Password.RequireLowercase"),
true),
new SettingDefinition(
IdentitySettingNames.Password.RequireUppercase,
true.ToString(), L("DisplayName:Abp.Identity.Password.RequireUppercase"),
true.ToString(),
L("DisplayName:Abp.Identity.Password.RequireUppercase"),
L("Description:Abp.Identity.Password.RequireUppercase"),
true),
new SettingDefinition(
IdentitySettingNames.Password.RequireDigit,
true.ToString(), L("DisplayName:Abp.Identity.Password.RequireDigit"),
true.ToString(),
L("DisplayName:Abp.Identity.Password.RequireDigit"),
L("Description:Abp.Identity.Password.RequireDigit"),
true),
new SettingDefinition(
IdentitySettingNames.Lockout.AllowedForNewUsers,
true.ToString(), L("DisplayName:Abp.Identity.Lockout.AllowedForNewUsers"),
true.ToString(),
L("DisplayName:Abp.Identity.Lockout.AllowedForNewUsers"),
L("Description:Abp.Identity.Lockout.AllowedForNewUsers"),
true),
new SettingDefinition(
IdentitySettingNames.Lockout.LockoutDuration,
(5 * 60).ToString(), L("DisplayName:Abp.Identity.Lockout.LockoutDuration"),
(5 * 60).ToString(),
L("DisplayName:Abp.Identity.Lockout.LockoutDuration"),
L("Description:Abp.Identity.Lockout.LockoutDuration"),
true),
new SettingDefinition(
IdentitySettingNames.Lockout.MaxFailedAccessAttempts,
5.ToString(), L("DisplayName:Abp.Identity.Lockout.MaxFailedAccessAttempts"),
5.ToString(),
L("DisplayName:Abp.Identity.Lockout.MaxFailedAccessAttempts"),
L("Description:Abp.Identity.Lockout.MaxFailedAccessAttempts"),
true),
new SettingDefinition(
IdentitySettingNames.SignIn.RequireConfirmedEmail,
false.ToString(), L("DisplayName:Abp.Identity.SignIn.RequireConfirmedEmail"),
false.ToString(),
L("DisplayName:Abp.Identity.SignIn.RequireConfirmedEmail"),
L("Description:Abp.Identity.SignIn.RequireConfirmedEmail"),
true),
new SettingDefinition(
IdentitySettingNames.SignIn.EnablePhoneNumberConfirmation,
true.ToString(), L("DisplayName:Abp.Identity.SignIn.EnablePhoneNumberConfirmation"),
true.ToString(),
L("DisplayName:Abp.Identity.SignIn.EnablePhoneNumberConfirmation"),
L("Description:Abp.Identity.SignIn.EnablePhoneNumberConfirmation"),
true),
new SettingDefinition(
IdentitySettingNames.SignIn.RequireConfirmedPhoneNumber,
false.ToString(), L("DisplayName:Abp.Identity.SignIn.RequireConfirmedPhoneNumber"),
false.ToString(),
L("DisplayName:Abp.Identity.SignIn.RequireConfirmedPhoneNumber"),
L("Description:Abp.Identity.SignIn.RequireConfirmedPhoneNumber"),
true),
new SettingDefinition(
IdentitySettingNames.User.IsUserNameUpdateEnabled,
true.ToString(), L("DisplayName:Abp.Identity.User.IsUserNameUpdateEnabled"),
true.ToString(),
L("DisplayName:Abp.Identity.User.IsUserNameUpdateEnabled"),
L("Description:Abp.Identity.User.IsUserNameUpdateEnabled"),
true),
new SettingDefinition(
IdentitySettingNames.User.IsEmailUpdateEnabled,
true.ToString(), L("DisplayName:Abp.Identity.User.IsEmailUpdateEnabled"),
true.ToString(),
L("DisplayName:Abp.Identity.User.IsEmailUpdateEnabled"),
L("Description:Abp.Identity.User.IsEmailUpdateEnabled"),
true),
new SettingDefinition(
IdentitySettingNames.OrganizationUnit.MaxUserMembershipCount,
int.MaxValue.ToString(), L("Identity.OrganizationUnit.MaxUserMembershipCount"),
int.MaxValue.ToString(),
L("Identity.OrganizationUnit.MaxUserMembershipCount"),
L("Identity.OrganizationUnit.MaxUserMembershipCount"),
true)
);

25
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs

@ -8,8 +8,6 @@ using Microsoft.AspNetCore.Identity;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.Guids;
using Volo.Abp.Identity.Organizations;
using Volo.Abp.ObjectMapping;
using Volo.Abp.Users;
namespace Volo.Abp.Identity
@ -133,7 +131,6 @@ namespace Volo.Abp.Identity
protected IdentityUser()
{
ExtraProperties = new Dictionary<string, object>();
}
public IdentityUser(Guid id, [NotNull] string userName, [NotNull] string email, Guid? tenantId = null)
@ -286,33 +283,37 @@ namespace Volo.Abp.Identity
public virtual void AddOrganizationUnit(Guid organizationUnitId)
{
Check.NotNull(organizationUnitId, nameof(organizationUnitId));
if (IsInOrganizationUnit(organizationUnitId))
{
return;
}
OrganizationUnits.Add(new IdentityUserOrganizationUnit(TenantId, Id, organizationUnitId));
OrganizationUnits.Add(
new IdentityUserOrganizationUnit(
TenantId,
Id,
organizationUnitId
)
);
}
public virtual void RemoveOrganizationUnit(Guid organizationUnitId)
{
Check.NotNull(organizationUnitId, nameof(organizationUnitId));
if (!IsInOrganizationUnit(organizationUnitId))
{
return;
}
OrganizationUnits.RemoveAll(ou => ou.OrganizationUnitId == organizationUnitId);
OrganizationUnits.RemoveAll(
ou => ou.OrganizationUnitId == organizationUnitId
);
}
public virtual bool IsInOrganizationUnit(Guid organizationUnitId)
{
Check.NotNull(organizationUnitId, nameof(organizationUnitId));
return OrganizationUnits.Any(ou => ou.OrganizationUnitId == organizationUnitId);
return OrganizationUnits.Any(
ou => ou.OrganizationUnitId == organizationUnitId
);
}
public override string ToString()

47
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs

@ -22,14 +22,13 @@ namespace Volo.Abp.Identity
{
protected IIdentityRoleRepository RoleRepository { get; }
protected IIdentityUserRepository UserRepository { get; }
protected IOrganizationUnitRepository OrganizationUnitRepository { get; }
protected IIdentityUserRepository IdentityUserRepository { get; }
protected ISettingProvider SettingProvider { get; }
protected ICancellationTokenProvider CancellationTokenProvider { get; }
protected IOrganizationUnitRepository _organizationUnitRepository { get; private set; }
protected IIdentityUserRepository _identityUserRepository { get; private set; }
private readonly ISettingProvider _settingProvider;
protected override CancellationToken CancellationToken => CancellationTokenProvider.Token;
protected ICancellationTokenProvider CancellationTokenProvider { get; }
public IdentityUserManager(
IdentityUserStore store,
IIdentityRoleRepository roleRepository,
@ -57,9 +56,9 @@ namespace Volo.Abp.Identity
services,
logger)
{
_organizationUnitRepository = organizationUnitRepository;
_identityUserRepository = identityUserRepository;
_settingProvider = settingProvider;
OrganizationUnitRepository = organizationUnitRepository;
IdentityUserRepository = identityUserRepository;
SettingProvider = settingProvider;
RoleRepository = roleRepository;
UserRepository = userRepository;
CancellationTokenProvider = cancellationTokenProvider;
@ -81,7 +80,7 @@ namespace Volo.Abp.Identity
Check.NotNull(user, nameof(user));
Check.NotNull(roleNames, nameof(roleNames));
var currentRoleNames = await GetRolesAsync(user).ConfigureAwait(false);
var currentRoleNames = await GetRolesAsync(user);
var result = await RemoveFromRolesAsync(user, currentRoleNames.Except(roleNames).Distinct());
if (!result.Succeeded)
@ -103,7 +102,7 @@ namespace Volo.Abp.Identity
{
return await IsInOrganizationUnitAsync(
await GetByIdAsync(userId).ConfigureAwait(false),
await _organizationUnitRepository.GetAsync(ouId).ConfigureAwait(false)
await OrganizationUnitRepository.GetAsync(ouId).ConfigureAwait(false)
);
}
@ -115,14 +114,14 @@ namespace Volo.Abp.Identity
public virtual async Task AddToOrganizationUnitAsync(Guid userId, Guid ouId)
{
await AddToOrganizationUnitAsync(
await _identityUserRepository.GetAsync(userId, true).ConfigureAwait(false),
await _organizationUnitRepository.GetAsync(ouId).ConfigureAwait(false)
await IdentityUserRepository.GetAsync(userId, true).ConfigureAwait(false),
await OrganizationUnitRepository.GetAsync(ouId).ConfigureAwait(false)
);
}
public virtual async Task AddToOrganizationUnitAsync(IdentityUser user, OrganizationUnit ou)
{
await _identityUserRepository.EnsureCollectionLoadedAsync(user, u => u.OrganizationUnits, CancellationTokenProvider.Token).ConfigureAwait(false);
await IdentityUserRepository.EnsureCollectionLoadedAsync(user, u => u.OrganizationUnits, CancellationTokenProvider.Token).ConfigureAwait(false);
var currentOus = user.OrganizationUnits;
@ -139,14 +138,14 @@ namespace Volo.Abp.Identity
public virtual async Task RemoveFromOrganizationUnitAsync(Guid userId, Guid ouId)
{
await RemoveFromOrganizationUnitAsync(
await _identityUserRepository.GetAsync(userId, true).ConfigureAwait(false),
await _organizationUnitRepository.GetAsync(ouId).ConfigureAwait(false)
await IdentityUserRepository.GetAsync(userId, true).ConfigureAwait(false),
await OrganizationUnitRepository.GetAsync(ouId).ConfigureAwait(false)
);
}
public virtual async Task RemoveFromOrganizationUnitAsync(IdentityUser user, OrganizationUnit ou)
{
await _identityUserRepository.EnsureCollectionLoadedAsync(user, u => u.OrganizationUnits, CancellationTokenProvider.Token).ConfigureAwait(false);
await IdentityUserRepository.EnsureCollectionLoadedAsync(user, u => u.OrganizationUnits, CancellationTokenProvider.Token).ConfigureAwait(false);
user.RemoveOrganizationUnit(ou.Id);
}
@ -154,7 +153,7 @@ namespace Volo.Abp.Identity
public virtual async Task SetOrganizationUnitsAsync(Guid userId, params Guid[] organizationUnitIds)
{
await SetOrganizationUnitsAsync(
await _identityUserRepository.GetAsync(userId, true).ConfigureAwait(false),
await IdentityUserRepository.GetAsync(userId, true).ConfigureAwait(false),
organizationUnitIds
);
}
@ -166,7 +165,7 @@ namespace Volo.Abp.Identity
await CheckMaxUserOrganizationUnitMembershipCountAsync(user.TenantId, organizationUnitIds.Length);
var currentOus = await _identityUserRepository.GetOrganizationUnitsAsync(user.Id).ConfigureAwait(false);
var currentOus = await IdentityUserRepository.GetOrganizationUnitsAsync(user.Id).ConfigureAwait(false);
//Remove from removed OUs
foreach (var currentOu in currentOus)
@ -184,7 +183,7 @@ namespace Volo.Abp.Identity
{
await AddToOrganizationUnitAsync(
user,
await _organizationUnitRepository.GetAsync(organizationUnitId).ConfigureAwait(false)
await OrganizationUnitRepository.GetAsync(organizationUnitId).ConfigureAwait(false)
);
}
}
@ -192,7 +191,7 @@ namespace Volo.Abp.Identity
private async Task CheckMaxUserOrganizationUnitMembershipCountAsync(Guid? tenantId, int requestedCount)
{
var maxCount = await _settingProvider.GetAsync<int>(IdentitySettingNames.OrganizationUnit.MaxUserMembershipCount).ConfigureAwait(false);
var maxCount = await SettingProvider.GetAsync<int>(IdentitySettingNames.OrganizationUnit.MaxUserMembershipCount).ConfigureAwait(false);
if (requestedCount > maxCount)
{
throw new AbpException(string.Format("Can not set more than {0} organization unit for a user!", maxCount));
@ -202,11 +201,11 @@ namespace Volo.Abp.Identity
[UnitOfWork]
public virtual async Task<List<OrganizationUnit>> GetOrganizationUnitsAsync(IdentityUser user)
{
await _identityUserRepository.EnsureCollectionLoadedAsync(user, u => u.OrganizationUnits, CancellationTokenProvider.Token).ConfigureAwait(false);
await IdentityUserRepository.EnsureCollectionLoadedAsync(user, u => u.OrganizationUnits, CancellationTokenProvider.Token).ConfigureAwait(false);
var ouOfUser = user.OrganizationUnits;
return await _organizationUnitRepository.GetListAsync(ouOfUser.Select(t => t.OrganizationUnitId)).ConfigureAwait(false);
return await OrganizationUnitRepository.GetListAsync(ouOfUser.Select(t => t.OrganizationUnitId)).ConfigureAwait(false);
}
[UnitOfWork]
@ -215,13 +214,13 @@ namespace Volo.Abp.Identity
{
if (includeChildren)
{
return await _identityUserRepository
return await IdentityUserRepository
.GetUsersInOrganizationUnitWithChildrenAsync(organizationUnit.Code)
.ConfigureAwait(false);
}
else
{
return await _identityUserRepository
return await IdentityUserRepository
.GetUsersInOrganizationUnitAsync(organizationUnit.Id)
.ConfigureAwait(false);
}

14
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserOrganizationUnit.cs

@ -1,5 +1,6 @@
using System;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.Identity.Organizations;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Identity
@ -21,7 +22,7 @@ namespace Volo.Abp.Identity
public virtual Guid UserId { get; set; }
/// <summary>
/// Id of the <see cref="OrganizationUnit"/>.
/// Id of the related <see cref="OrganizationUnit"/>.
/// </summary>
public virtual Guid OrganizationUnitId { get; set; }
@ -30,20 +31,11 @@ namespace Volo.Abp.Identity
/// </summary>
public virtual bool IsDeleted { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="UserOrganizationUnit"/> class.
/// </summary>
public IdentityUserOrganizationUnit()
protected IdentityUserOrganizationUnit()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="UserOrganizationUnit"/> class.
/// </summary>
/// <param name="tenantId">TenantId</param>
/// <param name="userId">Id of the User.</param>
/// <param name="organizationUnitId">Id of the <see cref="OrganizationUnit"/>.</param>
public IdentityUserOrganizationUnit(Guid? tenantId, Guid userId, Guid organizationUnitId)
{
TenantId = tenantId;

Loading…
Cancel
Save