Feature #26: User Flags
Flags can be associated with Users. Includes minor updates to Job Queues and improved visibility of user information.
This commit is contained in:
@@ -73,6 +73,10 @@ namespace Disco.Services.Authorization
|
||||
{ "Config.JobQueue.Create", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Config.JobQueue.Create, (c, v) => c.Config.JobQueue.Create = v, "Create Job Queues", "Can create job queues", false) },
|
||||
{ "Config.JobQueue.Delete", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Config.JobQueue.Delete, (c, v) => c.Config.JobQueue.Delete = v, "Delete Job Queues", "Can delete job queues", false) },
|
||||
{ "Config.JobQueue.Show", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Config.JobQueue.Show, (c, v) => c.Config.JobQueue.Show = v, "Show Job Queues", "Can show job queues", false) },
|
||||
{ "Config.UserFlag.Configure", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Config.UserFlag.Configure, (c, v) => c.Config.UserFlag.Configure = v, "Configure User Flags", "Can configure user flags", false) },
|
||||
{ "Config.UserFlag.Create", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Config.UserFlag.Create, (c, v) => c.Config.UserFlag.Create = v, "Create User Flags", "Can create user flags", false) },
|
||||
{ "Config.UserFlag.Delete", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Config.UserFlag.Delete, (c, v) => c.Config.UserFlag.Delete = v, "Delete User Flags", "Can delete user flags", false) },
|
||||
{ "Config.UserFlag.Show", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Config.UserFlag.Show, (c, v) => c.Config.UserFlag.Show = v, "Show User Flags", "Can show user flags", false) },
|
||||
{ "Config.Show", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Config.Show, (c, v) => c.Config.Show = v, "Show Configuration", "Can show the configuration menu", false) },
|
||||
{ "Job.Lists.AllOpen", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Lists.AllOpen, (c, v) => c.Job.Lists.AllOpen = v, "All Open List", "Can show list", false) },
|
||||
{ "Job.Lists.AwaitingFinanceAgreementBreach", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Lists.AwaitingFinanceAgreementBreach, (c, v) => c.Job.Lists.AwaitingFinanceAgreementBreach = v, "Awaiting Finance Agreement Breach List", "Can show list (NOTE: Requires Awaiting Finance List)", false) },
|
||||
@@ -198,9 +202,12 @@ namespace Disco.Services.Authorization
|
||||
{ "Device.Show", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Device.Show, (c, v) => c.Device.Show = v, "Show Devices", "Can show devices", false) },
|
||||
{ "Device.ShowJobs", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Device.ShowJobs, (c, v) => c.Device.ShowJobs = v, "Show Devices Jobs", "Can show jobs associated with devices", false) },
|
||||
{ "User.Actions.AddAttachments", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.User.Actions.AddAttachments, (c, v) => c.User.Actions.AddAttachments = v, "Add Attachments", "Can add attachments to users", false) },
|
||||
{ "User.Actions.AddFlags", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.User.Actions.AddFlags, (c, v) => c.User.Actions.AddFlags = v, "Add User Flags", "Can add user flags", false) },
|
||||
{ "User.Actions.EditFlags", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.User.Actions.EditFlags, (c, v) => c.User.Actions.EditFlags = v, "Edit User Flags", "Can edit user flags", false) },
|
||||
{ "User.Actions.GenerateDocuments", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.User.Actions.GenerateDocuments, (c, v) => c.User.Actions.GenerateDocuments = v, "Generate Documents", "Can generate documents for users", false) },
|
||||
{ "User.Actions.RemoveAnyAttachments", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.User.Actions.RemoveAnyAttachments, (c, v) => c.User.Actions.RemoveAnyAttachments = v, "Remove Any Attachments", "Can remove any attachments from users", false) },
|
||||
{ "User.Actions.RemoveOwnAttachments", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.User.Actions.RemoveOwnAttachments, (c, v) => c.User.Actions.RemoveOwnAttachments = v, "Remove Own Attachments", "Can remove own attachments from users", false) },
|
||||
{ "User.Actions.RemoveFlags", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.User.Actions.RemoveFlags, (c, v) => c.User.Actions.RemoveFlags = v, "Remove User Flags", "Can remove user flags", false) },
|
||||
{ "User.Search", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.User.Search, (c, v) => c.User.Search = v, "Search Users", "Can search users", false) },
|
||||
{ "User.ShowAttachments", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.User.ShowAttachments, (c, v) => c.User.ShowAttachments = v, "Show Attachments", "Can show user attachments", false) },
|
||||
{ "User.ShowAssignmentHistory", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.User.ShowAssignmentHistory, (c, v) => c.User.ShowAssignmentHistory = v, "Show Device Assignment History", "Can show the device assignment history for users", false) },
|
||||
@@ -208,6 +215,7 @@ namespace Disco.Services.Authorization
|
||||
{ "User.Show", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.User.Show, (c, v) => c.User.Show = v, "Show Users", "Can show users", false) },
|
||||
{ "User.ShowAuthorization", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.User.ShowAuthorization, (c, v) => c.User.ShowAuthorization = v, "Show Users Authorization", "Can show authorization permissions associated with users", false) },
|
||||
{ "User.ShowDetails", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.User.ShowDetails, (c, v) => c.User.ShowDetails = v, "Show Users Details", "Can show users contact and personal details", false) },
|
||||
{ "User.ShowFlagAssignments", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.User.ShowFlagAssignments, (c, v) => c.User.ShowFlagAssignments = v, "Show Users Flag Assignments", "Can show flags associated with users", false) },
|
||||
{ "User.ShowJobs", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.User.ShowJobs, (c, v) => c.User.ShowJobs = v, "Show Users Jobs", "Can show jobs associated with users", false) },
|
||||
{ "ComputerAccount", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.ComputerAccount, (c, v) => c.ComputerAccount = v, "Computer Account", "Represents a computer account", true) },
|
||||
{ "DiscoAdminAccount", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.DiscoAdminAccount, (c, v) => c.DiscoAdminAccount = v, "Disco Administrator Account", "Represents a Disco Administrator account", true) }
|
||||
@@ -291,6 +299,12 @@ namespace Disco.Services.Authorization
|
||||
new ClaimNavigatorItem("Config.System.ConfigureProxy", false),
|
||||
new ClaimNavigatorItem("Config.System.Show", false)
|
||||
}),
|
||||
new ClaimNavigatorItem("Config.UserFlag", "User Flags", "Permissions related to User Flags", false, new List<IClaimNavigatorItem>() {
|
||||
new ClaimNavigatorItem("Config.UserFlag.Configure", false),
|
||||
new ClaimNavigatorItem("Config.UserFlag.Create", false),
|
||||
new ClaimNavigatorItem("Config.UserFlag.Delete", false),
|
||||
new ClaimNavigatorItem("Config.UserFlag.Show", false)
|
||||
}),
|
||||
new ClaimNavigatorItem("Config.Show", false)
|
||||
}),
|
||||
new ClaimNavigatorItem("Job", "Job", "Permissions related to Jobs", false, new List<IClaimNavigatorItem>() {
|
||||
@@ -441,9 +455,12 @@ namespace Disco.Services.Authorization
|
||||
new ClaimNavigatorItem("User", "User", "Permissions related to Users", false, new List<IClaimNavigatorItem>() {
|
||||
new ClaimNavigatorItem("User.Actions", "Actions", "Permissions related to User Actions", false, new List<IClaimNavigatorItem>() {
|
||||
new ClaimNavigatorItem("User.Actions.AddAttachments", false),
|
||||
new ClaimNavigatorItem("User.Actions.AddFlags", false),
|
||||
new ClaimNavigatorItem("User.Actions.EditFlags", false),
|
||||
new ClaimNavigatorItem("User.Actions.GenerateDocuments", false),
|
||||
new ClaimNavigatorItem("User.Actions.RemoveAnyAttachments", false),
|
||||
new ClaimNavigatorItem("User.Actions.RemoveOwnAttachments", false)
|
||||
new ClaimNavigatorItem("User.Actions.RemoveOwnAttachments", false),
|
||||
new ClaimNavigatorItem("User.Actions.RemoveFlags", false)
|
||||
}),
|
||||
new ClaimNavigatorItem("User.Search", false),
|
||||
new ClaimNavigatorItem("User.ShowAttachments", false),
|
||||
@@ -452,6 +469,7 @@ namespace Disco.Services.Authorization
|
||||
new ClaimNavigatorItem("User.Show", false),
|
||||
new ClaimNavigatorItem("User.ShowAuthorization", false),
|
||||
new ClaimNavigatorItem("User.ShowDetails", false),
|
||||
new ClaimNavigatorItem("User.ShowFlagAssignments", false),
|
||||
new ClaimNavigatorItem("User.ShowJobs", false)
|
||||
}),
|
||||
new ClaimNavigatorItem("ComputerAccount", true),
|
||||
@@ -567,6 +585,10 @@ namespace Disco.Services.Authorization
|
||||
c.Config.JobQueue.Create = true;
|
||||
c.Config.JobQueue.Delete = true;
|
||||
c.Config.JobQueue.Show = true;
|
||||
c.Config.UserFlag.Configure = true;
|
||||
c.Config.UserFlag.Create = true;
|
||||
c.Config.UserFlag.Delete = true;
|
||||
c.Config.UserFlag.Show = true;
|
||||
c.Config.Show = true;
|
||||
c.Job.Lists.AllOpen = true;
|
||||
c.Job.Lists.AwaitingFinanceAgreementBreach = true;
|
||||
@@ -692,9 +714,12 @@ namespace Disco.Services.Authorization
|
||||
c.Device.Show = true;
|
||||
c.Device.ShowJobs = true;
|
||||
c.User.Actions.AddAttachments = true;
|
||||
c.User.Actions.AddFlags = true;
|
||||
c.User.Actions.EditFlags = true;
|
||||
c.User.Actions.GenerateDocuments = true;
|
||||
c.User.Actions.RemoveAnyAttachments = true;
|
||||
c.User.Actions.RemoveOwnAttachments = true;
|
||||
c.User.Actions.RemoveFlags = true;
|
||||
c.User.Search = true;
|
||||
c.User.ShowAttachments = true;
|
||||
c.User.ShowAssignmentHistory = true;
|
||||
@@ -702,6 +727,7 @@ namespace Disco.Services.Authorization
|
||||
c.User.Show = true;
|
||||
c.User.ShowAuthorization = true;
|
||||
c.User.ShowDetails = true;
|
||||
c.User.ShowFlagAssignments = true;
|
||||
c.User.ShowJobs = true;
|
||||
c.DiscoAdminAccount = true;
|
||||
#endregion
|
||||
@@ -1051,6 +1077,33 @@ namespace Disco.Services.Authorization
|
||||
public const string Show = "Config.JobQueue.Show";
|
||||
}
|
||||
|
||||
/// <summary>User Flags
|
||||
/// <para>Permissions related to User Flags</para>
|
||||
/// </summary>
|
||||
public static class UserFlag
|
||||
{
|
||||
|
||||
/// <summary>Configure User Flags
|
||||
/// <para>Can configure user flags</para>
|
||||
/// </summary>
|
||||
public const string Configure = "Config.UserFlag.Configure";
|
||||
|
||||
/// <summary>Create User Flags
|
||||
/// <para>Can create user flags</para>
|
||||
/// </summary>
|
||||
public const string Create = "Config.UserFlag.Create";
|
||||
|
||||
/// <summary>Delete User Flags
|
||||
/// <para>Can delete user flags</para>
|
||||
/// </summary>
|
||||
public const string Delete = "Config.UserFlag.Delete";
|
||||
|
||||
/// <summary>Show User Flags
|
||||
/// <para>Can show user flags</para>
|
||||
/// </summary>
|
||||
public const string Show = "Config.UserFlag.Show";
|
||||
}
|
||||
|
||||
/// <summary>Show Configuration
|
||||
/// <para>Can show the configuration menu</para>
|
||||
/// </summary>
|
||||
@@ -1766,6 +1819,16 @@ namespace Disco.Services.Authorization
|
||||
/// </summary>
|
||||
public const string AddAttachments = "User.Actions.AddAttachments";
|
||||
|
||||
/// <summary>Add User Flags
|
||||
/// <para>Can add user flags</para>
|
||||
/// </summary>
|
||||
public const string AddFlags = "User.Actions.AddFlags";
|
||||
|
||||
/// <summary>Edit User Flags
|
||||
/// <para>Can edit user flags</para>
|
||||
/// </summary>
|
||||
public const string EditFlags = "User.Actions.EditFlags";
|
||||
|
||||
/// <summary>Generate Documents
|
||||
/// <para>Can generate documents for users</para>
|
||||
/// </summary>
|
||||
@@ -1780,6 +1843,11 @@ namespace Disco.Services.Authorization
|
||||
/// <para>Can remove own attachments from users</para>
|
||||
/// </summary>
|
||||
public const string RemoveOwnAttachments = "User.Actions.RemoveOwnAttachments";
|
||||
|
||||
/// <summary>Remove User Flags
|
||||
/// <para>Can remove user flags</para>
|
||||
/// </summary>
|
||||
public const string RemoveFlags = "User.Actions.RemoveFlags";
|
||||
}
|
||||
|
||||
/// <summary>Search Users
|
||||
@@ -1817,6 +1885,11 @@ namespace Disco.Services.Authorization
|
||||
/// </summary>
|
||||
public const string ShowDetails = "User.ShowDetails";
|
||||
|
||||
/// <summary>Show Users Flag Assignments
|
||||
/// <para>Can show flags associated with users</para>
|
||||
/// </summary>
|
||||
public const string ShowFlagAssignments = "User.ShowFlagAssignments";
|
||||
|
||||
/// <summary>Show Users Jobs
|
||||
/// <para>Can show jobs associated with users</para>
|
||||
/// </summary>
|
||||
|
||||
@@ -10,6 +10,7 @@ using Disco.Services.Authorization.Roles.ClaimGroups.Configuration.Logging;
|
||||
using Disco.Services.Authorization.Roles.ClaimGroups.Configuration.Origanisation;
|
||||
using Disco.Services.Authorization.Roles.ClaimGroups.Configuration.Plugin;
|
||||
using Disco.Services.Authorization.Roles.ClaimGroups.Configuration.System;
|
||||
using Disco.Services.Authorization.Roles.ClaimGroups.Configuration.UserFlag;
|
||||
|
||||
namespace Disco.Services.Authorization.Roles.ClaimGroups.Configuration
|
||||
{
|
||||
@@ -30,6 +31,7 @@ namespace Disco.Services.Authorization.Roles.ClaimGroups.Configuration
|
||||
this.Organisation = new OrganisationClaims();
|
||||
this.JobPreferences = new JobPreferencesClaims();
|
||||
this.JobQueue = new JobQueueClaims();
|
||||
this.UserFlag = new UserFlagClaims();
|
||||
}
|
||||
|
||||
[ClaimDetails("Show Configuration", "Can show the configuration menu")]
|
||||
@@ -58,5 +60,7 @@ namespace Disco.Services.Authorization.Roles.ClaimGroups.Configuration
|
||||
public JobPreferencesClaims JobPreferences { get; set; }
|
||||
|
||||
public JobQueueClaims JobQueue { get; set; }
|
||||
|
||||
public UserFlagClaims UserFlag { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
namespace Disco.Services.Authorization.Roles.ClaimGroups.Configuration.UserFlag
|
||||
{
|
||||
[ClaimDetails("User Flags", "Permissions related to User Flags")]
|
||||
public class UserFlagClaims : BaseRoleClaimGroup
|
||||
{
|
||||
[ClaimDetails("Configure User Flags", "Can configure user flags")]
|
||||
public bool Configure { get; set; }
|
||||
|
||||
[ClaimDetails("Create User Flags", "Can create user flags")]
|
||||
public bool Create { get; set; }
|
||||
|
||||
[ClaimDetails("Delete User Flags", "Can delete user flags")]
|
||||
public bool Delete { get; set; }
|
||||
|
||||
[ClaimDetails("Show User Flags", "Can show user flags")]
|
||||
public bool Show { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Disco.Services.Authorization.Roles.ClaimGroups.User
|
||||
namespace Disco.Services.Authorization.Roles.ClaimGroups.User
|
||||
{
|
||||
[ClaimDetails("Actions", "Permissions related to User Actions")]
|
||||
public class UserActionsClaims : BaseRoleClaimGroup
|
||||
@@ -18,5 +12,12 @@ namespace Disco.Services.Authorization.Roles.ClaimGroups.User
|
||||
|
||||
[ClaimDetails("Generate Documents", "Can generate documents for users")]
|
||||
public bool GenerateDocuments { get; set; }
|
||||
|
||||
[ClaimDetails("Add User Flags", "Can add user flags")]
|
||||
public bool AddFlags { get; set; }
|
||||
[ClaimDetails("Remove User Flags", "Can remove user flags")]
|
||||
public bool RemoveFlags { get; set; }
|
||||
[ClaimDetails("Edit User Flags", "Can edit user flags")]
|
||||
public bool EditFlags { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,9 @@ namespace Disco.Services.Authorization.Roles.ClaimGroups.User
|
||||
[ClaimDetails("Show Users Jobs", "Can show jobs associated with users")]
|
||||
public bool ShowJobs { get; set; }
|
||||
|
||||
[ClaimDetails("Show Users Flag Assignments", "Can show flags associated with users")]
|
||||
public bool ShowFlagAssignments { get; set; }
|
||||
|
||||
[ClaimDetails("Show Users Authorization", "Can show authorization permissions associated with users")]
|
||||
public bool ShowAuthorization { get; set; }
|
||||
|
||||
|
||||
@@ -154,6 +154,7 @@
|
||||
<Compile Include="Authorization\Roles\ClaimGroups\Configuration\Origanisation\OrganisationClaims.cs" />
|
||||
<Compile Include="Authorization\Roles\ClaimGroups\Configuration\Plugin\PluginClaims.cs" />
|
||||
<Compile Include="Authorization\Roles\ClaimGroups\Configuration\System\SystemClaims.cs" />
|
||||
<Compile Include="Authorization\Roles\ClaimGroups\Configuration\UserFlag\UserFlagClaims.cs" />
|
||||
<Compile Include="Authorization\Roles\ClaimGroups\Device\DeviceActionsClaims.cs" />
|
||||
<Compile Include="Authorization\Roles\ClaimGroups\Device\DeviceClaims.cs" />
|
||||
<Compile Include="Authorization\Roles\ClaimGroups\Device\DevicePropertiesClaims.cs" />
|
||||
@@ -206,6 +207,7 @@
|
||||
<Compile Include="Extensions\DateTimeExtensions.cs" />
|
||||
<Compile Include="Extensions\RxExtensions.cs" />
|
||||
<Compile Include="Extensions\StringExtensions.cs" />
|
||||
<Compile Include="Extensions\UIHelpers.cs" />
|
||||
<Compile Include="Interop\ActiveDirectory\ActiveDirectory.cs" />
|
||||
<Compile Include="Interop\ActiveDirectory\ActiveDirectoryContext.cs" />
|
||||
<Compile Include="Interop\ActiveDirectory\ActiveDirectoryExtensions.cs" />
|
||||
@@ -297,6 +299,9 @@
|
||||
<Compile Include="Users\Cache.cs" />
|
||||
<Compile Include="Users\CacheCleanTask.cs" />
|
||||
<Compile Include="Users\UserExtensions.cs" />
|
||||
<Compile Include="Users\UserFlags\Cache.cs" />
|
||||
<Compile Include="Users\UserFlags\UserFlagsDeleteTask.cs" />
|
||||
<Compile Include="Users\UserFlags\UserFlagService.cs" />
|
||||
<Compile Include="Users\UserService.cs" />
|
||||
<Compile Include="Users\UserUpdatesHub.cs" />
|
||||
<Compile Include="Web\AuthorizedController.cs" />
|
||||
@@ -343,7 +348,7 @@
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.DeltaBaseYear.MonthAndDayStamp.TimeStamp" BuildVersion_StartDate="2011/7/1" BuildVersion_BuildAction="Both" BuildVersion_DetectChanges="False" BuildVersion_UseGlobalSettings="False" />
|
||||
<UserProperties BuildVersion_UseGlobalSettings="False" BuildVersion_DetectChanges="False" BuildVersion_BuildAction="Both" BuildVersion_StartDate="2011/7/1" BuildVersion_BuildVersioningStyle="None.DeltaBaseYear.MonthAndDayStamp.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<PropertyGroup>
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Disco.Services.Extensions
|
||||
{
|
||||
public static class UIHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// FontAwesome Category Icons
|
||||
/// </summary>
|
||||
public static ReadOnlyCollection<KeyValuePair<string, string>> Icons { get; private set; }
|
||||
/// <summary>
|
||||
/// User-selectable Colour Themes
|
||||
/// </summary>
|
||||
public static ReadOnlyCollection<KeyValuePair<string, string>> ThemeColours { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns a randomly selected Icon using <see cref="System.Random"/>.
|
||||
/// </summary>
|
||||
public static string RandomIcon()
|
||||
{
|
||||
return RandomIcon(null);
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a randomly selected Icon using <see cref="System.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)
|
||||
{
|
||||
var rnd = new Random();
|
||||
if (Except != null)
|
||||
{
|
||||
var availableIcons = UIHelpers.Icons.Select(i => i.Key).Except(Except).ToList();
|
||||
if (availableIcons.Count > 0)
|
||||
return availableIcons[rnd.Next(availableIcons.Count - 1)];
|
||||
}
|
||||
return UIHelpers.Icons[rnd.Next(UIHelpers.Icons.Count - 1)].Key;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a randomly selected Theme Colour using <see cref="System.Random"/>.
|
||||
/// </summary>
|
||||
public static string RandomThemeColour()
|
||||
{
|
||||
return RandomThemeColour(null);
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a randomly selected Theme Colour using <see cref="System.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)
|
||||
{
|
||||
var rnd = new Random();
|
||||
if (Except != null)
|
||||
{
|
||||
var availableColours = UIHelpers.ThemeColours.Select(i => i.Key).Except(Except).ToList();
|
||||
if (availableColours.Count > 0)
|
||||
return availableColours[rnd.Next(availableColours.Count - 1)];
|
||||
}
|
||||
return UIHelpers.ThemeColours[rnd.Next(UIHelpers.ThemeColours.Count - 1)].Key;
|
||||
}
|
||||
|
||||
static UIHelpers()
|
||||
{
|
||||
// Icons
|
||||
Icons = new List<KeyValuePair<string, string>>(){
|
||||
new KeyValuePair<string, string>("ambulance" , "Ambulance"),
|
||||
new KeyValuePair<string, string>("anchor" , "Anchor"),
|
||||
new KeyValuePair<string, string>("android" , "Android"),
|
||||
new KeyValuePair<string, string>("apple" , "Apple"),
|
||||
new KeyValuePair<string, string>("archive" , "Archive"),
|
||||
new KeyValuePair<string, string>("arrow-circle-down" , "Arrow Circle Down"),
|
||||
new KeyValuePair<string, string>("arrow-circle-left" , "Arrow Circle Left"),
|
||||
new KeyValuePair<string, string>("arrow-circle-right" , "Arrow Circle Right"),
|
||||
new KeyValuePair<string, string>("arrow-circle-up" , "Arrow Circle Up"),
|
||||
new KeyValuePair<string, string>("asterisk" , "Asterisk"),
|
||||
new KeyValuePair<string, string>("ban" , "Ban"),
|
||||
new KeyValuePair<string, string>("beer" , "Beer"),
|
||||
new KeyValuePair<string, string>("bell" , "Bell"),
|
||||
new KeyValuePair<string, string>("bolt" , "Bolt"),
|
||||
new KeyValuePair<string, string>("bomb" , "Bomb"),
|
||||
new KeyValuePair<string, string>("book" , "Book"),
|
||||
new KeyValuePair<string, string>("bookmark" , "Bookmark"),
|
||||
new KeyValuePair<string, string>("briefcase" , "Briefcase"),
|
||||
new KeyValuePair<string, string>("bug" , "Bug"),
|
||||
new KeyValuePair<string, string>("building-o" , "Building"),
|
||||
new KeyValuePair<string, string>("bullhorn" , "Bullhorn"),
|
||||
new KeyValuePair<string, string>("bullseye" , "Bullseye"),
|
||||
new KeyValuePair<string, string>("cab" , "Cab"),
|
||||
new KeyValuePair<string, string>("calendar" , "Calendar"),
|
||||
new KeyValuePair<string, string>("calendar-o" , "Calendar"),
|
||||
new KeyValuePair<string, string>("car" , "Car"),
|
||||
new KeyValuePair<string, string>("check-circle" , "Check Circle"),
|
||||
new KeyValuePair<string, string>("child" , "Child"),
|
||||
new KeyValuePair<string, string>("clock-o" , "Clock"),
|
||||
new KeyValuePair<string, string>("cloud" , "Cloud"),
|
||||
new KeyValuePair<string, string>("coffee" , "Coffee"),
|
||||
new KeyValuePair<string, string>("comments" , "Comments"),
|
||||
new KeyValuePair<string, string>("compass" , "Compass"),
|
||||
new KeyValuePair<string, string>("credit-card" , "Credit Card"),
|
||||
new KeyValuePair<string, string>("crosshairs" , "Crosshairs"),
|
||||
new KeyValuePair<string, string>("cube" , "Cube"),
|
||||
new KeyValuePair<string, string>("cubes" , "Cubes"),
|
||||
new KeyValuePair<string, string>("desktop" , "Desktop"),
|
||||
new KeyValuePair<string, string>("dollar" , "Dollar"),
|
||||
new KeyValuePair<string, string>("dot-circle-o" , "Dot Circle"),
|
||||
new KeyValuePair<string, string>("envelope" , "Envelope"),
|
||||
new KeyValuePair<string, string>("exclamation" , "Exclamation"),
|
||||
new KeyValuePair<string, string>("eye" , "Eye"),
|
||||
new KeyValuePair<string, string>("fax" , "Fax"),
|
||||
new KeyValuePair<string, string>("female" , "Female"),
|
||||
new KeyValuePair<string, string>("fighter-jet" , "Fighter Jet"),
|
||||
new KeyValuePair<string, string>("film" , "Film"),
|
||||
new KeyValuePair<string, string>("filter" , "Filter"),
|
||||
new KeyValuePair<string, string>("fire" , "Fire"),
|
||||
new KeyValuePair<string, string>("fire-extinguisher" , "Fire Extinguisher"),
|
||||
new KeyValuePair<string, string>("flask" , "Flask"),
|
||||
new KeyValuePair<string, string>("frown-o" , "Frown"),
|
||||
new KeyValuePair<string, string>("gamepad" , "Gamepad"),
|
||||
new KeyValuePair<string, string>("gift" , "Gift"),
|
||||
new KeyValuePair<string, string>("glass" , "Glass"),
|
||||
new KeyValuePair<string, string>("globe" , "Globe"),
|
||||
new KeyValuePair<string, string>("graduation-cap" , "Graduation Cap"),
|
||||
new KeyValuePair<string, string>("hand-o-down" , "Hand Down"),
|
||||
new KeyValuePair<string, string>("hand-o-left" , "Hand Left"),
|
||||
new KeyValuePair<string, string>("hand-o-right" , "Hand Right"),
|
||||
new KeyValuePair<string, string>("hand-o-up" , "Hand Up"),
|
||||
new KeyValuePair<string, string>("hdd-o" , "Hdd"),
|
||||
new KeyValuePair<string, string>("heart" , "Heart"),
|
||||
new KeyValuePair<string, string>("history" , "History"),
|
||||
new KeyValuePair<string, string>("home" , "Home"),
|
||||
new KeyValuePair<string, string>("info" , "Info"),
|
||||
new KeyValuePair<string, string>("key" , "Key"),
|
||||
new KeyValuePair<string, string>("keyboard-o" , "Keyboard"),
|
||||
new KeyValuePair<string, string>("language" , "Language"),
|
||||
new KeyValuePair<string, string>("laptop" , "Laptop"),
|
||||
new KeyValuePair<string, string>("leaf" , "Leaf"),
|
||||
new KeyValuePair<string, string>("legal" , "Legal"),
|
||||
new KeyValuePair<string, string>("life-ring" , "Life Ring"),
|
||||
new KeyValuePair<string, string>("lightbulb-o" , "Lightbulb"),
|
||||
new KeyValuePair<string, string>("linux" , "Linux"),
|
||||
new KeyValuePair<string, string>("location-arrow" , "Location Arrow"),
|
||||
new KeyValuePair<string, string>("magnet" , "Magnet"),
|
||||
new KeyValuePair<string, string>("male" , "Male"),
|
||||
new KeyValuePair<string, string>("map-marker" , "Map Marker"),
|
||||
new KeyValuePair<string, string>("medkit" , "Medkit"),
|
||||
new KeyValuePair<string, string>("meh-o" , "Meh"),
|
||||
new KeyValuePair<string, string>("microphone" , "Microphone"),
|
||||
new KeyValuePair<string, string>("microphone-slash" , "Microphone Slash"),
|
||||
new KeyValuePair<string, string>("minus-circle" , "Minus Circle"),
|
||||
new KeyValuePair<string, string>("mobile" , "Mobile"),
|
||||
new KeyValuePair<string, string>("money" , "Money"),
|
||||
new KeyValuePair<string, string>("moon-o" , "Moon"),
|
||||
new KeyValuePair<string, string>("music" , "Music"),
|
||||
new KeyValuePair<string, string>("paper-plane" , "Paper Plane"),
|
||||
new KeyValuePair<string, string>("paperclip" , "Paperclip"),
|
||||
new KeyValuePair<string, string>("paw" , "Paw"),
|
||||
new KeyValuePair<string, string>("pencil" , "Pencil"),
|
||||
new KeyValuePair<string, string>("phone" , "Phone"),
|
||||
new KeyValuePair<string, string>("picture-o" , "Picture"),
|
||||
new KeyValuePair<string, string>("plane" , "Plane"),
|
||||
new KeyValuePair<string, string>("power-off" , "Power Off"),
|
||||
new KeyValuePair<string, string>("print" , "Print"),
|
||||
new KeyValuePair<string, string>("puzzle-piece" , "Puzzle Piece"),
|
||||
new KeyValuePair<string, string>("question" , "Question"),
|
||||
new KeyValuePair<string, string>("question-circle" , "Question Circle"),
|
||||
new KeyValuePair<string, string>("random" , "Random"),
|
||||
new KeyValuePair<string, string>("recycle" , "Recycle"),
|
||||
new KeyValuePair<string, string>("retweet" , "Retweet"),
|
||||
new KeyValuePair<string, string>("road" , "Road"),
|
||||
new KeyValuePair<string, string>("rocket" , "Rocket"),
|
||||
new KeyValuePair<string, string>("shield" , "Shield"),
|
||||
new KeyValuePair<string, string>("shopping-cart" , "Shopping Cart"),
|
||||
new KeyValuePair<string, string>("smile-o" , "Smile"),
|
||||
new KeyValuePair<string, string>("space-shuttle" , "Space Shuttle"),
|
||||
new KeyValuePair<string, string>("star" , "Star"),
|
||||
new KeyValuePair<string, string>("suitcase" , "Suitcase"),
|
||||
new KeyValuePair<string, string>("sun-o" , "Sun"),
|
||||
new KeyValuePair<string, string>("tablet" , "Tablet"),
|
||||
new KeyValuePair<string, string>("tachometer" , "Tachometer"),
|
||||
new KeyValuePair<string, string>("tasks" , "Tasks"),
|
||||
new KeyValuePair<string, string>("thumbs-down" , "Thumbs Down"),
|
||||
new KeyValuePair<string, string>("thumbs-o-down" , "Thumbs Down"),
|
||||
new KeyValuePair<string, string>("thumbs-o-up" , "Thumbs Up"),
|
||||
new KeyValuePair<string, string>("thumbs-up" , "Thumbs Up"),
|
||||
new KeyValuePair<string, string>("thumb-tack" , "Thumb Tack"),
|
||||
new KeyValuePair<string, string>("trash-o" , "Trash"),
|
||||
new KeyValuePair<string, string>("trophy" , "Trophy"),
|
||||
new KeyValuePair<string, string>("truck" , "Truck"),
|
||||
new KeyValuePair<string, string>("umbrella" , "Umbrella"),
|
||||
new KeyValuePair<string, string>("university" , "University"),
|
||||
new KeyValuePair<string, string>("wheelchair" , "Wheelchair"),
|
||||
new KeyValuePair<string, string>("windows" , "Windows"),
|
||||
new KeyValuePair<string, string>("wrench" , "Wrench")
|
||||
}.AsReadOnly();
|
||||
|
||||
// Icon Colours
|
||||
ThemeColours = new List<KeyValuePair<string, string>>(){
|
||||
new KeyValuePair<string, string>("lime" , "Lime"),
|
||||
new KeyValuePair<string, string>("green" , "Green"),
|
||||
new KeyValuePair<string, string>("emerald" , "Emerald"),
|
||||
new KeyValuePair<string, string>("teal" , "Teal"),
|
||||
new KeyValuePair<string, string>("cyan" , "Cyan"),
|
||||
new KeyValuePair<string, string>("cobalt" , "Cobalt"),
|
||||
new KeyValuePair<string, string>("indigo" , "Indigo"),
|
||||
new KeyValuePair<string, string>("violet" , "Violet"),
|
||||
new KeyValuePair<string, string>("pink" , "Pink"),
|
||||
new KeyValuePair<string, string>("magenta" , "Magenta"),
|
||||
new KeyValuePair<string, string>("crimson" , "Crimson"),
|
||||
new KeyValuePair<string, string>("red" , "Red"),
|
||||
new KeyValuePair<string, string>("orange" , "Orange"),
|
||||
new KeyValuePair<string, string>("amber" , "Amber"),
|
||||
new KeyValuePair<string, string>("yellow" , "Yellow"),
|
||||
new KeyValuePair<string, string>("brown" , "Brown"),
|
||||
new KeyValuePair<string, string>("olive" , "Olive"),
|
||||
new KeyValuePair<string, string>("steel" , "Steel"),
|
||||
new KeyValuePair<string, string>("mauve" , "Mauve"),
|
||||
new KeyValuePair<string, string>("sienna" , "Sienna")
|
||||
}.AsReadOnly();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,6 @@ namespace Disco.Services.Jobs.JobQueues
|
||||
private ConcurrentDictionary<int, JobQueueToken> _Cache;
|
||||
private Dictionary<string, List<JobQueueToken>> _SubjectCache;
|
||||
|
||||
private ReadOnlyCollection<KeyValuePair<string, string>> _Icons;
|
||||
private ReadOnlyCollection<KeyValuePair<string, string>> _IconColourCache;
|
||||
private ReadOnlyCollection<KeyValuePair<int, string>> _SlaOptions;
|
||||
|
||||
public Cache(DiscoDataContext Database)
|
||||
@@ -29,20 +27,6 @@ namespace Disco.Services.Jobs.JobQueues
|
||||
// Queues from Database
|
||||
var queues = Database.JobQueues.ToList();
|
||||
|
||||
// Default System Queue
|
||||
//var defaultQueue = new JobQueue()
|
||||
//{
|
||||
// Id = 0,
|
||||
// Name = "Default Queue",
|
||||
// Description = "Default system queue for orphaned jobs",
|
||||
// Icon = "question-circle",
|
||||
// IconColour = "F0A30A",
|
||||
// DefaultSLAExpiry = null,
|
||||
// Priority = JobQueuePriority.Normal,
|
||||
// SubjectIds = null
|
||||
//};
|
||||
//queues.Add(defaultQueue);
|
||||
|
||||
// Add Queues to In-Memory Cache
|
||||
this._Cache = new ConcurrentDictionary<int, JobQueueToken>(queues.Select(q => new KeyValuePair<int, JobQueueToken>(q.Id, JobQueueToken.FromJobQueue(q))));
|
||||
|
||||
@@ -50,168 +34,6 @@ namespace Disco.Services.Jobs.JobQueues
|
||||
CalculateSubjectCache();
|
||||
|
||||
#region Predefined Options
|
||||
// Icons
|
||||
if (this._Icons == null)
|
||||
{
|
||||
this._Icons = new List<KeyValuePair<string, string>>(){
|
||||
new KeyValuePair<string, string>("ambulance" , "Ambulance"),
|
||||
new KeyValuePair<string, string>("anchor" , "Anchor"),
|
||||
new KeyValuePair<string, string>("android" , "Android"),
|
||||
new KeyValuePair<string, string>("apple" , "Apple"),
|
||||
new KeyValuePair<string, string>("archive" , "Archive"),
|
||||
new KeyValuePair<string, string>("arrow-circle-down" , "Arrow Circle Down"),
|
||||
new KeyValuePair<string, string>("arrow-circle-left" , "Arrow Circle Left"),
|
||||
new KeyValuePair<string, string>("arrow-circle-right" , "Arrow Circle Right"),
|
||||
new KeyValuePair<string, string>("arrow-circle-up" , "Arrow Circle Up"),
|
||||
new KeyValuePair<string, string>("asterisk" , "Asterisk"),
|
||||
new KeyValuePair<string, string>("ban" , "Ban"),
|
||||
new KeyValuePair<string, string>("beer" , "Beer"),
|
||||
new KeyValuePair<string, string>("bell" , "Bell"),
|
||||
new KeyValuePair<string, string>("bolt" , "Bolt"),
|
||||
new KeyValuePair<string, string>("bomb" , "Bomb"),
|
||||
new KeyValuePair<string, string>("book" , "Book"),
|
||||
new KeyValuePair<string, string>("bookmark" , "Bookmark"),
|
||||
new KeyValuePair<string, string>("briefcase" , "Briefcase"),
|
||||
new KeyValuePair<string, string>("bug" , "Bug"),
|
||||
new KeyValuePair<string, string>("building-o" , "Building"),
|
||||
new KeyValuePair<string, string>("bullhorn" , "Bullhorn"),
|
||||
new KeyValuePair<string, string>("bullseye" , "Bullseye"),
|
||||
new KeyValuePair<string, string>("cab" , "Cab"),
|
||||
new KeyValuePair<string, string>("calendar" , "Calendar"),
|
||||
new KeyValuePair<string, string>("calendar-o" , "Calendar"),
|
||||
new KeyValuePair<string, string>("car" , "Car"),
|
||||
new KeyValuePair<string, string>("check-circle" , "Check Circle"),
|
||||
new KeyValuePair<string, string>("child" , "Child"),
|
||||
new KeyValuePair<string, string>("clock-o" , "Clock"),
|
||||
new KeyValuePair<string, string>("cloud" , "Cloud"),
|
||||
new KeyValuePair<string, string>("coffee" , "Coffee"),
|
||||
new KeyValuePair<string, string>("comments" , "Comments"),
|
||||
new KeyValuePair<string, string>("compass" , "Compass"),
|
||||
new KeyValuePair<string, string>("credit-card" , "Credit Card"),
|
||||
new KeyValuePair<string, string>("crosshairs" , "Crosshairs"),
|
||||
new KeyValuePair<string, string>("cube" , "Cube"),
|
||||
new KeyValuePair<string, string>("cubes" , "Cubes"),
|
||||
new KeyValuePair<string, string>("desktop" , "Desktop"),
|
||||
new KeyValuePair<string, string>("dollar" , "Dollar"),
|
||||
new KeyValuePair<string, string>("dot-circle-o" , "Dot Circle"),
|
||||
new KeyValuePair<string, string>("envelope" , "Envelope"),
|
||||
new KeyValuePair<string, string>("exclamation" , "Exclamation"),
|
||||
new KeyValuePair<string, string>("eye" , "Eye"),
|
||||
new KeyValuePair<string, string>("fax" , "Fax"),
|
||||
new KeyValuePair<string, string>("female" , "Female"),
|
||||
new KeyValuePair<string, string>("fighter-jet" , "Fighter Jet"),
|
||||
new KeyValuePair<string, string>("film" , "Film"),
|
||||
new KeyValuePair<string, string>("filter" , "Filter"),
|
||||
new KeyValuePair<string, string>("fire" , "Fire"),
|
||||
new KeyValuePair<string, string>("fire-extinguisher" , "Fire Extinguisher"),
|
||||
new KeyValuePair<string, string>("flask" , "Flask"),
|
||||
new KeyValuePair<string, string>("frown-o" , "Frown"),
|
||||
new KeyValuePair<string, string>("gamepad" , "Gamepad"),
|
||||
new KeyValuePair<string, string>("gift" , "Gift"),
|
||||
new KeyValuePair<string, string>("glass" , "Glass"),
|
||||
new KeyValuePair<string, string>("globe" , "Globe"),
|
||||
new KeyValuePair<string, string>("graduation-cap" , "Graduation Cap"),
|
||||
new KeyValuePair<string, string>("hand-o-down" , "Hand Down"),
|
||||
new KeyValuePair<string, string>("hand-o-left" , "Hand Left"),
|
||||
new KeyValuePair<string, string>("hand-o-right" , "Hand Right"),
|
||||
new KeyValuePair<string, string>("hand-o-up" , "Hand Up"),
|
||||
new KeyValuePair<string, string>("hdd-o" , "Hdd"),
|
||||
new KeyValuePair<string, string>("heart" , "Heart"),
|
||||
new KeyValuePair<string, string>("history" , "History"),
|
||||
new KeyValuePair<string, string>("home" , "Home"),
|
||||
new KeyValuePair<string, string>("info" , "Info"),
|
||||
new KeyValuePair<string, string>("key" , "Key"),
|
||||
new KeyValuePair<string, string>("keyboard-o" , "Keyboard"),
|
||||
new KeyValuePair<string, string>("language" , "Language"),
|
||||
new KeyValuePair<string, string>("laptop" , "Laptop"),
|
||||
new KeyValuePair<string, string>("leaf" , "Leaf"),
|
||||
new KeyValuePair<string, string>("legal" , "Legal"),
|
||||
new KeyValuePair<string, string>("life-ring" , "Life Ring"),
|
||||
new KeyValuePair<string, string>("lightbulb-o" , "Lightbulb"),
|
||||
new KeyValuePair<string, string>("linux" , "Linux"),
|
||||
new KeyValuePair<string, string>("location-arrow" , "Location Arrow"),
|
||||
new KeyValuePair<string, string>("magnet" , "Magnet"),
|
||||
new KeyValuePair<string, string>("male" , "Male"),
|
||||
new KeyValuePair<string, string>("map-marker" , "Map Marker"),
|
||||
new KeyValuePair<string, string>("medkit" , "Medkit"),
|
||||
new KeyValuePair<string, string>("meh-o" , "Meh"),
|
||||
new KeyValuePair<string, string>("microphone" , "Microphone"),
|
||||
new KeyValuePair<string, string>("microphone-slash" , "Microphone Slash"),
|
||||
new KeyValuePair<string, string>("minus-circle" , "Minus Circle"),
|
||||
new KeyValuePair<string, string>("mobile" , "Mobile"),
|
||||
new KeyValuePair<string, string>("money" , "Money"),
|
||||
new KeyValuePair<string, string>("moon-o" , "Moon"),
|
||||
new KeyValuePair<string, string>("music" , "Music"),
|
||||
new KeyValuePair<string, string>("paper-plane" , "Paper Plane"),
|
||||
new KeyValuePair<string, string>("paperclip" , "Paperclip"),
|
||||
new KeyValuePair<string, string>("paw" , "Paw"),
|
||||
new KeyValuePair<string, string>("pencil" , "Pencil"),
|
||||
new KeyValuePair<string, string>("phone" , "Phone"),
|
||||
new KeyValuePair<string, string>("picture-o" , "Picture"),
|
||||
new KeyValuePair<string, string>("plane" , "Plane"),
|
||||
new KeyValuePair<string, string>("power-off" , "Power Off"),
|
||||
new KeyValuePair<string, string>("print" , "Print"),
|
||||
new KeyValuePair<string, string>("puzzle-piece" , "Puzzle Piece"),
|
||||
new KeyValuePair<string, string>("question" , "Question"),
|
||||
new KeyValuePair<string, string>("question-circle" , "Question Circle"),
|
||||
new KeyValuePair<string, string>("random" , "Random"),
|
||||
new KeyValuePair<string, string>("recycle" , "Recycle"),
|
||||
new KeyValuePair<string, string>("retweet" , "Retweet"),
|
||||
new KeyValuePair<string, string>("road" , "Road"),
|
||||
new KeyValuePair<string, string>("rocket" , "Rocket"),
|
||||
new KeyValuePair<string, string>("shield" , "Shield"),
|
||||
new KeyValuePair<string, string>("shopping-cart" , "Shopping Cart"),
|
||||
new KeyValuePair<string, string>("smile-o" , "Smile"),
|
||||
new KeyValuePair<string, string>("space-shuttle" , "Space Shuttle"),
|
||||
new KeyValuePair<string, string>("star" , "Star"),
|
||||
new KeyValuePair<string, string>("suitcase" , "Suitcase"),
|
||||
new KeyValuePair<string, string>("sun-o" , "Sun"),
|
||||
new KeyValuePair<string, string>("tablet" , "Tablet"),
|
||||
new KeyValuePair<string, string>("tachometer" , "Tachometer"),
|
||||
new KeyValuePair<string, string>("tasks" , "Tasks"),
|
||||
new KeyValuePair<string, string>("thumbs-down" , "Thumbs Down"),
|
||||
new KeyValuePair<string, string>("thumbs-o-down" , "Thumbs Down"),
|
||||
new KeyValuePair<string, string>("thumbs-o-up" , "Thumbs Up"),
|
||||
new KeyValuePair<string, string>("thumbs-up" , "Thumbs Up"),
|
||||
new KeyValuePair<string, string>("thumb-tack" , "Thumb Tack"),
|
||||
new KeyValuePair<string, string>("trash-o" , "Trash"),
|
||||
new KeyValuePair<string, string>("trophy" , "Trophy"),
|
||||
new KeyValuePair<string, string>("truck" , "Truck"),
|
||||
new KeyValuePair<string, string>("umbrella" , "Umbrella"),
|
||||
new KeyValuePair<string, string>("university" , "University"),
|
||||
new KeyValuePair<string, string>("wheelchair" , "Wheelchair"),
|
||||
new KeyValuePair<string, string>("windows" , "Windows"),
|
||||
new KeyValuePair<string, string>("wrench" , "Wrench")
|
||||
}.AsReadOnly();
|
||||
}
|
||||
|
||||
// Icon Colours
|
||||
if (this._IconColourCache == null)
|
||||
{
|
||||
this._IconColourCache = new List<KeyValuePair<string, string>>(){
|
||||
new KeyValuePair<string, string>("lime" , "Lime"),
|
||||
new KeyValuePair<string, string>("green" , "Green"),
|
||||
new KeyValuePair<string, string>("emerald" , "Emerald"),
|
||||
new KeyValuePair<string, string>("teal" , "Teal"),
|
||||
new KeyValuePair<string, string>("cyan" , "Cyan"),
|
||||
new KeyValuePair<string, string>("cobalt" , "Cobalt"),
|
||||
new KeyValuePair<string, string>("indigo" , "Indigo"),
|
||||
new KeyValuePair<string, string>("violet" , "Violet"),
|
||||
new KeyValuePair<string, string>("pink" , "Pink"),
|
||||
new KeyValuePair<string, string>("magenta" , "Magenta"),
|
||||
new KeyValuePair<string, string>("crimson" , "Crimson"),
|
||||
new KeyValuePair<string, string>("red" , "Red"),
|
||||
new KeyValuePair<string, string>("orange" , "Orange"),
|
||||
new KeyValuePair<string, string>("amber" , "Amber"),
|
||||
new KeyValuePair<string, string>("yellow" , "Yellow"),
|
||||
new KeyValuePair<string, string>("brown" , "Brown"),
|
||||
new KeyValuePair<string, string>("olive" , "Olive"),
|
||||
new KeyValuePair<string, string>("steel" , "Steel"),
|
||||
new KeyValuePair<string, string>("mauve" , "Mauve"),
|
||||
new KeyValuePair<string, string>("sienna" , "Sienna")
|
||||
}.AsReadOnly();
|
||||
}
|
||||
|
||||
// SLA Options
|
||||
if (this._SlaOptions == null)
|
||||
{
|
||||
@@ -251,8 +73,6 @@ namespace Disco.Services.Jobs.JobQueues
|
||||
select subjectId).ToDictionary(g => g.Key.ToLower(), g => g.ToList());
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<KeyValuePair<string, string>> Icons { get { return this._Icons; } }
|
||||
public ReadOnlyCollection<KeyValuePair<string, string>> IconColours { get { return this._IconColourCache; } }
|
||||
public ReadOnlyCollection<KeyValuePair<int, string>> SlaOptions { get { return this._SlaOptions; } }
|
||||
|
||||
public JobQueueToken UpdateQueue(JobQueue JobQueue)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.Repository;
|
||||
using Disco.Services.Authorization;
|
||||
using Disco.Services.Extensions;
|
||||
using Disco.Services.Tasks;
|
||||
using Disco.Services.Users;
|
||||
using System;
|
||||
@@ -23,8 +24,6 @@ namespace Disco.Services.Jobs.JobQueues
|
||||
_cache = new Cache(Database);
|
||||
}
|
||||
|
||||
public static ReadOnlyCollection<KeyValuePair<string, string>> IconColours { get { return _cache.IconColours; } }
|
||||
public static ReadOnlyCollection<KeyValuePair<string, string>> Icons { get { return _cache.Icons; } }
|
||||
public static ReadOnlyCollection<KeyValuePair<int, string>> SlaOptions { get { return _cache.SlaOptions; } }
|
||||
|
||||
public static ReadOnlyCollection<JobQueueToken> GetQueues() { return _cache.GetQueues(); }
|
||||
@@ -38,7 +37,7 @@ namespace Disco.Services.Jobs.JobQueues
|
||||
throw new ArgumentException("The Job Queue Name is required");
|
||||
|
||||
// Name Unique
|
||||
if (_cache.GetQueues().Count(q => q.JobQueue.Name == JobQueue.Name) > 0)
|
||||
if (_cache.GetQueues().Any(q => q.JobQueue.Name == JobQueue.Name))
|
||||
throw new ArgumentException("Another Job Queue already exists with that name", "JobQueue");
|
||||
|
||||
// Clone to break reference
|
||||
@@ -65,7 +64,7 @@ namespace Disco.Services.Jobs.JobQueues
|
||||
throw new ArgumentException("The Job Queue Name is required");
|
||||
|
||||
// Name Unique
|
||||
if (_cache.GetQueues().Count(q => q.JobQueue.Id != JobQueue.Id && q.JobQueue.Name == JobQueue.Name) > 0)
|
||||
if (_cache.GetQueues().Any(q => q.JobQueue.Id != JobQueue.Id && q.JobQueue.Name == JobQueue.Name))
|
||||
throw new ArgumentException("Another Job Queue already exists with that name", "JobQueue");
|
||||
|
||||
Database.SaveChanges();
|
||||
@@ -77,8 +76,8 @@ namespace Disco.Services.Jobs.JobQueues
|
||||
JobQueue queue = Database.JobQueues.Find(JobQueueId);
|
||||
|
||||
// Validate: Current Jobs?
|
||||
int currentJobCount = Database.JobQueueJobs.Count(jqj => jqj.JobQueueId == queue.Id && !jqj.RemovedDate.HasValue);
|
||||
if (currentJobCount > 0)
|
||||
var currentJobs = Database.JobQueueJobs.Any(jqj => jqj.JobQueueId == queue.Id && !jqj.RemovedDate.HasValue);
|
||||
if (currentJobs)
|
||||
throw new InvalidOperationException("The Job Queue cannot be deleted because it contains jobs");
|
||||
|
||||
// Delete History
|
||||
@@ -161,23 +160,13 @@ namespace Disco.Services.Jobs.JobQueues
|
||||
return tokens;
|
||||
}
|
||||
|
||||
public static string RandomIcon()
|
||||
public static string RandomUnusedIcon()
|
||||
{
|
||||
var rnd = new Random();
|
||||
var unusedIcons = _cache.Icons.Select(i => i.Key).Except(_cache.GetQueues().Select(q => q.JobQueue.Icon)).ToList();
|
||||
if (unusedIcons.Count > 0)
|
||||
return unusedIcons[rnd.Next(unusedIcons.Count - 1)];
|
||||
else
|
||||
return _cache.Icons[rnd.Next(_cache.Icons.Count - 1)].Key;
|
||||
return UIHelpers.RandomIcon(_cache.GetQueues().Select(q => q.JobQueue.Icon));
|
||||
}
|
||||
public static string RandomIconColour()
|
||||
public static string RandomUnusedThemeColour()
|
||||
{
|
||||
var rnd = new Random();
|
||||
var unusedColours = _cache.IconColours.Select(i => i.Key).Except(_cache.GetQueues().Select(q => q.JobQueue.IconColour)).ToList();
|
||||
if (unusedColours.Count > 0)
|
||||
return unusedColours[rnd.Next(unusedColours.Count - 1)];
|
||||
else
|
||||
return _cache.IconColours[rnd.Next(_cache.IconColours.Count - 1)].Key;
|
||||
return UIHelpers.RandomThemeColour(_cache.GetQueues().Select(q => q.JobQueue.IconColour));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,11 +145,14 @@ namespace Disco.Services.Searching
|
||||
return UserService.SearchUsers(Database, Term, PersistResults, LimitCount).Select(u => new UserSearchResultItem()
|
||||
{
|
||||
Id = u.UserId,
|
||||
FriendlyId = u.FriendlyId(),
|
||||
Surname = u.Surname,
|
||||
GivenName = u.GivenName,
|
||||
DisplayName = u.DisplayName,
|
||||
AssignedDevicesCount = 0,
|
||||
JobCount = 0
|
||||
JobCount = 0,
|
||||
JobCountOpen = 0,
|
||||
UserFlagAssignments = null
|
||||
}).OrderByDescending(i => i.ScoreValues.Score(Term)).ToList();
|
||||
}
|
||||
|
||||
@@ -160,23 +163,15 @@ namespace Disco.Services.Searching
|
||||
|
||||
// Search Active Directory
|
||||
var adResults = SearchUsersUpstream(Database, Term, PersistResults, LimitCount);
|
||||
|
||||
|
||||
// Search Database
|
||||
var dbResults = Database.Users.Where(u =>
|
||||
u.UserId.Contains(Term) ||
|
||||
u.Surname.Contains(Term) ||
|
||||
u.GivenName.Contains(Term) ||
|
||||
u.DisplayName.Contains(Term)
|
||||
).Select(u => new UserSearchResultItem()
|
||||
{
|
||||
Id = u.UserId,
|
||||
Surname = u.Surname,
|
||||
GivenName = u.GivenName,
|
||||
DisplayName = u.DisplayName,
|
||||
AssignedDevicesCount = u.DeviceUserAssignments.Where(dua => !dua.UnassignedDate.HasValue).Count(),
|
||||
JobCount = u.Jobs.Count()
|
||||
}).ToList();
|
||||
|
||||
u.DisplayName.Contains(Term))
|
||||
.ToUserSearchResultItems(null)
|
||||
.ToList();
|
||||
|
||||
IEnumerable<UserSearchResultItem> results;
|
||||
if (PersistResults)
|
||||
@@ -215,6 +210,35 @@ namespace Disco.Services.Searching
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
public static List<UserSearchResultItem> SearchUserFlag(DiscoDataContext Database, int UserFlagId)
|
||||
{
|
||||
return Database.UserFlagAssignments
|
||||
.Where(a => a.UserFlagId == UserFlagId && !a.RemovedDate.HasValue)
|
||||
.Select(a => a.User)
|
||||
.ToUserSearchResultItems(null);
|
||||
}
|
||||
|
||||
private static List<UserSearchResultItem> ToUserSearchResultItems(this IQueryable<User> Query, int? LimitCount = ActiveDirectory.DefaultSearchResultLimit)
|
||||
{
|
||||
if (LimitCount.HasValue)
|
||||
Query = Query.Take(LimitCount.Value);
|
||||
|
||||
var results = Query.Select(u => new UserSearchResultItem()
|
||||
{
|
||||
Id = u.UserId,
|
||||
Surname = u.Surname,
|
||||
GivenName = u.GivenName,
|
||||
DisplayName = u.DisplayName,
|
||||
AssignedDevicesCount = u.DeviceUserAssignments.Where(dua => !dua.UnassignedDate.HasValue).Count(),
|
||||
JobCount = u.Jobs.Count(),
|
||||
JobCountOpen = u.Jobs.Count(j => !j.ClosedDate.HasValue),
|
||||
UserFlagAssignments = u.UserFlagAssignments
|
||||
}).ToList();
|
||||
|
||||
results.ForEach(u => u.FriendlyId = UserExtensions.FriendlyUserId(u.Id));
|
||||
|
||||
return results;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Devices
|
||||
@@ -251,17 +275,17 @@ namespace Disco.Services.Searching
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public static List<DeviceSearchResultItem> SearchDeviceModel(DiscoDataContext Database, int DeviceModelId, int? LimitCount = ActiveDirectory.DefaultSearchResultLimit)
|
||||
public static List<DeviceSearchResultItem> SearchDeviceModel(DiscoDataContext Database, int DeviceModelId)
|
||||
{
|
||||
return Database.Devices.Where(d => d.DeviceModelId == DeviceModelId).ToDeviceSearchResultItems(LimitCount);
|
||||
return Database.Devices.Where(d => d.DeviceModelId == DeviceModelId).ToDeviceSearchResultItems(null);
|
||||
}
|
||||
public static List<DeviceSearchResultItem> SearchDeviceProfile(DiscoDataContext Database, int DeviceProfileId, int? LimitCount = ActiveDirectory.DefaultSearchResultLimit)
|
||||
public static List<DeviceSearchResultItem> SearchDeviceProfile(DiscoDataContext Database, int DeviceProfileId)
|
||||
{
|
||||
return Database.Devices.Where(d => d.DeviceProfileId == DeviceProfileId).ToDeviceSearchResultItems(LimitCount);
|
||||
return Database.Devices.Where(d => d.DeviceProfileId == DeviceProfileId).ToDeviceSearchResultItems(null);
|
||||
}
|
||||
public static List<DeviceSearchResultItem> SearchDeviceBatch(DiscoDataContext Database, int DeviceBatchId, int? LimitCount = ActiveDirectory.DefaultSearchResultLimit)
|
||||
public static List<DeviceSearchResultItem> SearchDeviceBatch(DiscoDataContext Database, int DeviceBatchId)
|
||||
{
|
||||
return Database.Devices.Where(d => d.DeviceBatchId == DeviceBatchId).ToDeviceSearchResultItems(LimitCount);
|
||||
return Database.Devices.Where(d => d.DeviceBatchId == DeviceBatchId).ToDeviceSearchResultItems(null);
|
||||
}
|
||||
|
||||
private static List<DeviceSearchResultItem> ToDeviceSearchResultItems(this IQueryable<Device> Query, int? LimitCount = ActiveDirectory.DefaultSearchResultLimit)
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.Repository;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Disco.Services.Users.UserFlags
|
||||
{
|
||||
internal class Cache
|
||||
{
|
||||
private ConcurrentDictionary<int, UserFlag> _Cache;
|
||||
|
||||
public Cache(DiscoDataContext Database)
|
||||
{
|
||||
Initialize(Database);
|
||||
}
|
||||
|
||||
public void ReInitialize(DiscoDataContext Database)
|
||||
{
|
||||
Initialize(Database);
|
||||
}
|
||||
|
||||
private void Initialize(DiscoDataContext Database)
|
||||
{
|
||||
// Queues from Database
|
||||
var flags = Database.UserFlags.ToList();
|
||||
|
||||
// Add Queues to In-Memory Cache
|
||||
this._Cache = new ConcurrentDictionary<int, UserFlag>(flags.Select(f => new KeyValuePair<int, UserFlag>(f.Id, f)));
|
||||
}
|
||||
|
||||
public UserFlag GetUserFlag(int UserFlagId)
|
||||
{
|
||||
UserFlag item;
|
||||
if (_Cache.TryGetValue(UserFlagId, out item))
|
||||
return item;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
public List<UserFlag> GetUserFlags()
|
||||
{
|
||||
return _Cache.Values.ToList();
|
||||
}
|
||||
|
||||
public UserFlag Update(UserFlag UserFlag)
|
||||
{
|
||||
UserFlag existingItem;
|
||||
|
||||
if (_Cache.TryGetValue(UserFlag.Id, out existingItem))
|
||||
{
|
||||
if (_Cache.TryUpdate(UserFlag.Id, UserFlag, existingItem))
|
||||
{
|
||||
return UserFlag;
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_Cache.TryAdd(UserFlag.Id, UserFlag))
|
||||
{
|
||||
return UserFlag;
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public UserFlag Remove(int UserFlagId)
|
||||
{
|
||||
UserFlag item;
|
||||
if (_Cache.TryRemove(UserFlagId, out item))
|
||||
return item;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
public UserFlag Remove(UserFlag UserFlag)
|
||||
{
|
||||
return Remove(UserFlag.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.Repository;
|
||||
using Disco.Services.Extensions;
|
||||
using Disco.Services.Tasks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Disco.Services.Users.UserFlags
|
||||
{
|
||||
public static class UserFlagService
|
||||
{
|
||||
private static Cache _cache;
|
||||
|
||||
public static void Initialize(DiscoDataContext Database)
|
||||
{
|
||||
_cache = new Cache(Database);
|
||||
}
|
||||
|
||||
public static List<UserFlag> GetUserFlags() { return _cache.GetUserFlags(); }
|
||||
public static UserFlag GetUserFlag(int UserFlagId) { return _cache.GetUserFlag(UserFlagId); }
|
||||
|
||||
#region User Flag Maintenance
|
||||
public static UserFlag CreateUserFlag(DiscoDataContext Database, UserFlag UserFlag)
|
||||
{
|
||||
// Verify
|
||||
if (string.IsNullOrWhiteSpace(UserFlag.Name))
|
||||
throw new ArgumentException("The User Flag Name is required");
|
||||
|
||||
// Name Unique
|
||||
if (_cache.GetUserFlags().Any(f => f.Name == UserFlag.Name))
|
||||
throw new ArgumentException("Another User Flag already exists with that name", "UserFlag");
|
||||
|
||||
// Clone to break reference
|
||||
var flag = new UserFlag()
|
||||
{
|
||||
Name = UserFlag.Name,
|
||||
Description = UserFlag.Description,
|
||||
Icon = UserFlag.Icon,
|
||||
IconColour = UserFlag.IconColour
|
||||
};
|
||||
|
||||
Database.UserFlags.Add(flag);
|
||||
Database.SaveChanges();
|
||||
|
||||
return _cache.Update(flag);
|
||||
}
|
||||
public static UserFlag Update(DiscoDataContext Database, UserFlag UserFlag)
|
||||
{
|
||||
// Verify
|
||||
if (string.IsNullOrWhiteSpace(UserFlag.Name))
|
||||
throw new ArgumentException("The User Flag Name is required");
|
||||
|
||||
// Name Unique
|
||||
if (_cache.GetUserFlags().Any(f => f.Id != UserFlag.Id && f.Name == UserFlag.Name))
|
||||
throw new ArgumentException("Another User Flag already exists with that name", "UserFlag");
|
||||
|
||||
Database.SaveChanges();
|
||||
|
||||
return _cache.Update(UserFlag);
|
||||
}
|
||||
public static void DeleteUserFlag(DiscoDataContext Database, int UserFlagId, IScheduledTaskStatus Status)
|
||||
{
|
||||
UserFlag flag = Database.UserFlags.Find(UserFlagId);
|
||||
|
||||
// Delete Assignments
|
||||
Status.UpdateStatus(0, string.Format("Removing '{0}' [{1}] User Flag", flag.Name, flag.Id), "Starting");
|
||||
List<UserFlagAssignment> flagAssignments = Database.UserFlagAssignments.Where(fa => fa.UserFlagId == flag.Id).ToList();
|
||||
if (flagAssignments.Count > 0)
|
||||
{
|
||||
Status.UpdateStatus(20, "Removing flag from users");
|
||||
flagAssignments.ForEach(flagAssignment => Database.UserFlagAssignments.Remove(flagAssignment));
|
||||
Database.SaveChanges();
|
||||
}
|
||||
|
||||
// Delete Flag
|
||||
Status.UpdateStatus(90, "Deleting User Flag");
|
||||
Database.UserFlags.Remove(flag);
|
||||
Database.SaveChanges();
|
||||
|
||||
// Remove from Cache
|
||||
_cache.Remove(UserFlagId);
|
||||
|
||||
Status.Finished(string.Format("Successfully Deleted User Flag: '{0}' [{1}]", flag.Name, flag.Id));
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static string RandomUnusedIcon()
|
||||
{
|
||||
return UIHelpers.RandomIcon(_cache.GetUserFlags().Select(f => f.Icon));
|
||||
}
|
||||
public static string RandomUnusedThemeColour()
|
||||
{
|
||||
return UIHelpers.RandomThemeColour(_cache.GetUserFlags().Select(f => f.IconColour));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Services.Tasks;
|
||||
using Quartz;
|
||||
|
||||
namespace Disco.Services.Users.UserFlags
|
||||
{
|
||||
public class UserFlagDeleteTask : ScheduledTask
|
||||
{
|
||||
public override string TaskName { get { return "User Flags - Delete Flag"; } }
|
||||
|
||||
public override bool SingleInstanceTask { get { return false; }}
|
||||
public override bool CancelInitiallySupported { get { return false; } }
|
||||
public override bool LogExceptionsOnly { get { return true; } }
|
||||
|
||||
protected override void ExecuteTask()
|
||||
{
|
||||
int UserFlagId = (int)this.ExecutionContext.JobDetail.JobDataMap["UserFlagId"];
|
||||
|
||||
using (DiscoDataContext Database = new DiscoDataContext())
|
||||
{
|
||||
UserFlagService.DeleteUserFlag(Database, UserFlagId, this.Status);
|
||||
}
|
||||
}
|
||||
|
||||
public static ScheduledTaskStatus ScheduleNow(int UserFlagId)
|
||||
{
|
||||
JobDataMap taskData = new JobDataMap() { { "UserFlagId", UserFlagId } };
|
||||
|
||||
var instance = new UserFlagDeleteTask();
|
||||
|
||||
return instance.ScheduleTask(taskData);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user