remove device custom details

this plugin functionality has never been used
This commit is contained in:
Gary Sharp
2023-02-08 16:24:21 +11:00
parent 47e11c0fd6
commit 57a7f67c3a
19 changed files with 617 additions and 1054 deletions
@@ -130,8 +130,6 @@ namespace Disco.Models.Services.Devices.Exporting
public bool DetailBattery { get; set; }
[Display(ShortName = "Details", Name = "Keyboard", Description = "The Keyboard associated with the device")]
public bool DetailKeyboard { get; set; }
[Display(ShortName = "Details", Name = "Custom Details", Description = "Custom details provided by plugins")]
public bool DetailCustom { get; set; }
public static DeviceExportOptions DefaultOptions()
{
@@ -21,7 +21,6 @@ namespace Disco.Models.Services.Devices.Exporting
public List<string> DeviceDetailLanMacAddresses { get; set; }
public List<string> DeviceDetailWlanMacAddresses { get; set; }
public List<Battery> DeviceDetailBatteries { get; set; }
public Dictionary<string, string> DeviceDetailCustom { get; set; }
// Model
public int? ModelId { get; set; }
@@ -21,7 +21,6 @@ namespace Disco.Models.UI.Device
List<Repository.DocumentTemplate> DocumentTemplates { get; set; }
List<DocumentTemplatePackage> DocumentTemplatePackages { get; set; }
DetailsResult DeviceDetails { get; set; }
DetailsResult AssignedUserDetails { get; set; }
bool HasAssignedUserPhoto { get; set; }
}
-1
View File
@@ -20,6 +20,5 @@ namespace Disco.Models.UI.Job
List<JobLocationReference> LocationOptions { get; set; }
DetailsResult UserDetails { get; set; }
bool HasUserPhoto { get; set; }
DetailsResult DeviceDetails { get; set; }
}
}
-1
View File
@@ -20,6 +20,5 @@ namespace Disco.Models.UI.User
IClaimNavigatorItem ClaimNavigator { get; set; }
DetailsResult UserDetails { get; set; }
bool HasUserPhoto { get; set; }
Dictionary<string, DetailsResult> AssignedDevicesDetails { get; set; }
}
}
@@ -58,11 +58,11 @@ namespace Disco.Services.Devices.Exporting
if (Options.DetailBatteries)
r.DeviceDetailBatteries = r.DeviceDetails.Batteries();
var detailsService = new DetailsProviderService(Database);
if (Options.DetailCustom)
r.DeviceDetailCustom = detailsService.GetDetails(r.Device).Details;
if (Options.AssignedUserDetailCustom && r.AssignedUser != null)
{
var detailsService = new DetailsProviderService(Database);
r.AssignedUserCustomDetails = detailsService.GetDetails(r.AssignedUser).Details;
}
});
TaskStatus.UpdateStatus(40, "Building metadata and database query");
@@ -259,14 +259,11 @@ namespace Disco.Services.Devices.Exporting
var certificateMaxCount = Math.Max(1, records.Max(r => r.DeviceCertificates?.Count() ?? 0));
var batteriesMaxCount = Math.Max(1, records.Max(r => r.DeviceDetailBatteries?.Count ?? 0));
IEnumerable<string> deviceDetailCustomKeys = null;
IEnumerable<string> assignedUserDetailCustomKeys = null;
if (options.DetailCustom)
deviceDetailCustomKeys = records.Where(r => r.DeviceDetailCustom != null).SelectMany(r => r.DeviceDetailCustom.Keys).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
if (options.AssignedUserDetailCustom)
assignedUserDetailCustomKeys = records.Where(r => r.AssignedUserCustomDetails != null).SelectMany(r => r.AssignedUserCustomDetails.Keys).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
var allAssessors = BuildRecordAccessors(processorMaxCount, memoryMaxCount, diskDriveMaxCount, lanAdapterMaxCount, wlanAdapterMaxCount, certificateMaxCount, batteriesMaxCount, deviceDetailCustomKeys, assignedUserDetailCustomKeys);
var allAssessors = BuildRecordAccessors(processorMaxCount, memoryMaxCount, diskDriveMaxCount, lanAdapterMaxCount, wlanAdapterMaxCount, certificateMaxCount, batteriesMaxCount, assignedUserDetailCustomKeys);
return typeof(DeviceExportOptions).GetProperties()
.Where(p => p.PropertyType == typeof(bool))
@@ -288,7 +285,7 @@ namespace Disco.Services.Devices.Exporting
}).ToList();
}
private static Dictionary<string, List<DeviceExportFieldMetadata>> BuildRecordAccessors(int processorMaxCount, int memoryMaxCount, int diskDriveMaxCount, int lanAdapterMaxCount, int wlanAdapterMaxCount, int certificateMaxCount, int batteriesMaxCount, IEnumerable<string> deviceDetailCustomKeys, IEnumerable<string> assignedUserDetailCustomKeys)
private static Dictionary<string, List<DeviceExportFieldMetadata>> BuildRecordAccessors(int processorMaxCount, int memoryMaxCount, int diskDriveMaxCount, int lanAdapterMaxCount, int wlanAdapterMaxCount, int certificateMaxCount, int batteriesMaxCount, IEnumerable<string> assignedUserDetailCustomKeys)
{
const string DateFormat = "yyyy-MM-dd";
const string DateTimeFormat = DateFormat + " HH:mm:ss";
@@ -535,16 +532,6 @@ namespace Disco.Services.Devices.Exporting
}
metadata.Add(nameof(DeviceExportOptions.DetailBatteries), batteriesFields);
metadata.Add(nameof(DeviceExportOptions.DetailKeyboard), new List<DeviceExportFieldMetadata>() { new DeviceExportFieldMetadata(nameof(DeviceExportOptions.DetailKeyboard), typeof(string), r => r.DeviceDetails.Where(dd => dd.Key == DeviceDetail.HardwareKeyKeyboard).Select(dd => dd.Value).FirstOrDefault(), csvStringEncoded) });
if (deviceDetailCustomKeys != null)
{
var deviceDetailCustomFields = new List<DeviceExportFieldMetadata>();
foreach (var detailKey in deviceDetailCustomKeys.OrderBy(k => k, StringComparer.OrdinalIgnoreCase))
{
var key = detailKey;
deviceDetailCustomFields.Add(new DeviceExportFieldMetadata(detailKey, detailKey, typeof(string), r => r.DeviceDetailCustom != null && r.DeviceDetailCustom.TryGetValue(key, out var value) ? value : null, csvStringEncoded));
}
metadata.Add(nameof(DeviceExportOptions.DetailCustom), deviceDetailCustomFields);
}
return metadata;
}
-13
View File
@@ -209,16 +209,13 @@ namespace Disco.Services.Expressions
if (target is User targetUser)
{
detailsVariables.Add("UserDetails", new LazyDictionary(() => detailsService.GetDetails(targetUser).Details));
detailsVariables.Add("AssignedDeviceDetails", targetUser.CurrentDeviceUserAssignments().Select(a => new { a.Device, Details = new LazyDictionary(() => detailsService.GetDetails(targetUser).Details) }).ToDictionary(d => d.Device.SerialNumber, d => d.Details, StringComparer.OrdinalIgnoreCase));
}
else if (target is Job targetJob)
{
detailsVariables.Add("UserDetails", targetJob.User == null ? (IDictionary<string, string>)new Dictionary<string, string>() : new LazyDictionary(() => detailsService.GetDetails(targetJob.User).Details));
detailsVariables.Add("DeviceDetails", targetJob.Device == null ? (IDictionary<string, string>)new Dictionary<string, string>() : new LazyDictionary(() => detailsService.GetDetails(targetJob.Device).Details));
}
else if (target is Device targetDevice)
{
detailsVariables.Add("DeviceDetails", new LazyDictionary(() => detailsService.GetDetails(targetDevice).Details));
detailsVariables.Add("UserDetails", targetDevice.AssignedUser == null ? (IDictionary<string, string>)new Dictionary<string, string>() : new LazyDictionary(() => detailsService.GetDetails(targetDevice.AssignedUser).Details));
}
}
@@ -285,16 +282,6 @@ namespace Disco.Services.Expressions
"#UserDetails",
typeof(Dictionary<string, string>).AssemblyQualifiedName
},
{
"#DeviceDetails",
typeof(Dictionary<string, string>).AssemblyQualifiedName
},
{
"#AssignedDeviceDetails",
typeof(Dictionary<string, Dictionary<string, string>>).AssemblyQualifiedName
},
};
}
public static Dictionary<string, string> ExtensionLibraryTypes()
@@ -1,9 +1,7 @@
using Disco.Data.Repository;
using Disco.Models.Services.Plugins.Details;
using Disco.Models.UI.Device;
using Disco.Models.UI.Job;
using Disco.Models.UI.User;
using System.Collections.Generic;
namespace Disco.Services.Plugins.Features.DetailsProvider
{
@@ -16,27 +14,13 @@ namespace Disco.Services.Plugins.Features.DetailsProvider
model.UserDetails = service.GetDetails(model.User);
model.HasUserPhoto = service.HasUserPhoto(model.User);
var currentAssignments = model.User.CurrentDeviceUserAssignments();
if (currentAssignments.Count > 0)
{
model.AssignedDevicesDetails = new Dictionary<string, DetailsResult>(currentAssignments.Count);
foreach (var device in currentAssignments)
{
model.AssignedDevicesDetails[device.DeviceSerialNumber] = service.GetDetails(device.Device);
}
}
}
public static void PopulateDetails(this DeviceShowModel model, DiscoDataContext database)
{
var service = new DetailsProviderService(database);
model.DeviceDetails = service.GetDetails(model.Device);
if (model.Device.AssignedUser != null)
{
var service = new DetailsProviderService(database);
model.AssignedUserDetails = service.GetDetails(model.Device.AssignedUser);
model.HasAssignedUserPhoto = service.HasUserPhoto(model.Device.AssignedUser);
}
@@ -44,13 +28,9 @@ namespace Disco.Services.Plugins.Features.DetailsProvider
public static void PopulateDetails(this JobShowModel model, DiscoDataContext database)
{
var service = new DetailsProviderService(database);
if (model.Job.Device != null)
model.DeviceDetails = service.GetDetails(model.Job.Device);
if (model.Job.User != null)
{
var service = new DetailsProviderService(database);
model.UserDetails = service.GetDetails(model.Job.User);
model.HasUserPhoto = service.HasUserPhoto(model.Job.User);
}
@@ -9,6 +9,7 @@ namespace Disco.Services.Plugins.Features.DetailsProvider
public abstract class DetailsProviderFeature : PluginFeature
{
public abstract DetailsResult GetDetails(DiscoDataContext database, User user, DateTime? cacheTimestamp);
[Obsolete("Never used")]
public abstract DetailsResult GetDetails(DiscoDataContext database, Device device, DateTime? cacheTimestamp);
public abstract byte[] GetUserPhoto(DiscoDataContext database, User user, DateTime? cacheTimestamp);
}
@@ -158,78 +158,5 @@ namespace Disco.Services.Plugins.Features.DetailsProvider
return result;
}
public DetailsResult GetDetails(Device device)
{
var result = new DetailsResult();
var saveChangesRequired = false;
if (!UserService.CurrentAuthorization.HasAll(Claims.Device.Show, Claims.Device.ShowDetails))
return result;
var features = Plugins.GetPluginFeatures(typeof(DetailsProviderFeature));
if (features.Count == 0)
return result;
var cache = device.DeviceDetails?.Where(d => d.Scope == DetailsScope).ToDictionary(d => d.Key, d => new { DbDetails = d, Details = JsonConvert.DeserializeObject<DetailsResult>(d.Value) }, StringComparer.OrdinalIgnoreCase);
foreach (var feature in features)
{
var featureResult = default(DetailsResult);
if (!cache.TryGetValue(feature.Id, out var cacheResult) || cacheResult.Details.ExpiresOn < DateTime.Now || cacheResult.Details.GatheredOn < database.DiscoConfiguration.PluginDetailsCacheExpiration)
{
var timestamp = cacheResult?.Details.GatheredOn;
if (timestamp.HasValue && timestamp.Value < database.DiscoConfiguration.PluginDetailsCacheExpiration)
timestamp = null;
try
{
var featureInstance = feature.CreateInstance<DetailsProviderFeature>();
featureResult = featureInstance.GetDetails(database, device, timestamp);
if (featureResult != null)
{
if (featureResult.ExpiresOn > DateTime.Now)
{
if (cacheResult == null)
database.DeviceDetails.Add(new DeviceDetail() { DeviceSerialNumber = device.SerialNumber, Scope = DetailsScope, Key = feature.Id, Value = JsonConvert.SerializeObject(featureResult) });
else
cacheResult.DbDetails.Value = JsonConvert.SerializeObject(featureResult);
saveChangesRequired = true;
}
else if (cacheResult != null)
{
database.DeviceDetails.Remove(cacheResult.DbDetails);
saveChangesRequired = true;
}
}
}
catch (Exception)
{
// ignore exceptions when plugins behave badly
}
}
else
{
featureResult = cacheResult.Details;
}
// apply feature results
if (featureResult != null)
{
result.SetExpiration(featureResult.ExpiresOn);
foreach (var value in featureResult.Details)
{
result.Details[value.Key] = value.Value;
}
}
}
if (saveChangesRequired)
database.SaveChanges();
return result;
}
}
}
-1
View File
@@ -35,7 +35,6 @@ namespace Disco.Web.Models.Device
HandlersPresent = Plugins.GetPluginFeatures(typeof(DocumentHandlerProviderFeature)).Any(),
};
public DetailsResult DeviceDetails { get; set; }
public DetailsResult AssignedUserDetails { get; set; }
public bool HasAssignedUserPhoto { get; set; }
}
-1
View File
@@ -36,6 +36,5 @@ namespace Disco.Web.Models.Job
public DetailsResult UserDetails { get; set; }
public bool HasUserPhoto { get; set; }
public DetailsResult DeviceDetails { get; set; }
}
}
-1
View File
@@ -33,7 +33,6 @@ namespace Disco.Web.Models.User
public DetailsResult UserDetails { get; set; }
public bool HasUserPhoto { get; set; }
public Dictionary<string, DetailsResult> AssignedDevicesDetails { get; set; }
public FancyTreeNode[] ClaimNavigatorFancyTreeNodes
{
@@ -187,37 +187,6 @@
</tr>
</table>
</div>
@if (Model.DeviceDetails != null && Model.DeviceDetails.Details.Count(d => !d.Key.EndsWith("&")) > 0)
{
<div id="Device_Show_CustomDetails" class="status clearfix">
@foreach (var detail in Model.DeviceDetails.Details.Where(d => !d.Key.EndsWith("&")))
{
<div>
<strong>@detail.Key.TrimEnd('*'):</strong>
@if (detail.Key.EndsWith("*"))
{
<a href="" class="reveal smallMessage">[reveal]</a>
<span class="reveal hidden">@Html.Partial(MVC.Shared.Views._CustomDetailValueRender, detail)</span>
}
else
{
@Html.Partial(MVC.Shared.Views._CustomDetailValueRender, detail)
}
</div>
}
<script type="text/javascript">
$(() => {
$('#Device_Show_CustomDetails').on('click', 'a.reveal', e => {
e.preventDefault();
const t = $(e.currentTarget);
t.next('span.reveal').removeClass('hidden');
t.remove();
return false;
})
});
</script>
</div>
}
<div class="status">
@{
var assignedUser = Model.Device.AssignedUser;
File diff suppressed because it is too large Load Diff
@@ -254,17 +254,6 @@
}
}
</div>
@if (Model.DeviceDetails != null && Model.DeviceDetails.Details.Count > 0)
{
<div id="Job_Show_Device_CustomDetails" class="status clearfix">
@foreach (var detail in Model.DeviceDetails.Details)
{
<div>
<strong>@detail.Key:</strong> @Html.Partial(MVC.Shared.Views._CustomDetailValueRender, detail)
</div>
}
</div>
}
@if (Model.Job.DeviceHeld.HasValue)
{
var canEditLocation = Authorization.Has(Claims.Job.Properties.DeviceHeldLocation);
File diff suppressed because it is too large Load Diff
@@ -3,7 +3,6 @@
Authorization.Require(Claims.User.Show);
var currentDeviceAssignments = Model.User.DeviceUserAssignments.Where(dua => !dua.UnassignedDate.HasValue).OrderByDescending(dua => dua.AssignedDate).ToList();
Disco.Models.Services.Plugins.Details.DetailsResult deviceDetails;
}
<table id="User_Show_Subjects">
<tbody>
@@ -419,16 +418,6 @@
<span class="User_Show_AssignedDevices_CurrentAssignment_Assigned">@CommonHelpers.FriendlyDate(assignment.AssignedDate)</span>
</td>
</tr>
@if (Model.AssignedDevicesDetails != null && Model.AssignedDevicesDetails.TryGetValue(assignment.DeviceSerialNumber, out deviceDetails) && deviceDetails.Details.Count > 0)
{
foreach (var detail in deviceDetails.Details)
{
<tr>
<td>@detail.Key:</td>
<td>@Html.Partial(MVC.Shared.Views._CustomDetailValueRender, detail)</td>
</tr>
}
}
</tbody>
</table>
</div>
File diff suppressed because it is too large Load Diff