qol: simplify accessors

This commit is contained in:
Gary Sharp
2025-07-20 11:24:04 +10:00
parent 3aeb9374a9
commit b4e54c9edf
61 changed files with 132 additions and 132 deletions
@@ -34,7 +34,7 @@ namespace Disco.Services.Authorization
Current.Log((int)EventTypeId, Args);
}
protected override List<Logging.Models.LogEventType> LoadEventTypes()
protected override List<LogEventType> LoadEventTypes()
{
List<LogEventType> eventTypes = new List<LogEventType>() {
new LogEventType() {
@@ -68,17 +68,17 @@ namespace Disco.Services.Authorization
/// <summary>
/// Checks if token contains at least one of the claims requested.
/// </summary>
/// <param name="ClaimKeys">Claim Keys from <see cref="Disco.Services.Authorization.Claims"/></param>
/// <param name="ClaimKeys">Claim Keys from <see cref="Claims"/></param>
/// <returns>true if the token satisfies the claim request, otherwise false.</returns>
public bool HasAny(params string[] ClaimKeys)
{
return HasAny((IEnumerable<string>)ClaimKeys);
}
/// <summary>
/// Checks if token contains at least one of the claims requested.
/// </summary>
/// <param name="ClaimKeys">Claim Keys from <see cref="Disco.Services.Authorization.Claims"/></param>
/// <param name="ClaimKeys">Claim Keys from <see cref="Claims"/></param>
/// <returns>true if the token satisfies the claim request, otherwise false.</returns>
public bool HasAny(IEnumerable<string> ClaimKeys)
{
@@ -88,7 +88,7 @@ namespace Disco.Services.Authorization
/// <summary>
/// Checks if token contains all the claims requested.
/// </summary>
/// <param name="ClaimKeys">Claim Keys from <see cref="Disco.Services.Authorization.Claims"/></param>
/// <param name="ClaimKeys">Claim Keys from <see cref="Claims"/></param>
/// <returns>true if the token satisfies the claim request, otherwise false.</returns>
public bool HasAll(params string[] ClaimKeys)
{
@@ -97,7 +97,7 @@ namespace Disco.Services.Authorization
/// <summary>
/// Checks if token contains all the claims requested.
/// </summary>
/// <param name="ClaimKeys">Claim Keys from <see cref="Disco.Services.Authorization.Claims"/></param>
/// <param name="ClaimKeys">Claim Keys from <see cref="Claims"/></param>
/// <returns>true if the token satisfies the claim request, otherwise false.</returns>
public bool HasAll(IEnumerable<string> ClaimKeys)
{
@@ -107,7 +107,7 @@ namespace Disco.Services.Authorization
/// <summary>
/// Checks if token contains the claim requested.
/// </summary>
/// <param name="ClaimKey">Claim Key from <see cref="Disco.Services.Authorization.Claims"/></param>
/// <param name="ClaimKey">Claim Key from <see cref="Claims"/></param>
/// <returns>true if the token satisfies the claim request, otherwise false.</returns>
public bool Has(string ClaimKey)
{
@@ -127,9 +127,9 @@ namespace Disco.Services.Authorization
}
/// <summary>
/// Validates the token contains the claim required. An <see cref="Disco.Services.Authorization.AccessDeniedException"/> is thrown if the requirements are not met.
/// Validates the token contains the claim required. An <see cref="AccessDeniedException"/> is thrown if the requirements are not met.
/// </summary>
/// <param name="ClaimKey">Claim Key from <see cref="Disco.Services.Authorization.Claims"/></param>
/// <param name="ClaimKey">Claim Key from <see cref="Claims"/></param>
public void Require(string ClaimKey)
{
if (!Has(ClaimKey))
@@ -137,19 +137,19 @@ namespace Disco.Services.Authorization
}
/// <summary>
/// Validates the token contains all the claims required. An <see cref="Disco.Services.Authorization.AccessDeniedException"/> is thrown if the requirements are not met.
/// Validates the token contains all the claims required. An <see cref="AccessDeniedException"/> is thrown if the requirements are not met.
/// </summary>
/// <param name="ClaimKeys">Claim Keys from <see cref="Disco.Services.Authorization.Claims"/></param>
/// <param name="ClaimKeys">Claim Keys from <see cref="Claims"/></param>
public void RequireAll(params string[] ClaimKeys)
{
if (!HasAll(ClaimKeys))
throw new AccessDeniedException(BuildRequireAllMessage(ClaimKeys), GetRequireResource());
}
/// <summary>
/// Validates the token contains at least one of the claims required. An <see cref="Disco.Services.Authorization.AccessDeniedException"/> is thrown if the requirements are not met.
/// Validates the token contains at least one of the claims required. An <see cref="AccessDeniedException"/> is thrown if the requirements are not met.
/// </summary>
/// <param name="ClaimKeys">Claim Keys from <see cref="Disco.Services.Authorization.Claims"/></param>
/// <param name="ClaimKeys">Claim Keys from <see cref="Claims"/></param>
public void RequireAny(params string[] ClaimKeys)
{
if (!HasAny(ClaimKeys))
@@ -8,7 +8,7 @@ namespace Disco.Services.Authorization
{
public class ClaimNavigatorItem : IClaimNavigatorItem
{
private Func<Roles.RoleClaims, bool> accessor { get; set; }
private Func<RoleClaims, bool> accessor { get; set; }
public string Key { get; private set; }
public string Name { get; private set; }
@@ -51,7 +51,7 @@ namespace Disco.Services
public static string ImageFilePath(this DeviceModel deviceModel)
{
var configCache = new Disco.Data.Configuration.SystemConfiguration(null);
var configCache = new Data.Configuration.SystemConfiguration(null);
var deviceModelImagesDataStore = DataStore.CreateLocation(configCache, "DeviceModelImages");
@@ -68,7 +68,7 @@ namespace Disco.Services.Devices.Enrolment
public EnrolmentLog()
{
}
private static void Log(EnrolmentLog.EventTypeIds EventTypeId, params object[] Args)
private static void Log(EventTypeIds EventTypeId, params object[] Args)
{
EnrolmentLog.Current.Log((int)EventTypeId, Args);
}
@@ -143,7 +143,7 @@ namespace Disco.Services.Devices.Enrolment
EnrolmentLog.LogSessionFinished(sessionId);
MacSecureEnrol = response;
}
catch (System.Exception ex)
catch (Exception ex)
{
EnrolmentLog.LogSessionError(sessionId, ex);
throw ex;
+1 -1
View File
@@ -60,7 +60,7 @@ namespace Disco.Services.Documents
return "Documents";
}
}
private static void Log(DocumentsLog.EventTypeIds EventTypeId, params object[] Args)
private static void Log(EventTypeIds EventTypeId, params object[] Args)
{
DocumentsLog.Current.Log((int)EventTypeId, Args);
}
@@ -17,7 +17,7 @@ namespace Disco.Services.Expressions.Extensions
}
public static FileImageExpressionResult ImageFromDataStoreFile(string RelativeFilePath)
{
var configCache = new Disco.Data.Configuration.SystemConfiguration(null);
var configCache = new Data.Configuration.SystemConfiguration(null);
string DataStoreLocation = configCache.DataStoreLocation;
string AbsoluteFilePath = System.IO.Path.Combine(DataStoreLocation, RelativeFilePath);
return new FileImageExpressionResult(AbsoluteFilePath);
+4 -4
View File
@@ -21,14 +21,14 @@ namespace Disco.Services.Extensions
public static ReadOnlyCollection<KeyValuePair<string, string>> NoticeboardThemes { get; private set; }
/// <summary>
/// Returns a randomly selected Icon using <see cref="System.Random"/>.
/// Returns a randomly selected Icon using <see cref="Random"/>.
/// </summary>
public static string RandomIcon()
{
return RandomIcon(null);
}
/// <summary>
/// Returns a randomly selected Icon using <see cref="System.Random"/>.
/// Returns a randomly selected Icon using <see cref="Random"/>.
/// </summary>
/// <param name="Except">A list of Icons which will be ignored (if all are excluded, a random one will be returned)</param>
public static string RandomIcon(IEnumerable<string> Except)
@@ -44,14 +44,14 @@ namespace Disco.Services.Extensions
}
/// <summary>
/// Returns a randomly selected Theme Colour using <see cref="System.Random"/>.
/// Returns a randomly selected Theme Colour using <see cref="Random"/>.
/// </summary>
public static string RandomThemeColour()
{
return RandomThemeColour(null);
}
/// <summary>
/// Returns a randomly selected Theme Colour using <see cref="System.Random"/>.
/// Returns a randomly selected Theme Colour using <see cref="Random"/>.
/// </summary>
/// <param name="Except">A list of Theme Colours which will be ignored (if all are excluded, a random one will be returned)</param>
public static string RandomThemeColour(IEnumerable<string> Except)
@@ -104,12 +104,12 @@ namespace Disco.Services.Interop.ActiveDirectory
var domain = Context.GetDomainFromId(Id);
return domain.GetAvailableDomainController().RetrieveADMachineAccount(Id, AdditionalProperties);
}
public static ADMachineAccount RetrieveADMachineAccount(string Id, System.Guid? NetbootGUID, params string[] AdditionalProperties)
public static ADMachineAccount RetrieveADMachineAccount(string Id, Guid? NetbootGUID, params string[] AdditionalProperties)
{
var domain = Context.GetDomainFromId(Id);
return domain.GetAvailableDomainController().RetrieveADMachineAccount(Id, NetbootGUID, AdditionalProperties);
}
public static ADMachineAccount RetrieveADMachineAccount(string Id, System.Guid? UUIDNetbootGUID, System.Guid? MacAddressNetbootGUID, params string[] AdditionalProperties)
public static ADMachineAccount RetrieveADMachineAccount(string Id, Guid? UUIDNetbootGUID, Guid? MacAddressNetbootGUID, params string[] AdditionalProperties)
{
var domain = Context.GetDomainFromId(Id);
return domain.GetAvailableDomainController().RetrieveADMachineAccount(Id, UUIDNetbootGUID, MacAddressNetbootGUID, AdditionalProperties);
@@ -19,7 +19,7 @@ namespace Disco.Services.Logging.Models
public string FormattedTimestamp { get; set; }
public bool UseDisplay { get; set; }
public static LogLiveEvent Create(LogBase logModule, Models.LogEventType eventType, DateTime Timestamp, string jsonArguments)
public static LogLiveEvent Create(LogBase logModule, LogEventType eventType, DateTime Timestamp, string jsonArguments)
{
object[] Arguments = null;
if (jsonArguments != null)
@@ -29,9 +29,9 @@ namespace Disco.Services.Logging.Models
return Create(logModule, eventType, Timestamp, Arguments);
}
public static LogLiveEvent Create(LogBase logModule, Models.LogEventType eventType, DateTime Timestamp, params object[] Arguments)
public static LogLiveEvent Create(LogBase logModule, LogEventType eventType, DateTime Timestamp, params object[] Arguments)
{
return new Models.LogLiveEvent()
return new LogLiveEvent()
{
ModuleId = logModule.ModuleId,
ModuleName = logModule.ModuleName,
@@ -8,7 +8,7 @@ namespace Disco.Services.Logging.Persistance
static LogPersistContext()
{
Database.SetInitializer<LogPersistContext>(new LogPersistContextInitializer());
Database.SetInitializer(new LogPersistContextInitializer());
}
public DbSet<Models.LogModule> Modules { get; set; }
+2 -2
View File
@@ -28,9 +28,9 @@ namespace Disco.Services.Logging
return true;
}
public List<Models.LogLiveEvent> Query(DiscoDataContext Database)
public List<LogLiveEvent> Query(DiscoDataContext Database)
{
List<Models.LogLiveEvent> results = new List<LogLiveEvent>();
List<LogLiveEvent> results = new List<LogLiveEvent>();
// Validate Options
Validate();
@@ -67,7 +67,7 @@ namespace Disco.Services.Plugins.Features.CertificateProvider
public CertificateProvidersLog()
{
}
private static void Log(CertificateProvidersLog.EventTypeIds EventTypeId, params object[] Args)
private static void Log(EventTypeIds EventTypeId, params object[] Args)
{
CertificateProvidersLog.Current.Log((int)EventTypeId, Args);
}
@@ -12,7 +12,7 @@ namespace Disco.Services.Plugins.Features.RepairProvider
public abstract class RepairProviderFeature : PluginFeature
{
/// <summary>
/// The repairer identifier. Used to link this provider to any <see cref="Disco.Models.Repository.RepairerName"/>. This identifier is used to automatically set the RepairerName when a job is submitted using this plugin.
/// The repairer identifier. Used to link this provider to any <see cref="Models.Repository.RepairerName"/>. This identifier is used to automatically set the RepairerName when a job is submitted using this plugin.
/// </summary>
public abstract string ProviderId { get; }
@@ -45,7 +45,7 @@ namespace Disco.Services.Plugins.Features.RepairProvider
/// <summary>
/// Called when the plugin should submit the job to the external party.
/// </summary>
/// <returns>A reference number/identifier from the external party which is stored in <see cref="Disco.Models.Repository.RepairerReference"/></returns>
/// <returns>A reference number/identifier from the external party which is stored in <see cref="Models.Repository.RepairerReference"/></returns>
public abstract string SubmitJob(DiscoDataContext Database, Job Job, OrganisationAddress Address, User TechUser, string RepairDescription, Dictionary<string, string> ProviderProperties);
#endregion
@@ -19,7 +19,7 @@ namespace Disco.Services.Plugins.Features.UIExtension.Results
model = Model;
}
public override void ExecuteResult<T>(System.Web.Mvc.WebViewPage<T> page)
public override void ExecuteResult<T>(WebViewPage<T> page)
{
WebViewPage partialView = Activator.CreateInstance(viewType) as WebViewPage;
if (partialView == null)
+4 -4
View File
@@ -16,15 +16,15 @@ namespace Disco.Services.Plugins
#region Model Binding from Controller
public static bool TryUpdateModel<TModel>(this Controller controller, TModel model) where TModel : class
{
return controller.TryUpdateModel<TModel>(model, null, controller.ValueProvider);
return controller.TryUpdateModel(model, null, controller.ValueProvider);
}
public static bool TryUpdateModel<TModel>(this Controller controller, TModel model, IValueProvider valueProvider) where TModel : class
{
return controller.TryUpdateModel<TModel>(model, null, valueProvider);
return controller.TryUpdateModel(model, null, valueProvider);
}
public static bool TryUpdateModel<TModel>(this Controller controller, TModel model, string prefix) where TModel : class
{
return controller.TryUpdateModel<TModel>(model, prefix, controller.ValueProvider);
return controller.TryUpdateModel(model, prefix, controller.ValueProvider);
}
public static bool TryUpdateModel<TModel>(this Controller controller, TModel model, string prefix, IValueProvider valueProvider) where TModel : class
{
@@ -250,7 +250,7 @@ namespace Disco.Services.Plugins
private static MvcForm FormHelper<T>(this WebViewPage<T> ViewPage, string formAction, FormMethod method, IDictionary<string, object> htmlAttributes)
{
TagBuilder builder = new TagBuilder("form");
builder.MergeAttributes<string, object>(htmlAttributes);
builder.MergeAttributes(htmlAttributes);
builder.MergeAttribute("action", formAction);
builder.MergeAttribute("method", HtmlHelper.GetFormMethodString(method), true);
bool flag = ViewPage.ViewContext.ClientValidationEnabled && !ViewPage.ViewContext.UnobtrusiveJavaScriptEnabled;
+1 -1
View File
@@ -2,7 +2,7 @@
namespace Disco.Services.Plugins
{
public abstract class PluginWebViewPage<T> : Disco.Services.Web.WebViewPage<T>
public abstract class PluginWebViewPage<T> : Web.WebViewPage<T>
{
private Lazy<WebPageHelper<T>> _plugin;
+3 -3
View File
@@ -176,10 +176,10 @@ namespace Disco.Services.Plugins
Log(WarningOrMessage, LogData);
}
protected override List<Logging.Models.LogEventType> LoadEventTypes()
protected override List<LogEventType> LoadEventTypes()
{
return new System.Collections.Generic.List<LogEventType>
{
return new List<LogEventType>
{
new LogEventType
{
Id = (int)EventTypeIds.InitializingPlugins,
+1 -1
View File
@@ -77,7 +77,7 @@ namespace Disco.Services.Plugins
public HtmlString PartialCompiled<ViewType>(object Model) where ViewType : WebViewPage
{
using (System.IO.StringWriter writer = new StringWriter(CultureInfo.CurrentCulture))
using (StringWriter writer = new StringWriter(CultureInfo.CurrentCulture))
{
RenderPartialCompiled<ViewType>(writer, Model);
+1 -1
View File
@@ -80,7 +80,7 @@ namespace Disco.Services.Tasks
#endregion
#region Events
public delegate void UpdatedEvent(ScheduledTaskStatus sender, KeyValuePair<string, object>[] ChangedProperties);
public delegate void UpdatedEvent(ScheduledTaskStatus sender, ChangedItem[] ChangedProperties);
public delegate void CancelingEvent(ScheduledTaskStatus sender);
public event UpdatedEvent Updated;
public event CancelingEvent Canceling;
+3 -3
View File
@@ -124,10 +124,10 @@ namespace Disco.Services.Tasks
Log(EventTypeIds.ScheduledTasksWarning, ScheduledTaskName, SessionId, Message);
}
protected override List<Logging.Models.LogEventType> LoadEventTypes()
protected override List<LogEventType> LoadEventTypes()
{
return new System.Collections.Generic.List<LogEventType>
{
return new List<LogEventType>
{
new LogEventType
{
Id = (int)EventTypeIds.InitializingScheduledTasks,