|
|
@@ -126,39 +126,59 @@ namespace InABox.Core
|
|
|
_descriptors.Add(descriptor);
|
|
|
}
|
|
|
|
|
|
+ private static bool IsAllowedInternal(ISecurityDescriptor descriptor, Guid userGuid)
|
|
|
+ {
|
|
|
+ // If you're not logged in, you can't do jack!
|
|
|
+ if (userGuid == Guid.Empty)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ CheckTokens();
|
|
|
+
|
|
|
+ // First Check for a matching User Token (override)
|
|
|
+ var usertoken = _usertokens.FirstOrDefault(x => x.Descriptor.Equals(descriptor.Code));
|
|
|
+ if (usertoken != null)
|
|
|
+ return usertoken.Enabled;
|
|
|
+
|
|
|
+ // If not found, fall back to the Group Token
|
|
|
+ var grouptoken = _grouptokens.FirstOrDefault(x => x.Descriptor.Equals(descriptor.Code));
|
|
|
+ if (grouptoken != null)
|
|
|
+ return grouptoken.Enabled;
|
|
|
+
|
|
|
+ // Still not found? fall back to the Global Token
|
|
|
+ var globaltoken = _globaltokens.FirstOrDefault(x => x.Descriptor.Equals(descriptor.Code));
|
|
|
+ if (globaltoken != null)
|
|
|
+ return globaltoken.Enabled;
|
|
|
+
|
|
|
+ // Aaand finally, just return the default for the descriptor
|
|
|
+ return descriptor.Value;
|
|
|
+ }
|
|
|
+
|
|
|
public static bool IsAllowed(Type T, Guid userGuid, Guid securityId)
|
|
|
{
|
|
|
var descriptor = (Activator.CreateInstance(T) as ISecurityDescriptor)!;
|
|
|
try
|
|
|
{
|
|
|
- // If you're not logged in, you can't do jack!
|
|
|
- if (userGuid == Guid.Empty)
|
|
|
+ if(IsAllowedInternal(descriptor, userGuid))
|
|
|
+ {
|
|
|
+ if(descriptor is IDependentSecurityDescriptor dependent)
|
|
|
+ {
|
|
|
+ return dependent.DependsOn.All(x => IsAllowed(T, userGuid, securityId));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
return false;
|
|
|
-
|
|
|
- CheckTokens();
|
|
|
-
|
|
|
- // First Check for a matching User Token (override)
|
|
|
- var usertoken = _usertokens.FirstOrDefault(x => x.Descriptor.Equals(descriptor.Code));
|
|
|
- if (usertoken != null)
|
|
|
- return usertoken.Enabled;
|
|
|
-
|
|
|
- // If not found, fall back to the Group Token
|
|
|
- var grouptoken = _grouptokens.FirstOrDefault(x => x.Descriptor.Equals(descriptor.Code));
|
|
|
- if (grouptoken != null)
|
|
|
- return grouptoken.Enabled;
|
|
|
-
|
|
|
- // Still not found? fall back to the Global Token
|
|
|
- var globaltoken = _globaltokens.FirstOrDefault(x => x.Descriptor.Equals(descriptor.Code));
|
|
|
- if (globaltoken != null)
|
|
|
- return globaltoken.Enabled;
|
|
|
+ }
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
|
|
|
+ return false;
|
|
|
}
|
|
|
-
|
|
|
- // Aaand finally, just return the default for the descriptor
|
|
|
- return descriptor.Value;
|
|
|
}
|
|
|
|
|
|
public static bool IsAllowed<T>(Guid userGuid, Guid securityId) where T : ISecurityDescriptor, new()
|
|
|
@@ -172,96 +192,89 @@ namespace InABox.Core
|
|
|
|
|
|
public static bool CanView<TEntity>(Guid userGuid, Guid securityId) where TEntity : Entity, new()
|
|
|
{
|
|
|
- return ClientFactory.IsSupported<TEntity>()
|
|
|
- && IsAllowed<AutoSecurityDescriptor<TEntity, CanView<TEntity>>>(userGuid, securityId);
|
|
|
+ return IsAllowed<AutoSecurityDescriptor<TEntity, CanView<TEntity>>>(userGuid, securityId);
|
|
|
}
|
|
|
|
|
|
public static bool CanView(Type TEntity)
|
|
|
{
|
|
|
- return ClientFactory.IsSupported(TEntity) &&
|
|
|
- IsAllowed(typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanView<>).MakeGenericType(TEntity)));
|
|
|
+ return IsAllowed(typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanView<>).MakeGenericType(TEntity)));
|
|
|
}
|
|
|
public static bool CanView<TEntity>() where TEntity : Entity, new()
|
|
|
{
|
|
|
- return ClientFactory.IsSupported<TEntity>() && IsAllowed<AutoSecurityDescriptor<TEntity, CanView<TEntity>>>();
|
|
|
+ return IsAllowed<AutoSecurityDescriptor<TEntity, CanView<TEntity>>>();
|
|
|
}
|
|
|
|
|
|
public static bool CanEdit(Type TEntity, Guid userGuid, Guid securityId)
|
|
|
{
|
|
|
- return ClientFactory.IsSupported(TEntity) &&
|
|
|
- IsAllowed(typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanEdit<>).MakeGenericType(TEntity)), userGuid, securityId);
|
|
|
+ return IsAllowed(typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanEdit<>).MakeGenericType(TEntity)), userGuid, securityId);
|
|
|
}
|
|
|
public static bool CanEdit<TEntity>(Guid userGuid, Guid securityId) where TEntity : Entity, new()
|
|
|
{
|
|
|
- return ClientFactory.IsSupported<TEntity>() && IsAllowed<AutoSecurityDescriptor<TEntity, CanEdit<TEntity>>>(userGuid, securityId);
|
|
|
+ return IsAllowed<AutoSecurityDescriptor<TEntity, CanEdit<TEntity>>>(userGuid, securityId);
|
|
|
}
|
|
|
|
|
|
public static bool CanEdit(Type TEntity)
|
|
|
{
|
|
|
- return ClientFactory.IsSupported(TEntity) &&
|
|
|
- IsAllowed(typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanEdit<>).MakeGenericType(TEntity)));
|
|
|
+ return IsAllowed(typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanEdit<>).MakeGenericType(TEntity)));
|
|
|
}
|
|
|
public static bool CanEdit<TEntity>() where TEntity : Entity, new()
|
|
|
{
|
|
|
- return ClientFactory.IsSupported<TEntity>() && IsAllowed<AutoSecurityDescriptor<TEntity, CanEdit<TEntity>>>();
|
|
|
+ return IsAllowed<AutoSecurityDescriptor<TEntity, CanEdit<TEntity>>>();
|
|
|
}
|
|
|
|
|
|
public static bool CanImport<TEntity>() where TEntity : Entity, new()
|
|
|
{
|
|
|
- return ClientFactory.IsSupported<TEntity>() && IsAllowed<AutoSecurityDescriptor<TEntity, CanImport<TEntity>>>();
|
|
|
+ return IsAllowed<AutoSecurityDescriptor<TEntity, CanImport<TEntity>>>();
|
|
|
}
|
|
|
|
|
|
public static bool CanExport<TEntity>() where TEntity : Entity, new()
|
|
|
{
|
|
|
- return ClientFactory.IsSupported<TEntity>() && IsAllowed<AutoSecurityDescriptor<TEntity, CanExport<TEntity>>>();
|
|
|
+ return IsAllowed<AutoSecurityDescriptor<TEntity, CanExport<TEntity>>>();
|
|
|
}
|
|
|
|
|
|
public static bool CanMerge<TEntity>() where TEntity : Entity, new()
|
|
|
{
|
|
|
- return ClientFactory.IsSupported<TEntity>() && IsAllowed<AutoSecurityDescriptor<TEntity, CanMerge<TEntity>>>();
|
|
|
+ return IsAllowed<AutoSecurityDescriptor<TEntity, CanMerge<TEntity>>>();
|
|
|
}
|
|
|
|
|
|
public static bool CanPost<TEntity>() where TEntity : Entity, new()
|
|
|
{
|
|
|
- return ClientFactory.IsSupported<TEntity>() && IsAllowed<AutoSecurityDescriptor<TEntity, CanPost<TEntity>>>();
|
|
|
+ return IsAllowed<AutoSecurityDescriptor<TEntity, CanPost<TEntity>>>();
|
|
|
}
|
|
|
|
|
|
public static bool CanConfigurePost<TEntity>() where TEntity : Entity, new()
|
|
|
{
|
|
|
- return ClientFactory.IsSupported<TEntity>() && IsAllowed<AutoSecurityDescriptor<TEntity, CanConfigurePost<TEntity>>>();
|
|
|
+ return IsAllowed<AutoSecurityDescriptor<TEntity, CanConfigurePost<TEntity>>>();
|
|
|
}
|
|
|
|
|
|
public static bool CanDelete<TEntity>() where TEntity : Entity, new()
|
|
|
{
|
|
|
- return ClientFactory.IsSupported<TEntity>() && IsAllowed<AutoSecurityDescriptor<TEntity, CanDelete<TEntity>>>();
|
|
|
+ return IsAllowed<AutoSecurityDescriptor<TEntity, CanDelete<TEntity>>>();
|
|
|
}
|
|
|
|
|
|
public static bool CanDelete(Type TEntity)
|
|
|
{
|
|
|
- return ClientFactory.IsSupported(TEntity) &&
|
|
|
- IsAllowed(typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanDelete<>).MakeGenericType(TEntity)));
|
|
|
+ return IsAllowed(typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanDelete<>).MakeGenericType(TEntity)));
|
|
|
}
|
|
|
|
|
|
public static bool CanManageIssues(Type TEntity)
|
|
|
{
|
|
|
- return ClientFactory.IsSupported(TEntity)
|
|
|
- && IsAllowed(typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanManageIssues<>).MakeGenericType(TEntity)));
|
|
|
+ return IsAllowed(typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanManageIssues<>).MakeGenericType(TEntity)));
|
|
|
}
|
|
|
|
|
|
public static bool CanManageIssues<TEntity>() where TEntity : Entity, IIssues, new()
|
|
|
{
|
|
|
- return ClientFactory.IsSupported<TEntity>() && IsAllowed<AutoSecurityDescriptor<TEntity, CanManageIssues<TEntity>>>();
|
|
|
+ return IsAllowed<AutoSecurityDescriptor<TEntity, CanManageIssues<TEntity>>>();
|
|
|
}
|
|
|
|
|
|
public static bool CanManageProblems(Type TEntity)
|
|
|
{
|
|
|
- return ClientFactory.IsSupported(TEntity)
|
|
|
- && IsAllowed(typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanManageProblems<>).MakeGenericType(TEntity)));
|
|
|
+ return IsAllowed(typeof(AutoSecurityDescriptor<,>).MakeGenericType(TEntity, typeof(CanManageProblems<>).MakeGenericType(TEntity)));
|
|
|
}
|
|
|
|
|
|
public static bool CanManageProblems<TEntity>() where TEntity : Entity, IProblems, new()
|
|
|
{
|
|
|
- return ClientFactory.IsSupported<TEntity>() && IsAllowed<AutoSecurityDescriptor<TEntity, CanManageProblems<TEntity>>>();
|
|
|
+ return IsAllowed<AutoSecurityDescriptor<TEntity, CanManageProblems<TEntity>>>();
|
|
|
}
|
|
|
}
|
|
|
}
|