fix: simplify document template managed groups
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
using Disco.Data.Repository;
|
using Disco.Data.Repository;
|
||||||
using Disco.Data.Repository.Monitor;
|
using Disco.Data.Repository.Monitor;
|
||||||
using Disco.Models.Repository;
|
using Disco.Models.Repository;
|
||||||
|
using Disco.Models.Services.Documents;
|
||||||
using Disco.Models.Services.Interop.ActiveDirectory;
|
using Disco.Models.Services.Interop.ActiveDirectory;
|
||||||
|
using Disco.Services.Expressions;
|
||||||
using Disco.Services.Interop.ActiveDirectory;
|
using Disco.Services.Interop.ActiveDirectory;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -157,128 +159,73 @@ namespace Disco.Services.Documents.ManagedGroups
|
|||||||
switch (DocumentTemplateScope)
|
switch (DocumentTemplateScope)
|
||||||
{
|
{
|
||||||
case DocumentTemplate.DocumentTemplateScopes.Device:
|
case DocumentTemplate.DocumentTemplateScopes.Device:
|
||||||
|
var deviceFilter = Database.DeviceAttachments.Include("Device").Where(a => a.DocumentTemplateId == DocumentTemplateId);
|
||||||
|
|
||||||
if (Configuration.FilterBeginDate.HasValue)
|
if (Configuration.FilterBeginDate.HasValue)
|
||||||
{
|
{
|
||||||
return Database.Devices
|
deviceFilter = deviceFilter.Where(a => a.Timestamp >= Configuration.FilterBeginDate);
|
||||||
.Where(d => d.DeviceDomainId != null && d.DeviceAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId && a.Timestamp >= Configuration.FilterBeginDate))
|
}
|
||||||
.Select(d => d.DeviceDomainId)
|
|
||||||
|
return deviceFilter.Select(a => a.Device.DeviceDomainId)
|
||||||
|
.Distinct()
|
||||||
.ToList()
|
.ToList()
|
||||||
.Where(ActiveDirectory.IsValidDomainAccountId)
|
.Where(ActiveDirectory.IsValidDomainAccountId)
|
||||||
.Select(id => id + "$");
|
.Select(id => id + "$");
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Database.Devices
|
|
||||||
.Where(d => d.DeviceDomainId != null && d.DeviceAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId))
|
|
||||||
.Select(d => d.DeviceDomainId)
|
|
||||||
.ToList()
|
|
||||||
.Where(ActiveDirectory.IsValidDomainAccountId)
|
|
||||||
.Select(id => id + "$");
|
|
||||||
}
|
|
||||||
case DocumentTemplate.DocumentTemplateScopes.Job:
|
case DocumentTemplate.DocumentTemplateScopes.Job:
|
||||||
|
var jobFilter = Database.JobAttachments.Include("Job.Device").Where(a => a.DocumentTemplateId == DocumentTemplateId && a.Job.Device.DeviceDomainId != null);
|
||||||
|
|
||||||
if (Configuration.FilterBeginDate.HasValue)
|
if (Configuration.FilterBeginDate.HasValue)
|
||||||
{
|
{
|
||||||
return Database.Jobs
|
jobFilter = jobFilter.Where(a => a.Timestamp >= Configuration.FilterBeginDate);
|
||||||
.Where(j => j.Device.DeviceDomainId != null && j.JobAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId && a.Timestamp >= Configuration.FilterBeginDate))
|
}
|
||||||
.Select(j => j.Device.DeviceDomainId)
|
|
||||||
|
return jobFilter.Select(a => a.Job.Device.DeviceDomainId)
|
||||||
.Distinct()
|
.Distinct()
|
||||||
.ToList()
|
.ToList()
|
||||||
.Where(ActiveDirectory.IsValidDomainAccountId)
|
.Where(ActiveDirectory.IsValidDomainAccountId)
|
||||||
.Select(id => id + "$");
|
.Select(id => id + "$");
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Database.Jobs
|
|
||||||
.Where(j => j.Device.DeviceDomainId != null && j.JobAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId))
|
|
||||||
.Select(j => j.Device.DeviceDomainId)
|
|
||||||
.Distinct()
|
|
||||||
.ToList()
|
|
||||||
.Where(ActiveDirectory.IsValidDomainAccountId)
|
|
||||||
.Select(id => id + "$");
|
|
||||||
}
|
|
||||||
case DocumentTemplate.DocumentTemplateScopes.User:
|
case DocumentTemplate.DocumentTemplateScopes.User:
|
||||||
|
var userFilter = Database.UserAttachments.Include("User.Device.DeviceUserAssignments.Device").Where(a => a.DocumentTemplateId == DocumentTemplateId && a.User.DeviceUserAssignments.Where(ua => ua.UnassignedDate == null && ua.Device.DeviceDomainId != null).Any());
|
||||||
|
|
||||||
if (Configuration.FilterBeginDate.HasValue)
|
if (Configuration.FilterBeginDate.HasValue)
|
||||||
{
|
{
|
||||||
return Database.Users
|
userFilter = userFilter.Where(a => a.Timestamp >= Configuration.FilterBeginDate);
|
||||||
.Where(u => u.UserAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId && a.Timestamp >= Configuration.FilterBeginDate))
|
}
|
||||||
.SelectMany(u => u.DeviceUserAssignments.Where(dua => !dua.UnassignedDate.HasValue && dua.Device.DeviceDomainId != null), (u, dua) => dua.Device.DeviceDomainId)
|
|
||||||
|
return userFilter.SelectMany(a => a.User.DeviceUserAssignments)
|
||||||
|
.Where(a => a.UnassignedDate == null)
|
||||||
|
.Select(a => a.Device.DeviceDomainId)
|
||||||
|
.Distinct()
|
||||||
.ToList()
|
.ToList()
|
||||||
.Where(ActiveDirectory.IsValidDomainAccountId)
|
.Where(ActiveDirectory.IsValidDomainAccountId)
|
||||||
.Select(id => id + "$");
|
.Select(id => id + "$");
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Database.Users
|
|
||||||
.Where(u => u.UserAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId))
|
|
||||||
.SelectMany(u => u.DeviceUserAssignments.Where(dua => !dua.UnassignedDate.HasValue && dua.Device.DeviceDomainId != null), (u, dua) => dua.Device.DeviceDomainId)
|
|
||||||
.ToList()
|
|
||||||
.Where(ActiveDirectory.IsValidDomainAccountId)
|
|
||||||
.Select(id => id + "$");
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return Enumerable.Empty<string>();
|
return Enumerable.Empty<string>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Device Scope
|
#region Device Scope
|
||||||
private class ContainsAttachmentResult
|
|
||||||
{
|
|
||||||
public string Id;
|
|
||||||
public bool HasAttachment;
|
|
||||||
public string SerialNumber;
|
|
||||||
public IEnumerable<ContainsAttachmentDeviceResult> Devices;
|
|
||||||
}
|
|
||||||
private class ContainsAttachmentDeviceResult
|
|
||||||
{
|
|
||||||
public string Id;
|
|
||||||
public string SerialNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool DeviceContainsAttachment(DiscoDataContext Database, string DeviceSerialNumber, out string DeviceAccountId)
|
private bool DeviceContainsAttachment(DiscoDataContext Database, string DeviceSerialNumber, out string DeviceAccountId)
|
||||||
{
|
{
|
||||||
ContainsAttachmentResult result;
|
var query = Database.DeviceAttachments.Include("Device")
|
||||||
|
.Where(a => a.DocumentTemplateId == DocumentTemplateId && a.DeviceSerialNumber == DeviceSerialNumber && a.Device.DeviceDomainId != null);
|
||||||
|
|
||||||
if (Configuration.FilterBeginDate.HasValue)
|
if (Configuration.FilterBeginDate.HasValue)
|
||||||
{
|
{
|
||||||
result = Database.Devices
|
query = query.Where(a => a.Timestamp >= Configuration.FilterBeginDate);
|
||||||
.Where(d => d.SerialNumber == DeviceSerialNumber && d.DeviceDomainId != null)
|
|
||||||
.Select(d => new ContainsAttachmentResult()
|
|
||||||
{
|
|
||||||
Id = d.DeviceDomainId,
|
|
||||||
HasAttachment = d.DeviceAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId && a.Timestamp >= Configuration.FilterBeginDate)
|
|
||||||
})
|
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = Database.Devices
|
|
||||||
.Where(d => d.SerialNumber == DeviceSerialNumber && d.DeviceDomainId != null)
|
|
||||||
.Select(d => new ContainsAttachmentResult()
|
|
||||||
{
|
|
||||||
Id = d.DeviceDomainId,
|
|
||||||
HasAttachment = d.DeviceAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId)
|
|
||||||
})
|
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == null)
|
var deviceDomainId = query.Select(a => a.Device.DeviceDomainId).FirstOrDefault();
|
||||||
|
if (ActiveDirectory.IsValidDomainAccountId(deviceDomainId))
|
||||||
|
{
|
||||||
|
DeviceAccountId = deviceDomainId + "$";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
DeviceAccountId = null;
|
DeviceAccountId = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if (ActiveDirectory.IsValidDomainAccountId(result.Id))
|
|
||||||
{
|
|
||||||
DeviceAccountId = result.Id + "$";
|
|
||||||
return result.HasAttachment;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DeviceAccountId = result.Id + "$";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessDeviceAttachmentAddEvent(RepositoryMonitorEvent e)
|
private void ProcessDeviceAttachmentAddEvent(RepositoryMonitorEvent e)
|
||||||
@@ -307,55 +254,27 @@ namespace Disco.Services.Documents.ManagedGroups
|
|||||||
#region Job Scope
|
#region Job Scope
|
||||||
private bool JobsContainAttachment(DiscoDataContext Database, int JobId, out string DeviceAccountId, out string DeviceSerialNumber)
|
private bool JobsContainAttachment(DiscoDataContext Database, int JobId, out string DeviceAccountId, out string DeviceSerialNumber)
|
||||||
{
|
{
|
||||||
ContainsAttachmentResult result;
|
var query = Database.JobAttachments.Include("Job.Device")
|
||||||
|
.Where(a => a.DocumentTemplateId == DocumentTemplateId && a.JobId == JobId && a.Job.Device.DeviceDomainId != null);
|
||||||
|
|
||||||
if (Configuration.FilterBeginDate.HasValue)
|
if (Configuration.FilterBeginDate.HasValue)
|
||||||
{
|
{
|
||||||
result = Database.Jobs
|
query = query.Where(a => a.Timestamp >= Configuration.FilterBeginDate);
|
||||||
.Where(j => j.Id == JobId && j.Device.DeviceDomainId != null)
|
}
|
||||||
.Select(j => new ContainsAttachmentResult()
|
|
||||||
|
var deviceRecord = query.Select(a => Tuple.Create(a.Job.DeviceSerialNumber, a.Job.Device.DeviceDomainId)).FirstOrDefault();
|
||||||
|
if (ActiveDirectory.IsValidDomainAccountId(deviceRecord.Item2))
|
||||||
{
|
{
|
||||||
Id = j.Device.DeviceDomainId,
|
DeviceSerialNumber = deviceRecord.Item1;
|
||||||
SerialNumber = j.Device.SerialNumber,
|
DeviceAccountId = deviceRecord.Item2 + "$";
|
||||||
HasAttachment = j.Device.Jobs.Any(dj => dj.JobAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId && a.Timestamp >= Configuration.FilterBeginDate))
|
return true;
|
||||||
})
|
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = Database.Jobs
|
|
||||||
.Where(j => j.Id == JobId && j.Device.DeviceDomainId != null)
|
|
||||||
.Select(j => new ContainsAttachmentResult()
|
|
||||||
{
|
|
||||||
Id = j.Device.DeviceDomainId,
|
|
||||||
SerialNumber = j.Device.SerialNumber,
|
|
||||||
HasAttachment = j.Device.Jobs.Any(dj => dj.JobAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId))
|
|
||||||
})
|
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (result == null)
|
|
||||||
{
|
|
||||||
DeviceAccountId = null;
|
|
||||||
DeviceSerialNumber = null;
|
DeviceSerialNumber = null;
|
||||||
|
DeviceAccountId = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if (ActiveDirectory.IsValidDomainAccountId(result.Id))
|
|
||||||
{
|
|
||||||
DeviceAccountId = result.Id + "$";
|
|
||||||
DeviceSerialNumber = result.SerialNumber;
|
|
||||||
return result.HasAttachment;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DeviceAccountId = result.Id + "$";
|
|
||||||
DeviceSerialNumber = result.SerialNumber;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessJobAttachmentAddEvent(RepositoryMonitorEvent e)
|
private void ProcessJobAttachmentAddEvent(RepositoryMonitorEvent e)
|
||||||
@@ -390,48 +309,28 @@ namespace Disco.Services.Documents.ManagedGroups
|
|||||||
#region User Scope
|
#region User Scope
|
||||||
private bool DeviceUserContainAttachment(DiscoDataContext Database, string UserId, out List<Tuple<string, string>> Devices)
|
private bool DeviceUserContainAttachment(DiscoDataContext Database, string UserId, out List<Tuple<string, string>> Devices)
|
||||||
{
|
{
|
||||||
ContainsAttachmentResult result;
|
var query = Database.UserAttachments.Include("User.DeviceUserAssignments.Device")
|
||||||
|
.Where(a => a.DocumentTemplateId == DocumentTemplateId && a.UserId == UserId && a.User.DeviceUserAssignments.Any(d => d.UnassignedDate == null && d.Device.DeviceDomainId != null));
|
||||||
|
|
||||||
if (Configuration.FilterBeginDate.HasValue)
|
if (Configuration.FilterBeginDate.HasValue)
|
||||||
{
|
{
|
||||||
result = Database.Users
|
query = query.Where(a => a.Timestamp >= Configuration.FilterBeginDate);
|
||||||
.Where(u => u.UserId == UserId)
|
|
||||||
.Select(u => new ContainsAttachmentResult()
|
|
||||||
{
|
|
||||||
HasAttachment = u.UserAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId && a.Timestamp >= Configuration.FilterBeginDate),
|
|
||||||
Devices = u.DeviceUserAssignments
|
|
||||||
.Where(dua => !dua.UnassignedDate.HasValue && dua.Device.DeviceDomainId != null)
|
|
||||||
.Select(dua => new ContainsAttachmentDeviceResult() { Id = dua.Device.DeviceDomainId, SerialNumber = dua.Device.SerialNumber })
|
|
||||||
})
|
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = Database.Users
|
|
||||||
.Where(u => u.UserId == UserId)
|
|
||||||
.Select(u => new ContainsAttachmentResult()
|
|
||||||
{
|
|
||||||
HasAttachment = u.UserAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId),
|
|
||||||
Devices = u.DeviceUserAssignments
|
|
||||||
.Where(dua => !dua.UnassignedDate.HasValue && dua.Device.DeviceDomainId != null)
|
|
||||||
.Select(dua => new ContainsAttachmentDeviceResult() { Id = dua.Device.DeviceDomainId, SerialNumber = dua.Device.SerialNumber })
|
|
||||||
})
|
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == null)
|
var deviceRecords = query.Take(1).SelectMany(a => a.User.DeviceUserAssignments)
|
||||||
|
.Where(a => a.UnassignedDate == null && a.Device.DeviceDomainId != null)
|
||||||
|
.Select(a => new { a.Device.SerialNumber, a.Device.DeviceDomainId }).ToList()
|
||||||
|
.Where(r => ActiveDirectory.IsValidDomainAccountId(r.DeviceDomainId)).ToList();
|
||||||
|
if (deviceRecords.Count > 0)
|
||||||
|
{
|
||||||
|
Devices = deviceRecords.Select(r => Tuple.Create(r.DeviceDomainId + "$", r.SerialNumber)).ToList();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Devices = null;
|
Devices = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Devices = result.Devices
|
|
||||||
.Where(d => ActiveDirectory.IsValidDomainAccountId(d.Id))
|
|
||||||
.Select(d => new Tuple<string, string>(d.Id + "$", d.SerialNumber))
|
|
||||||
.ToList();
|
|
||||||
return result.HasAttachment;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessUserAttachmentAddEvent(RepositoryMonitorEvent e)
|
private void ProcessUserAttachmentAddEvent(RepositoryMonitorEvent e)
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
using Disco.Data.Repository;
|
using Disco.Data.Repository;
|
||||||
using Disco.Data.Repository.Monitor;
|
using Disco.Data.Repository.Monitor;
|
||||||
using Disco.Models.Repository;
|
using Disco.Models.Repository;
|
||||||
|
using Disco.Models.Services.Documents;
|
||||||
using Disco.Models.Services.Interop.ActiveDirectory;
|
using Disco.Models.Services.Interop.ActiveDirectory;
|
||||||
|
using Disco.Services.Expressions;
|
||||||
using Disco.Services.Interop.ActiveDirectory;
|
using Disco.Services.Interop.ActiveDirectory;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -152,84 +154,54 @@ namespace Disco.Services.Documents.ManagedGroups
|
|||||||
switch (DocumentTemplateScope)
|
switch (DocumentTemplateScope)
|
||||||
{
|
{
|
||||||
case DocumentTemplate.DocumentTemplateScopes.Device:
|
case DocumentTemplate.DocumentTemplateScopes.Device:
|
||||||
|
var deviceFilter = Database.DeviceAttachments.Include("Device").Where(a => a.DocumentTemplateId == DocumentTemplateId && a.Device.AssignedUserId != null);
|
||||||
|
|
||||||
if (Configuration.FilterBeginDate.HasValue)
|
if (Configuration.FilterBeginDate.HasValue)
|
||||||
{
|
{
|
||||||
return Database.Devices
|
deviceFilter = deviceFilter.Where(a => a.Timestamp >= Configuration.FilterBeginDate);
|
||||||
.Where(d => d.AssignedUserId != null && d.DeviceAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId && a.Timestamp >= Configuration.FilterBeginDate))
|
|
||||||
.Select(d => d.AssignedUserId);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Database.Devices
|
|
||||||
.Where(d => d.AssignedUserId != null && d.DeviceAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId))
|
|
||||||
.Select(d => d.AssignedUserId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return deviceFilter.Select(a => a.Device.AssignedUserId).Distinct();
|
||||||
case DocumentTemplate.DocumentTemplateScopes.Job:
|
case DocumentTemplate.DocumentTemplateScopes.Job:
|
||||||
|
var jobFilter = Database.JobAttachments.Include("Job").Where(a => a.DocumentTemplateId == DocumentTemplateId && a.Job.UserId != null);
|
||||||
|
|
||||||
if (Configuration.FilterBeginDate.HasValue)
|
if (Configuration.FilterBeginDate.HasValue)
|
||||||
{
|
{
|
||||||
return Database.Jobs
|
jobFilter = jobFilter.Where(a => a.Timestamp >= Configuration.FilterBeginDate);
|
||||||
.Where(j => j.UserId != null && j.JobAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId && a.Timestamp >= Configuration.FilterBeginDate))
|
|
||||||
.Select(j => j.UserId)
|
|
||||||
.Distinct();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Database.Jobs
|
|
||||||
.Where(j => j.UserId != null && j.JobAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId))
|
|
||||||
.Select(j => j.UserId)
|
|
||||||
.Distinct();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return jobFilter.Select(a => a.Job.UserId).Distinct();
|
||||||
case DocumentTemplate.DocumentTemplateScopes.User:
|
case DocumentTemplate.DocumentTemplateScopes.User:
|
||||||
|
var userFilter = Database.UserAttachments.Include("User").Where(a => a.DocumentTemplateId == DocumentTemplateId && a.User.UserId != null);
|
||||||
|
|
||||||
if (Configuration.FilterBeginDate.HasValue)
|
if (Configuration.FilterBeginDate.HasValue)
|
||||||
{
|
{
|
||||||
return Database.Users
|
userFilter = userFilter.Where(a => a.Timestamp >= Configuration.FilterBeginDate);
|
||||||
.Where(u => u.UserAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId && a.Timestamp >= Configuration.FilterBeginDate))
|
|
||||||
.Select(u => u.UserId);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Database.Users
|
|
||||||
.Where(u => u.UserAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId))
|
|
||||||
.Select(u => u.UserId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return userFilter.Select(a => a.UserId).Distinct();
|
||||||
default:
|
default:
|
||||||
return Enumerable.Empty<string>();
|
return Enumerable.Empty<string>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Device Scope
|
#region Device Scope
|
||||||
private class ContainsAttachmentResult
|
|
||||||
{
|
|
||||||
public string Id;
|
|
||||||
public bool HasAttachment;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool DeviceContainsAttachment(DiscoDataContext Database, string DeviceSerialNumber, out string UserId)
|
private bool DeviceContainsAttachment(DiscoDataContext Database, string DeviceSerialNumber, out string UserId)
|
||||||
{
|
{
|
||||||
ContainsAttachmentResult result;
|
var query = Database.DeviceAttachments
|
||||||
|
.Include("Device")
|
||||||
|
.Where(da => da.DocumentTemplateId == DocumentTemplateId && da.DeviceSerialNumber == DeviceSerialNumber && da.Device.AssignedUserId != null);
|
||||||
|
|
||||||
if (Configuration.FilterBeginDate.HasValue)
|
if (Configuration.FilterBeginDate.HasValue)
|
||||||
{
|
{
|
||||||
result = Database.Devices
|
query = query.Where(da => da.Timestamp >= Configuration.FilterBeginDate);
|
||||||
.Where(d => d.SerialNumber == DeviceSerialNumber && d.AssignedUser != null)
|
|
||||||
.Select(d => new ContainsAttachmentResult()
|
|
||||||
{
|
|
||||||
Id = d.AssignedUserId,
|
|
||||||
HasAttachment = d.DeviceAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId && a.Timestamp >= Configuration.FilterBeginDate)
|
|
||||||
})
|
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
var result = query.Select(da => new
|
||||||
{
|
{
|
||||||
result = Database.Devices
|
da.Id,
|
||||||
.Where(d => d.SerialNumber == DeviceSerialNumber && d.AssignedUser != null)
|
da.Device.AssignedUserId,
|
||||||
.Select(d => new ContainsAttachmentResult()
|
}).FirstOrDefault();
|
||||||
{
|
|
||||||
Id = d.AssignedUserId,
|
|
||||||
HasAttachment = d.DeviceAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId)
|
|
||||||
})
|
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
@@ -238,8 +210,8 @@ namespace Disco.Services.Documents.ManagedGroups
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UserId = result.Id;
|
UserId = result.AssignedUserId;
|
||||||
return result.HasAttachment;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,30 +244,20 @@ namespace Disco.Services.Documents.ManagedGroups
|
|||||||
#region Job Scope
|
#region Job Scope
|
||||||
private bool JobsContainAttachment(DiscoDataContext Database, int JobId, out string UserId)
|
private bool JobsContainAttachment(DiscoDataContext Database, int JobId, out string UserId)
|
||||||
{
|
{
|
||||||
ContainsAttachmentResult result;
|
var query = Database.JobAttachments
|
||||||
|
.Include("Job")
|
||||||
|
.Where(da => da.DocumentTemplateId == DocumentTemplateId && da.JobId == JobId && da.Job.UserId != null);
|
||||||
|
|
||||||
if (Configuration.FilterBeginDate.HasValue)
|
if (Configuration.FilterBeginDate.HasValue)
|
||||||
{
|
{
|
||||||
result = Database.Jobs
|
query = query.Where(da => da.Timestamp >= Configuration.FilterBeginDate);
|
||||||
.Where(j => j.Id == JobId && j.UserId != null)
|
|
||||||
.Select(j => new ContainsAttachmentResult()
|
|
||||||
{
|
|
||||||
Id = j.UserId,
|
|
||||||
HasAttachment = j.User.Jobs.Any(uj => uj.JobAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId && a.Timestamp >= Configuration.FilterBeginDate))
|
|
||||||
})
|
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
var result = query.Select(da => new
|
||||||
{
|
{
|
||||||
result = Database.Jobs
|
da.Id,
|
||||||
.Where(j => j.Id == JobId && j.UserId != null)
|
da.Job.UserId,
|
||||||
.Select(j => new ContainsAttachmentResult()
|
}).FirstOrDefault();
|
||||||
{
|
|
||||||
Id = j.UserId,
|
|
||||||
HasAttachment = j.User.Jobs.Any(uj => uj.JobAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId))
|
|
||||||
})
|
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
@@ -304,8 +266,8 @@ namespace Disco.Services.Documents.ManagedGroups
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UserId = result.Id;
|
UserId = result.UserId;
|
||||||
return result.HasAttachment;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,18 +300,16 @@ namespace Disco.Services.Documents.ManagedGroups
|
|||||||
#region User Scope
|
#region User Scope
|
||||||
private bool UserContainAttachment(DiscoDataContext Database, string UserId)
|
private bool UserContainAttachment(DiscoDataContext Database, string UserId)
|
||||||
{
|
{
|
||||||
|
var query = Database.UserAttachments
|
||||||
|
.Include("User")
|
||||||
|
.Where(da => da.DocumentTemplateId == DocumentTemplateId && da.UserId == UserId);
|
||||||
|
|
||||||
if (Configuration.FilterBeginDate.HasValue)
|
if (Configuration.FilterBeginDate.HasValue)
|
||||||
{
|
{
|
||||||
return Database.Users
|
query = query.Where(da => da.Timestamp >= Configuration.FilterBeginDate);
|
||||||
.Where(u => u.UserId == UserId)
|
|
||||||
.Any(u => u.UserAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId && a.Timestamp >= Configuration.FilterBeginDate));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Database.Users
|
|
||||||
.Where(u => u.UserId == UserId)
|
|
||||||
.Any(u => u.UserAttachments.Any(a => a.DocumentTemplateId == DocumentTemplateId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return query.Any();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessUserAttachmentAddEvent(RepositoryMonitorEvent e)
|
private void ProcessUserAttachmentAddEvent(RepositoryMonitorEvent e)
|
||||||
@@ -380,19 +340,16 @@ namespace Disco.Services.Documents.ManagedGroups
|
|||||||
var deviceSerialNumber = device.SerialNumber;
|
var deviceSerialNumber = device.SerialNumber;
|
||||||
bool relevantDevice;
|
bool relevantDevice;
|
||||||
|
|
||||||
|
var query = Event.Database.DeviceAttachments.Include("Device")
|
||||||
|
.Where(da => da.DocumentTemplateId == DocumentTemplateId && da.DeviceSerialNumber == deviceSerialNumber);
|
||||||
|
|
||||||
if (Configuration.FilterBeginDate.HasValue)
|
if (Configuration.FilterBeginDate.HasValue)
|
||||||
{
|
{
|
||||||
relevantDevice = Event.Database.Devices
|
query = query.Where(da => da.Timestamp >= Configuration.FilterBeginDate);
|
||||||
.Where(d => d.SerialNumber == deviceSerialNumber && d.DeviceAttachments.Any(ja => ja.DocumentTemplateId == DocumentTemplateId && ja.Timestamp >= Configuration.FilterBeginDate))
|
|
||||||
.Any();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
relevantDevice = Event.Database.Devices
|
|
||||||
.Where(d => d.SerialNumber == deviceSerialNumber && d.DeviceAttachments.Any(ja => ja.DocumentTemplateId == DocumentTemplateId))
|
|
||||||
.Any();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
relevantDevice = query.Any();
|
||||||
|
|
||||||
if (relevantDevice)
|
if (relevantDevice)
|
||||||
{
|
{
|
||||||
var deviceCurrentAssignedUserId = device.AssignedUserId;
|
var deviceCurrentAssignedUserId = device.AssignedUserId;
|
||||||
|
|||||||
@@ -113,14 +113,14 @@ WriteLiteral(" <div");
|
|||||||
|
|
||||||
WriteLiteral(" class=\"code\"");
|
WriteLiteral(" class=\"code\"");
|
||||||
|
|
||||||
WriteAttribute("title", Tuple.Create(" title=\"", 681), Tuple.Create("\"", 698)
|
WriteAttribute("title", Tuple.Create(" title=\"", 693), Tuple.Create("\"", 710)
|
||||||
|
|
||||||
#line 22 "..\..\Areas\Config\Views\Shared\LinkedGroupInstance.cshtml"
|
#line 22 "..\..\Areas\Config\Views\Shared\LinkedGroupInstance.cshtml"
|
||||||
, Tuple.Create(Tuple.Create("", 689), Tuple.Create<System.Object, System.Int32>(group.Id
|
, Tuple.Create(Tuple.Create("", 701), Tuple.Create<System.Object, System.Int32>(group.Id
|
||||||
|
|
||||||
#line default
|
#line default
|
||||||
#line hidden
|
#line hidden
|
||||||
, 689), false)
|
, 701), false)
|
||||||
);
|
);
|
||||||
|
|
||||||
WriteLiteral(">\r\n <i");
|
WriteLiteral(">\r\n <i");
|
||||||
@@ -201,14 +201,14 @@ WriteLiteral(">Change Link</button>\r\n");
|
|||||||
|
|
||||||
WriteLiteral(" <a");
|
WriteLiteral(" <a");
|
||||||
|
|
||||||
WriteAttribute("href", Tuple.Create(" href=\"", 1275), Tuple.Create("\"", 1389)
|
WriteAttribute("href", Tuple.Create(" href=\"", 1335), Tuple.Create("\"", 1449)
|
||||||
|
|
||||||
#line 26 "..\..\Areas\Config\Views\Shared\LinkedGroupInstance.cshtml"
|
#line 26 "..\..\Areas\Config\Views\Shared\LinkedGroupInstance.cshtml"
|
||||||
, Tuple.Create(Tuple.Create("", 1282), Tuple.Create<System.Object, System.Int32>(Url.Action(MVC.API.System.SyncActiveDirectoryManagedGroup(Model.ManagedGroup.Key, Context.Request.Path))
|
, Tuple.Create(Tuple.Create("", 1342), Tuple.Create<System.Object, System.Int32>(Url.Action(MVC.API.System.SyncActiveDirectoryManagedGroup(Model.ManagedGroup.Key, Context.Request.Path))
|
||||||
|
|
||||||
#line default
|
#line default
|
||||||
#line hidden
|
#line hidden
|
||||||
, 1282), false)
|
, 1342), false)
|
||||||
);
|
);
|
||||||
|
|
||||||
WriteLiteral(" class=\"button small\"");
|
WriteLiteral(" class=\"button small\"");
|
||||||
@@ -245,7 +245,7 @@ WriteLiteral(">");
|
|||||||
|
|
||||||
#line default
|
#line default
|
||||||
#line hidden
|
#line hidden
|
||||||
WriteLiteral("</strong>\r\n </div> \r\n");
|
WriteLiteral("</strong>\r\n </div>\r\n");
|
||||||
|
|
||||||
WriteLiteral(" <button");
|
WriteLiteral(" <button");
|
||||||
|
|
||||||
@@ -377,14 +377,14 @@ WriteLiteral(" <div");
|
|||||||
|
|
||||||
WriteLiteral(" class=\"code\"");
|
WriteLiteral(" class=\"code\"");
|
||||||
|
|
||||||
WriteAttribute("title", Tuple.Create(" title=\"", 2661), Tuple.Create("\"", 2678)
|
WriteAttribute("title", Tuple.Create(" title=\"", 2777), Tuple.Create("\"", 2794)
|
||||||
|
|
||||||
#line 47 "..\..\Areas\Config\Views\Shared\LinkedGroupInstance.cshtml"
|
#line 47 "..\..\Areas\Config\Views\Shared\LinkedGroupInstance.cshtml"
|
||||||
, Tuple.Create(Tuple.Create("", 2669), Tuple.Create<System.Object, System.Int32>(group.Id
|
, Tuple.Create(Tuple.Create("", 2785), Tuple.Create<System.Object, System.Int32>(group.Id
|
||||||
|
|
||||||
#line default
|
#line default
|
||||||
#line hidden
|
#line hidden
|
||||||
, 2669), false)
|
, 2785), false)
|
||||||
);
|
);
|
||||||
|
|
||||||
WriteLiteral(">\r\n <i");
|
WriteLiteral(">\r\n <i");
|
||||||
@@ -432,7 +432,7 @@ WriteLiteral(">");
|
|||||||
|
|
||||||
#line default
|
#line default
|
||||||
#line hidden
|
#line hidden
|
||||||
WriteLiteral("</strong>\r\n </div> \r\n");
|
WriteLiteral("</strong>\r\n </div>\r\n");
|
||||||
|
|
||||||
|
|
||||||
#line 56 "..\..\Areas\Config\Views\Shared\LinkedGroupInstance.cshtml"
|
#line 56 "..\..\Areas\Config\Views\Shared\LinkedGroupInstance.cshtml"
|
||||||
|
|||||||
@@ -34,10 +34,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
$(function () {
|
$(function () {
|
||||||
var dialog;
|
let dialog;
|
||||||
var dialogGroupId;
|
let dialogGroupId;
|
||||||
var dialogFilterDate;
|
let dialogFilterDate;
|
||||||
var dialogTitle;
|
let dialogTitle;
|
||||||
|
|
||||||
function showDialog(groupId, filterDateOption, filterDateValue, updateUrl, title) {
|
function showDialog(groupId, filterDateOption, filterDateValue, updateUrl, title) {
|
||||||
if (dialog == null) {
|
if (dialog == null) {
|
||||||
|
|||||||
@@ -125,10 +125,10 @@ WriteLiteral(@"></i><strong>Warning:</strong> This group will be managed by Disc
|
|||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
$(function () {
|
$(function () {
|
||||||
var dialog;
|
let dialog;
|
||||||
var dialogGroupId;
|
let dialogGroupId;
|
||||||
var dialogFilterDate;
|
let dialogFilterDate;
|
||||||
var dialogTitle;
|
let dialogTitle;
|
||||||
|
|
||||||
function showDialog(groupId, filterDateOption, filterDateValue, updateUrl, title) {
|
function showDialog(groupId, filterDateOption, filterDateValue, updateUrl, title) {
|
||||||
if (dialog == null) {
|
if (dialog == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user