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.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Disco.Services.Jobs.JobQueues
|
namespace Disco.Services.Jobs.JobQueues
|
||||||
{
|
{
|
||||||
@@ -28,16 +26,16 @@ namespace Disco.Services.Jobs.JobQueues
|
|||||||
var queues = Database.JobQueues.ToList();
|
var queues = Database.JobQueues.ToList();
|
||||||
|
|
||||||
// Add Queues to In-Memory Cache
|
// 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
|
// Calculate Queue Subject Cache
|
||||||
CalculateSubjectCache();
|
CalculateSubjectCache();
|
||||||
|
|
||||||
#region Predefined Options
|
#region Predefined Options
|
||||||
// SLA 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>(0, "<None>"),
|
||||||
new KeyValuePair<int, string>(15, "15 minutes"),
|
new KeyValuePair<int, string>(15, "15 minutes"),
|
||||||
@@ -67,13 +65,13 @@ namespace Disco.Services.Jobs.JobQueues
|
|||||||
}
|
}
|
||||||
private void CalculateSubjectCache()
|
private void CalculateSubjectCache()
|
||||||
{
|
{
|
||||||
_SubjectCache = (from c in _Cache.Values.ToList()
|
_SubjectCache = _Cache.Values.ToList()
|
||||||
from s in c.SubjectIds
|
.SelectMany(t => t.SubjectIds, (t, s) => new { t, s })
|
||||||
group c by s into subjectId
|
.GroupBy(i => i.s, StringComparer.OrdinalIgnoreCase)
|
||||||
select subjectId).ToDictionary(g => g.Key.ToLower(), g => g.ToList());
|
.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)
|
public JobQueueToken UpdateQueue(JobQueue JobQueue)
|
||||||
{
|
{
|
||||||
@@ -131,7 +129,7 @@ namespace Disco.Services.Jobs.JobQueues
|
|||||||
private IEnumerable<JobQueueToken> GetQueuesForSubject(string SubjectId)
|
private IEnumerable<JobQueueToken> GetQueuesForSubject(string SubjectId)
|
||||||
{
|
{
|
||||||
List<JobQueueToken> tokens;
|
List<JobQueueToken> tokens;
|
||||||
if (_SubjectCache.TryGetValue(SubjectId.ToLower(), out tokens))
|
if (_SubjectCache.TryGetValue(SubjectId, out tokens))
|
||||||
return tokens;
|
return tokens;
|
||||||
else
|
else
|
||||||
return Enumerable.Empty<JobQueueToken>();
|
return Enumerable.Empty<JobQueueToken>();
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
|
||||||
namespace Disco.Services.Jobs.JobQueues
|
namespace Disco.Services.Jobs.JobQueues
|
||||||
@@ -40,6 +38,21 @@ namespace Disco.Services.Jobs.JobQueues
|
|||||||
if (_cache.GetQueues().Any(q => q.JobQueue.Name == JobQueue.Name))
|
if (_cache.GetQueues().Any(q => q.JobQueue.Name == JobQueue.Name))
|
||||||
throw new ArgumentException("Another Job Queue already exists with that name", "JobQueue");
|
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
|
// Clone to break reference
|
||||||
var queue = new JobQueue()
|
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))
|
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");
|
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();
|
Database.SaveChanges();
|
||||||
|
|
||||||
return _cache.UpdateQueue(JobQueue);
|
return _cache.UpdateQueue(JobQueue);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user