Bug fix #106 - job queues: case-sensitive usernames
This commit is contained in:
@@ -5,8 +5,6 @@ using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Disco.Services.Jobs.JobQueues
|
||||
{
|
||||
@@ -28,16 +26,16 @@ namespace Disco.Services.Jobs.JobQueues
|
||||
var queues = Database.JobQueues.ToList();
|
||||
|
||||
// Add Queues to In-Memory Cache
|
||||
this._Cache = new ConcurrentDictionary<int, JobQueueToken>(queues.Select(q => new KeyValuePair<int, JobQueueToken>(q.Id, JobQueueToken.FromJobQueue(q))));
|
||||
_Cache = new ConcurrentDictionary<int, JobQueueToken>(queues.Select(q => new KeyValuePair<int, JobQueueToken>(q.Id, JobQueueToken.FromJobQueue(q))));
|
||||
|
||||
// Calculate Queue Subject Cache
|
||||
CalculateSubjectCache();
|
||||
|
||||
#region Predefined Options
|
||||
// SLA Options
|
||||
if (this._SlaOptions == null)
|
||||
if (_SlaOptions == null)
|
||||
{
|
||||
this._SlaOptions = new List<KeyValuePair<int, string>>()
|
||||
_SlaOptions = new List<KeyValuePair<int, string>>()
|
||||
{
|
||||
new KeyValuePair<int, string>(0, "<None>"),
|
||||
new KeyValuePair<int, string>(15, "15 minutes"),
|
||||
@@ -67,13 +65,13 @@ namespace Disco.Services.Jobs.JobQueues
|
||||
}
|
||||
private void CalculateSubjectCache()
|
||||
{
|
||||
_SubjectCache = (from c in _Cache.Values.ToList()
|
||||
from s in c.SubjectIds
|
||||
group c by s into subjectId
|
||||
select subjectId).ToDictionary(g => g.Key.ToLower(), g => g.ToList());
|
||||
_SubjectCache = _Cache.Values.ToList()
|
||||
.SelectMany(t => t.SubjectIds, (t, s) => new { t, s })
|
||||
.GroupBy(i => i.s, StringComparer.OrdinalIgnoreCase)
|
||||
.ToDictionary(g => g.Key, g => g.Select(i => i.t).ToList(), StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<KeyValuePair<int, string>> SlaOptions { get { return this._SlaOptions; } }
|
||||
public ReadOnlyCollection<KeyValuePair<int, string>> SlaOptions { get { return _SlaOptions; } }
|
||||
|
||||
public JobQueueToken UpdateQueue(JobQueue JobQueue)
|
||||
{
|
||||
@@ -131,7 +129,7 @@ namespace Disco.Services.Jobs.JobQueues
|
||||
private IEnumerable<JobQueueToken> GetQueuesForSubject(string SubjectId)
|
||||
{
|
||||
List<JobQueueToken> tokens;
|
||||
if (_SubjectCache.TryGetValue(SubjectId.ToLower(), out tokens))
|
||||
if (_SubjectCache.TryGetValue(SubjectId, out tokens))
|
||||
return tokens;
|
||||
else
|
||||
return Enumerable.Empty<JobQueueToken>();
|
||||
|
||||
@@ -8,8 +8,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace Disco.Services.Jobs.JobQueues
|
||||
@@ -40,6 +38,21 @@ namespace Disco.Services.Jobs.JobQueues
|
||||
if (_cache.GetQueues().Any(q => q.JobQueue.Name == JobQueue.Name))
|
||||
throw new ArgumentException("Another Job Queue already exists with that name", "JobQueue");
|
||||
|
||||
// Sanitize Subject Ids
|
||||
if (string.IsNullOrWhiteSpace(JobQueue.SubjectIds))
|
||||
{
|
||||
JobQueue.SubjectIds = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var subjectIds = JobQueue.SubjectIds.Split(',');
|
||||
foreach (var subjectId in subjectIds)
|
||||
{
|
||||
UserService.GetUser(subjectId, Database);
|
||||
}
|
||||
JobQueue.SubjectIds = string.Join(",", Database.Users.Where(u => subjectIds.Contains(u.UserId)).Select(u => u.UserId));
|
||||
}
|
||||
|
||||
// Clone to break reference
|
||||
var queue = new JobQueue()
|
||||
{
|
||||
@@ -67,6 +80,21 @@ namespace Disco.Services.Jobs.JobQueues
|
||||
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");
|
||||
|
||||
// Sanitize Subject Ids
|
||||
if (string.IsNullOrWhiteSpace(JobQueue.SubjectIds))
|
||||
{
|
||||
JobQueue.SubjectIds = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var subjectIds = JobQueue.SubjectIds.Split(',');
|
||||
foreach (var subjectId in subjectIds)
|
||||
{
|
||||
UserService.GetUser(subjectId, Database);
|
||||
}
|
||||
JobQueue.SubjectIds = string.Join(",", Database.Users.Where(u => subjectIds.Contains(u.UserId)).Select(u => u.UserId));
|
||||
}
|
||||
|
||||
Database.SaveChanges();
|
||||
|
||||
return _cache.UpdateQueue(JobQueue);
|
||||
|
||||
@@ -14,16 +14,19 @@
|
||||
<div id="Config_JobQueues_Show" class="form" style="width: 550px">
|
||||
<table>
|
||||
<tr>
|
||||
<th style="width: 150px">Id:
|
||||
<th style="width: 150px">
|
||||
Id:
|
||||
</th>
|
||||
<td>
|
||||
@Html.DisplayFor(model => model.Token.JobQueue.Id)
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Name:
|
||||
<th>
|
||||
Name:
|
||||
</th>
|
||||
<td>@if (canConfig)
|
||||
<td>
|
||||
@if (canConfig)
|
||||
{@Html.EditorFor(model => model.Token.JobQueue.Name)
|
||||
@AjaxHelpers.AjaxSave()
|
||||
@AjaxHelpers.AjaxLoader()
|
||||
@@ -45,9 +48,11 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Description:
|
||||
<th>
|
||||
Description:
|
||||
</th>
|
||||
<td>@if (canConfig)
|
||||
<td>
|
||||
@if (canConfig)
|
||||
{@Html.EditorFor(model => model.Token.JobQueue.Description)
|
||||
@AjaxHelpers.AjaxSave()
|
||||
@AjaxHelpers.AjaxLoader()
|
||||
@@ -77,7 +82,8 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Statistics:
|
||||
<th>
|
||||
Statistics:
|
||||
</th>
|
||||
<td>
|
||||
<div><strong>@Model.OpenJobCount job@(Model.OpenJobCount != 1 ? "s" : null) open</strong></div>
|
||||
@@ -85,7 +91,8 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Icon:
|
||||
<th>
|
||||
Icon:
|
||||
</th>
|
||||
<td>
|
||||
<i id="Config_JobQueues_Icon" data-icon="@(Model.Token.JobQueue.Icon)" data-colour="@(Model.Token.JobQueue.IconColour)" class="fa fa-@(Model.Token.JobQueue.Icon) fa-4x d-@(Model.Token.JobQueue.IconColour)"></i>
|
||||
@@ -191,9 +198,11 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Priority:
|
||||
<th>
|
||||
Priority:
|
||||
</th>
|
||||
<td>@if (canConfig)
|
||||
<td>
|
||||
@if (canConfig)
|
||||
{
|
||||
var priorityValue = Model.Token.JobQueue.Priority.ToString();
|
||||
var priorityItems = Enum.GetNames(typeof(JobQueuePriority)).Select(i => new SelectListItem() { Text = i, Value = i, Selected = (i == priorityValue) }).ToList();
|
||||
@@ -227,9 +236,11 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Default SLA:
|
||||
<th>
|
||||
Default SLA:
|
||||
</th>
|
||||
<td>@if (canConfig)
|
||||
<td>
|
||||
@if (canConfig)
|
||||
{
|
||||
var slaOptions = JobQueueService.SlaOptions.Select(o => new SelectListItem() { Text = o.Value, Value = o.Key.ToString() }).ToList();
|
||||
|
||||
@@ -302,14 +313,16 @@
|
||||
@foreach (var sg in Model.Subjects)
|
||||
{
|
||||
var displayName = sg.Id == sg.Name ? sg.Id : string.Format("{0} [{1}]", sg.Name, sg.Id);
|
||||
<li class="@(sg.IsGroup ? "group" : "user")">@if (sg.IsGroup)
|
||||
<li class="@(sg.IsGroup ? "group" : "user")">
|
||||
@if (sg.IsGroup)
|
||||
{
|
||||
<i class="fa fa-users fa-lg"></i>@displayName
|
||||
}
|
||||
else
|
||||
{
|
||||
<a href="@(Url.Action(MVC.User.Show(sg.Id)))"><i class="fa fa-user fa-lg"></i>@displayName</a>
|
||||
}</li>
|
||||
}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
@@ -324,14 +337,16 @@
|
||||
@foreach (var sg in Model.Subjects)
|
||||
{
|
||||
var displayName = sg.Id == sg.Name ? sg.Id : string.Format("{0} [{1}]", sg.Name, sg.Id);
|
||||
<li class="@(sg.IsGroup ? "group" : "user")" data-subjectid="@sg.Id">@if (sg.IsGroup)
|
||||
<li class="@(sg.IsGroup ? "group" : "user")" data-subjectid="@sg.Id">
|
||||
@if (sg.IsGroup)
|
||||
{
|
||||
<i class="fa fa-users fa-lg"></i>@displayName
|
||||
}
|
||||
else
|
||||
{
|
||||
<i class="fa fa-user fa-lg"></i>@displayName
|
||||
}<i class="fa fa-times-circle remove"></i></li>
|
||||
}<i class="fa fa-times-circle remove"></i>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
@@ -420,6 +435,8 @@
|
||||
}
|
||||
|
||||
updateNoSubjects();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function add() {
|
||||
@@ -464,6 +481,8 @@
|
||||
}).fail(function (jqXHR, textStatus, errorThrown) {
|
||||
alert('Error: ' + errorThrown);
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function updateNoSubjects() {
|
||||
@@ -546,7 +565,8 @@
|
||||
{
|
||||
<div id="trJobType@(jt.Id)" class="jobTypes">
|
||||
<h4>
|
||||
<input id="Types_@(jt.Id)" class="jobType" type="checkbox" value="@(jt.Id)" @(selectedTypes.Contains(jt) ? "checked=\"checked\"" : null) /><label for="Types_@(jt.Id)">@jt.Description</label></h4>
|
||||
<input id="Types_@(jt.Id)" class="jobType" type="checkbox" value="@(jt.Id)" @(selectedTypes.Contains(jt) ? "checked=\"checked\"" : null) /><label for="Types_@(jt.Id)">@jt.Description</label>
|
||||
</h4>
|
||||
<div id="SubTypes_@(jt.Id)" class="jobSubTypes">
|
||||
@CommonHelpers.CheckboxBulkSelect(string.Format("CheckboxBulkSelect_{0}", jt.Id), "div")
|
||||
@CommonHelpers.CheckBoxList("JobSubTypes", jt.JobSubTypes.OrderBy(jst => jst.Description).ToSelectListItems(Model.Token.JobQueue.JobSubTypes), 2)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user