-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TenantTypes is now [Flags] and has AddSharding
- Loading branch information
Showing
16 changed files
with
201 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
AuthPermissions/AdminCode/Services/Internal/ChangeRoleTypeChecks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2022 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ | ||
// Licensed under MIT license. See License.txt in the project root for license information. | ||
|
||
using AuthPermissions.CommonCode; | ||
using AuthPermissions.SetupCode; | ||
|
||
namespace AuthPermissions.AdminCode; | ||
|
||
public static class TenantTypeExtensions | ||
{ | ||
public static void ThrowExceptionIfTenantTypeIsWrong(this TenantTypes tenantType) | ||
{ | ||
if (tenantType.HasFlag(TenantTypes.SingleLevel) && tenantType.HasFlag(TenantTypes.HierarchicalTenant)) | ||
throw new AuthPermissionsException( | ||
$"The {nameof(AuthPermissionsOptions.TenantType)} option can't have {nameof(TenantTypes.SingleLevel)} and "+ | ||
$"{nameof(TenantTypes.HierarchicalTenant)} at the same time."); | ||
|
||
if (!tenantType.IsMultiTenant() && tenantType.HasFlag(TenantTypes.AddSharding)) | ||
throw new AuthPermissionsException( | ||
$"You need to set the {nameof(AuthPermissionsOptions.TenantType)} option to either {nameof(TenantTypes.SingleLevel)} or " + | ||
$"{nameof(TenantTypes.HierarchicalTenant)} when setting the {nameof(TenantTypes.AddSharding)} flag."); | ||
|
||
} | ||
|
||
public static bool IsMultiTenant(this TenantTypes tenantType) | ||
{ | ||
return tenantType.HasFlag(TenantTypes.SingleLevel) || tenantType.HasFlag(TenantTypes.HierarchicalTenant); | ||
} | ||
|
||
public static bool IsSingleLevel(this TenantTypes tenantType) | ||
{ | ||
return tenantType.HasFlag(TenantTypes.SingleLevel); | ||
} | ||
|
||
public static bool IsHierarchical(this TenantTypes tenantType) | ||
{ | ||
return tenantType.HasFlag(TenantTypes.HierarchicalTenant); | ||
} | ||
|
||
public static bool UsingSharding(this TenantTypes tenantType) | ||
{ | ||
return tenantType.HasFlag(TenantTypes.AddSharding); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,39 @@ | ||
// Copyright (c) 2021 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/ | ||
// Licensed under MIT license. See License.txt in the project root for license information. | ||
|
||
using System; | ||
|
||
namespace AuthPermissions.SetupCode | ||
{ | ||
/// <summary> | ||
/// This defines the types of tenant the AuthPermissions can handle | ||
/// This defines the types of tenant the AuthPermissions can handle, with optional sharding | ||
/// </summary> | ||
[Flags] | ||
public enum TenantTypes | ||
{ | ||
/// <summary> | ||
/// Usage of tenants are turned off | ||
/// </summary> | ||
NotUsingTenants, | ||
NotUsingTenants = 0, | ||
/// <summary> | ||
/// Multi-tenant with one level only, e.g. a company has different departments: sales, finance, HR etc. | ||
/// A User can only be in one of these levels | ||
/// </summary> | ||
SingleLevel, | ||
SingleLevel = 1, | ||
/// <summary> | ||
/// Multi-tenant with one level only, e.g. a company has different departments: sales, finance, HR etc. | ||
/// A tenant can be mixed in with | ||
/// </summary> | ||
/// <summary> | ||
/// Multi-tenant many levels, e.g. Holding company -> USA branch -> East Coast -> New York | ||
/// A User at the USA branch has read/write access to the USA branch data, read-only access to the East Coast and all its subsidiaries | ||
/// </summary> | ||
HierarchicalTenant | ||
HierarchicalTenant = 2, | ||
/// <summary> | ||
/// This turns on the sharding. Sharding allows tenants to be split across many databases, including placing a tenant's data in its own database. | ||
/// | ||
/// </summary> | ||
AddSharding = 4 | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
82e9ba63-1e53-4c0b-9a78-c3704baf399c | ||
8db6e054-0ea3-42f9-a143-4cba433737f7 |
Oops, something went wrong.