Skip to content

Commit

Permalink
Updated to localizers preview034
Browse files Browse the repository at this point in the history
  • Loading branch information
JonPSmith committed Dec 24, 2022
1 parent d85374a commit 776c1ba
Show file tree
Hide file tree
Showing 27 changed files with 593 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class LinkToTenantDataService : ILinkToTenantDataService
private readonly IAccessTenantDataCookie _cookieAccessor;

private readonly IEncryptDecryptService _encryptorService;
private readonly IDefaultLocalizer<ResourceLocalize> _localizeDefault;
private readonly IDefaultLocalizer _localizeDefault;

/// <summary>
/// Ctor
Expand All @@ -39,7 +39,7 @@ public LinkToTenantDataService(
AuthPermissionsDbContext context,
AuthPermissionsOptions options,
IAccessTenantDataCookie cookieAccessor,
IEncryptDecryptService encryptorService, IDefaultLocalizer<ResourceLocalize> localizeDefault)
IEncryptDecryptService encryptorService, IDefaultLocalizer localizeDefault)
{
_context = context;
_options = options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Net.LocalizeMessagesAndErrors" Version="1.0.0-preview033" />
<PackageReference Include="Net.LocalizeMessagesAndErrors" Version="1.0.0-preview034" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions AuthPermissions.AspNetCore/Services/ShardingConnections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ShardingConnections : IShardingConnections
private readonly ShardingSettingsOption _shardingSettings;
private readonly AuthPermissionsDbContext _context;
private readonly AuthPermissionsOptions _options;
private readonly IDefaultLocalizer<ResourceLocalize> _localizeDefault;
private readonly IDefaultLocalizer _localizeDefault;

/// <summary>
/// ctor
Expand Down Expand Up @@ -192,7 +192,7 @@ public IStatusGeneric TestFormingConnectionString(DatabaseInformation databaseIn
/// <exception cref="InvalidEnumArgumentException"></exception>
private IStatusGeneric<string> SetDatabaseInConnectionString(DatabaseInformation databaseInformation, string connectionString)
{
var status = new StatusGenericLocalizer<string, ResourceLocalize>(_localizeDefault);
var status = new StatusGenericLocalizer<string>(_localizeDefault);

switch (databaseInformation.DatabaseType)
{
Expand Down
2 changes: 1 addition & 1 deletion AuthPermissions.BaseCode/AuthPermissions.BaseCode.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Net.LocalizeMessagesAndErrors" Version="1.0.0-preview033" />
<PackageReference Include="Net.LocalizeMessagesAndErrors" Version="1.0.0-preview034" />
</ItemGroup>

</Project>
12 changes: 6 additions & 6 deletions AuthPermissions.BaseCode/DataLayer/Classes/AuthUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ private AuthUser(string userId, string email, string userName, List<RoleToPermis
/// <param name="localizeDefault">This provides the localize service</param>
/// <param name="userTenant">optional: defines multi-tenant tenant for this user</param>
public static IStatusGeneric<AuthUser> CreateAuthUser(string userId, string email,
string userName, List<RoleToPermissions> roles, IDefaultLocalizer<ResourceLocalize> localizeDefault,
string userName, List<RoleToPermissions> roles, IDefaultLocalizer localizeDefault,
Tenant userTenant = null)
{
var status = new StatusGenericLocalizer<AuthUser, ResourceLocalize>(localizeDefault);
var status = new StatusGenericLocalizer<AuthUser>(localizeDefault);

status.CombineStatuses(CheckRolesAreValidForUser(roles, userTenant != null, localizeDefault));
if (status.HasErrors)
Expand Down Expand Up @@ -139,12 +139,12 @@ public override string ToString()
/// </summary>
/// <param name="roles">List of roles to replace the current user's roles</param>
/// <param name="localizeDefault"></param>
public IStatusGeneric ReplaceAllRoles(List<RoleToPermissions> roles, IDefaultLocalizer<ResourceLocalize> localizeDefault)
public IStatusGeneric ReplaceAllRoles(List<RoleToPermissions> roles, IDefaultLocalizer localizeDefault)
{
if (_userRoles == null)
throw new AuthPermissionsException($"You must load the {nameof(UserRoles)} before calling this method");

var status = new StatusGenericLocalizer<ResourceLocalize>(localizeDefault);
var status = new StatusGenericLocalizer(localizeDefault);

status.CombineStatuses(CheckRolesAreValidForUser(roles, TenantId != null, localizeDefault));
if (status.HasErrors)
Expand Down Expand Up @@ -200,9 +200,9 @@ public void UpdateIsDisabled(bool isDisabled)
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
private static IStatusGeneric CheckRolesAreValidForUser(List<RoleToPermissions> foundRoles, bool tenantUser,
IDefaultLocalizer<ResourceLocalize> localizeDefault)
IDefaultLocalizer localizeDefault)
{
var status = new StatusGenericLocalizer<ResourceLocalize>(localizeDefault);
var status = new StatusGenericLocalizer(localizeDefault);

foreach (var foundRole in foundRoles)
{
Expand Down
12 changes: 6 additions & 6 deletions AuthPermissions.BaseCode/DataLayer/Classes/Tenant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private Tenant(string tenantFullName, bool isHierarchical, Tenant parent = null)
/// <param name="tenantRoles">Optional: add Roles that have a <see cref="RoleTypes"/> of
/// <see cref="RoleTypes.TenantAutoAdd"/> or <see cref="RoleTypes.TenantAdminAdd"/></param>
public static IStatusGeneric<Tenant> CreateSingleTenant(string fullTenantName,
IDefaultLocalizer<ResourceLocalize> localizeDefault, List<RoleToPermissions> tenantRoles = null)
IDefaultLocalizer localizeDefault, List<RoleToPermissions> tenantRoles = null)
{
var newInstance = new Tenant(fullTenantName, false);
var status = CheckRolesAreAllTenantRolesAndSetTenantRoles(tenantRoles, newInstance, localizeDefault);
Expand All @@ -65,7 +65,7 @@ public static IStatusGeneric<Tenant> CreateSingleTenant(string fullTenantName,
/// <param name="tenantRoles">Optional: add Roles that have a <see cref="RoleTypes"/> of
/// <see cref="RoleTypes.TenantAutoAdd"/> or <see cref="RoleTypes.TenantAdminAdd"/></param>
public static IStatusGeneric<Tenant> CreateHierarchicalTenant(string fullTenantName, Tenant parent,
IDefaultLocalizer<ResourceLocalize> localizeDefault, List<RoleToPermissions> tenantRoles = null)
IDefaultLocalizer localizeDefault, List<RoleToPermissions> tenantRoles = null)
{
var newInstance = new Tenant(fullTenantName, true, parent);
var status = CheckRolesAreAllTenantRolesAndSetTenantRoles(tenantRoles, newInstance, localizeDefault);
Expand Down Expand Up @@ -219,13 +219,13 @@ public void UpdateTenantName(string newNameAtThisLevel)
/// <param name="localizeDefault">localization service</param>
/// <exception cref="AuthPermissionsException"></exception>
/// <exception cref="AuthPermissionsBadDataException"></exception>
public IStatusGeneric UpdateTenantRoles(List<RoleToPermissions> tenantRoles, IDefaultLocalizer<ResourceLocalize> localizeDefault)
public IStatusGeneric UpdateTenantRoles(List<RoleToPermissions> tenantRoles, IDefaultLocalizer localizeDefault)
{
if (_tenantRoles == null)
throw new AuthPermissionsException(
$"You must include the tenant's {nameof(TenantRoles)} in your query before you can add/remove an tenant role.");

var status = new StatusGenericLocalizer<Tenant, ResourceLocalize>(localizeDefault);
var status = new StatusGenericLocalizer<Tenant>(localizeDefault);
return status.CombineStatuses(CheckRolesAreAllTenantRolesAndSetTenantRoles(tenantRoles, this, localizeDefault));
}

Expand Down Expand Up @@ -285,9 +285,9 @@ public static string ExtractEndLeftTenantName(string fullTenantName)
/// <exception cref="AuthPermissionsBadDataException"></exception>
/// <returns>status, with the <see param="thisTenant"/> instance if no errors.</returns>
private static IStatusGeneric<Tenant> CheckRolesAreAllTenantRolesAndSetTenantRoles(
List<RoleToPermissions> tenantRoles, Tenant thisTenant, IDefaultLocalizer<ResourceLocalize> localizeDefault)
List<RoleToPermissions> tenantRoles, Tenant thisTenant, IDefaultLocalizer localizeDefault)
{
var status = new StatusGenericLocalizer<Tenant, ResourceLocalize>(localizeDefault);
var status = new StatusGenericLocalizer<Tenant>(localizeDefault);
status.SetResult(thisTenant);

var badRoles = tenantRoles?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class SaveChangesExtensions
/// <param name="localizeDefault"></param>
/// <returns>Status</returns>
public static IStatusGeneric SaveChangesWithChecks(this DbContext context,
IDefaultLocalizer<ResourceLocalize> localizeDefault)
IDefaultLocalizer localizeDefault)
{
try
{
Expand All @@ -50,7 +50,7 @@ public static IStatusGeneric SaveChangesWithChecks(this DbContext context,
/// <param name="localizeDefault"></param>
/// <returns>Status</returns>
public static async Task<IStatusGeneric> SaveChangesWithChecksAsync(this DbContext context,
IDefaultLocalizer<ResourceLocalize> localizeDefault)
IDefaultLocalizer localizeDefault)
{
try
{
Expand All @@ -72,7 +72,7 @@ public static async Task<IStatusGeneric> SaveChangesWithChecksAsync(this DbConte
private enum ExceptionTypes {Duplicate, ConcurrencyError}

private static IStatusGeneric ConvertExceptionToStatus(this IReadOnlyList<EntityEntry> entities,
ExceptionTypes exceptionType, IDefaultLocalizer<ResourceLocalize> localizeDefault)
ExceptionTypes exceptionType, IDefaultLocalizer localizeDefault)
{
var status = new StatusGenericLocalizer<ResourceLocalize>(localizeDefault);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class AzureAdNewUserManager : IAddNewUserManager
private readonly IAuthTenantAdminService _tenantAdminService;
private readonly IAzureAdAccessService _azureAccessService;
private readonly AzureAdOptions _azureOptions;
private readonly IDefaultLocalizer<ResourceLocalize> _localizeDefault;
private readonly IDefaultLocalizer _localizeDefault;

/// <summary>
/// ctor
Expand Down Expand Up @@ -106,7 +106,7 @@ public Task<IStatusGeneric<AddNewUserDto>> LoginAsync()
if (UserLoginData == null)
throw new AuthPermissionsException($"Must call {nameof(SetUserInfoAsync)} before calling this method.");

var status = new StatusGenericLocalizer<AddNewUserDto, ResourceLocalize>(_localizeDefault);
var status = new StatusGenericLocalizer<AddNewUserDto>(_localizeDefault);
if (UserLoginData.Password == null)
{
status.SetMessageString("SuccessFoundUser".ClassLocalizeKey(this, true),
Expand All @@ -125,7 +125,7 @@ public Task<IStatusGeneric<AddNewUserDto>> LoginAsync()

private async Task<IStatusGeneric<string>> FindOrCreateAzureAdUser(string email)
{
var status = new StatusGenericLocalizer<string, ResourceLocalize>(_localizeDefault);
var status = new StatusGenericLocalizer<string>(_localizeDefault);

var approaches = _azureOptions.AzureAdApproaches?.Split(',')
.Select(x => x.Trim().ToLower()).ToArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public async Task<IStatusGeneric<AddNewUserDto>> LoginAsync()
var user = await _userManager.FindByEmailAsync(UserLoginData.Email);
await _signInManager.SignInAsync(user, isPersistent: UserLoginData.IsPersistent);

var status = new StatusGenericLocalizer<AddNewUserDto, ResourceLocalize>(_localizeDefault);
var status = new StatusGenericLocalizer<AddNewUserDto>(_localizeDefault);
status.SetMessageString("SuccessRegisterLogin".ClassLocalizeKey(this, true),
"You have been registered and logged in to this application.");
return status.SetResult(UserLoginData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class InviteNewUserService : IInviteNewUserService
private readonly IAuthUsersAdminService _usersAdmin;
private readonly AuthPermissionsOptions _options;
private readonly IAddNewUserManager _addNewUserManager;
private IDefaultLocalizer<ResourceLocalize> _localizeDefault;
private readonly IDefaultLocalizer _localizeDefault;

/// <summary>
/// ctor
Expand Down Expand Up @@ -92,7 +92,7 @@ public List<KeyValuePair<long, string>> ListOfExpirationTimes()
/// <returns>status with message and encrypted string containing the data to send the user in a link</returns>
public async Task<IStatusGeneric<string>> CreateInviteUserToJoinAsync(AddNewUserDto invitedUser, string userId)
{
var status = new StatusGenericLocalizer<string, ResourceLocalize>(_localizeDefault);
var status = new StatusGenericLocalizer<string>(_localizeDefault);

if (userId == null)
throw new ArgumentNullException(nameof(userId));
Expand Down Expand Up @@ -239,7 +239,7 @@ public async Task<IStatusGeneric<string>> CreateInviteUserToJoinAsync(AddNewUser
public async Task<IStatusGeneric<AddNewUserDto>> AddUserViaInvite(string inviteParam,
string email, string userName, string password = null, bool isPersistent = false)
{
var status = new StatusGenericLocalizer<AddNewUserDto, ResourceLocalize>(_localizeDefault);
var status = new StatusGenericLocalizer<AddNewUserDto>(_localizeDefault);
var normalizedEmail = email.Trim().ToLower();

AddNewUserDto newUserData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SignInAndCreateTenant : ISignInAndCreateTenant
private readonly AuthPermissionsOptions _options;
private readonly IAuthTenantAdminService _tenantAdmin;
private readonly IAddNewUserManager _addNewUserManager;
private readonly IDefaultLocalizer<ResourceLocalize> _localizeDefault;
private readonly IDefaultLocalizer _localizeDefault;
private readonly IGetDatabaseForNewTenant _getShardingDb;

/// <summary>
Expand Down Expand Up @@ -82,7 +82,7 @@ public async Task<IStatusGeneric<AddNewUserDto>> SignUpNewTenantWithVersionAsync
if (newUser == null) throw new ArgumentNullException(nameof(newUser));
if (tenantData == null) throw new ArgumentNullException(nameof(tenantData));
if (versionData == null) throw new ArgumentNullException(nameof(versionData));
var status = new StatusGenericLocalizer<AddNewUserDto, ResourceLocalize>(_localizeDefault);
var status = new StatusGenericLocalizer<AddNewUserDto>(_localizeDefault);

if (tenantData.TenantName == null)
return status.AddErrorString("NullTenantName".ClassLocalizeKey(this, true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class AzureAdAccessService : IAzureAdAccessService
private readonly ClientSecretCredential _clientSecretCredential;
private readonly string[] _scopes = new[] { "https://graph.microsoft.com/.default" };

private readonly IDefaultLocalizer<ResourceLocalize> _localizeDefault;
private readonly IDefaultLocalizer _localizeDefault;

/// <summary>
/// ctor
Expand Down Expand Up @@ -106,7 +106,7 @@ public async Task<string> FindAzureUserAsync(string email)
/// <returns>status: if error then return message, otherwise Result holds ID of the newly created Azure AD user</returns>
public async Task<IStatusGeneric<string>> CreateNewUserAsync(string email, string userName, string temporaryPassword)
{
var status = new StatusGenericLocalizer<string, ResourceLocalize>(_localizeDefault);
var status = new StatusGenericLocalizer<string>(_localizeDefault);

if (string.IsNullOrWhiteSpace(temporaryPassword)) throw new ArgumentNullException(nameof(temporaryPassword));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class AccessDatabaseInformation : IAccessDatabaseInformation
private readonly IShardingConnections _connectionsService;
private readonly AuthPermissionsDbContext _authDbContext;
private readonly AuthPermissionsOptions _options;
private readonly IDefaultLocalizer<ResourceLocalize> _localizeDefault;
private readonly IDefaultLocalizer _localizeDefault;

/// <summary>
/// Ctor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace AuthPermissions.SupportCode.ShardingServices;
public class DemoGetDatabaseForNewTenant : IGetDatabaseForNewTenant
{
private readonly IShardingConnections _shardingService;
private readonly IDefaultLocalizer<ResourceLocalize> _localizeDefault;
private readonly IDefaultLocalizer _localizeDefault;

/// <summary>
/// ctor
Expand All @@ -39,7 +39,7 @@ public DemoGetDatabaseForNewTenant(IShardingConnections shardingService,
/// <returns>Status with the DatabaseInfoName, or error if it can't find a database to work with</returns>
public async Task<IStatusGeneric<string>> FindBestDatabaseInfoNameAsync(bool hasOwnDb, string region, string version = null)
{
var status = new StatusGenericLocalizer<string, ResourceLocalize>(_localizeDefault);
var status = new StatusGenericLocalizer<string>(_localizeDefault);

//This gets the databases with the info on whether the database is available
var dbsWithUsers = await _shardingService.GetDatabaseInfoNamesWithTenantNamesAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace AuthPermissions.AdminCode.Services
public class AuthRolesAdminService : IAuthRolesAdminService
{
private readonly AuthPermissionsDbContext _context;
private readonly IDefaultLocalizer<ResourceLocalize> _localizeDefault;
private readonly IDefaultLocalizer _localizeDefault;
private readonly Type _permissionType;
private readonly bool _isMultiTenant;

Expand Down
Loading

0 comments on commit 776c1ba

Please sign in to comment.