This commit is contained in:
2021-03-17 00:11:42 +00:00
parent 8405c444db
commit 040e12c978
2 changed files with 18 additions and 7 deletions

View File

@@ -58,6 +58,7 @@ namespace AyaNova.Api.ControllerHelpers
internal static bool HasAnyRole(AuthorizationRoles currentUserRoles, AyaType objectType)
{
var RoleSet = BizRoles.GetRoleSet(objectType);
if (RoleSet == null) return false;
var AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change | RoleSet.Select;
return currentUserRoles.HasAnyFlags(AllowedRoles);
}
@@ -82,14 +83,17 @@ namespace AyaNova.Api.ControllerHelpers
/// <returns></returns>
internal static bool HasSelectRole(AuthorizationRoles currentUserRoles, AyaType objectType)
{
var RoleSet = BizRoles.GetRoleSet(objectType);
if (RoleSet == null) return false;
//NOTE: this assumes that if you can change you can read
if (currentUserRoles.HasAnyFlags(BizRoles.GetRoleSet(objectType).Change))
if (currentUserRoles.HasAnyFlags(RoleSet.Change))
return true;
if (currentUserRoles.HasAnyFlags(BizRoles.GetRoleSet(objectType).ReadFullRecord))
if (currentUserRoles.HasAnyFlags(RoleSet.ReadFullRecord))
return true;
if (currentUserRoles.HasAnyFlags(BizRoles.GetRoleSet(objectType).Select))
if (currentUserRoles.HasAnyFlags(RoleSet.Select))
return true;
return false;
@@ -118,6 +122,7 @@ namespace AyaNova.Api.ControllerHelpers
{
//NOTE: this assumes that if you can change you can read
var RoleSet = BizRoles.GetRoleSet(objectType);
if (RoleSet == null) return false;
var AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change;
return currentUserRoles.HasAnyFlags(AllowedRoles);
}
@@ -144,7 +149,9 @@ namespace AyaNova.Api.ControllerHelpers
/// <returns></returns>
internal static bool HasCreateRole(AuthorizationRoles currentUserRoles, AyaType objectType)
{
if (currentUserRoles.HasAnyFlags(BizRoles.GetRoleSet(objectType).Change))
var RoleSet = BizRoles.GetRoleSet(objectType);
if (RoleSet == null) return false;
if (currentUserRoles.HasAnyFlags(RoleSet.Change))
return true;
return false;
}
@@ -172,7 +179,9 @@ namespace AyaNova.Api.ControllerHelpers
/// <returns></returns>
internal static bool HasModifyRole(AuthorizationRoles currentUserRoles, AyaType objectType)
{
if (currentUserRoles.HasAnyFlags(BizRoles.GetRoleSet(objectType).Change))
var RoleSet = BizRoles.GetRoleSet(objectType);
if (RoleSet == null) return false;
if (currentUserRoles.HasAnyFlags(RoleSet.Change))
return true;
return false;
}
@@ -204,7 +213,9 @@ namespace AyaNova.Api.ControllerHelpers
//For now just going to treat as a modify, but for maximum flexibility keeping this as a separate method in case we change our minds in future
internal static bool HasDeleteRole(AuthorizationRoles currentUserRoles, AyaType objectType)
{
if (currentUserRoles.HasAnyFlags(BizRoles.GetRoleSet(objectType).Change))
var RoleSet = BizRoles.GetRoleSet(objectType);
if (RoleSet == null) return false;
if (currentUserRoles.HasAnyFlags(RoleSet.Change))
return true;
return false;
}