#138 device flag searching

This commit is contained in:
Gary Sharp
2024-01-14 17:56:20 +11:00
parent 7e07c07171
commit cd858c2215
2 changed files with 32 additions and 7 deletions
+8
View File
@@ -229,6 +229,14 @@ namespace Disco.Services.Searching
.ToUserSearchResultItems(null); .ToUserSearchResultItems(null);
} }
public static List<DeviceSearchResultItem> SearchDeviceFlag(DiscoDataContext Database, int deviceFlagId)
{
return Database.DeviceFlagAssignments
.Where(a => a.DeviceFlagId == deviceFlagId && !a.RemovedDate.HasValue)
.Select(a => a.Device)
.ToDeviceSearchResultItems(null);
}
private static List<UserSearchResultItem> ToUserSearchResultItems(this IQueryable<User> Query, int? LimitCount = ActiveDirectory.DefaultSearchResultLimit) private static List<UserSearchResultItem> ToUserSearchResultItems(this IQueryable<User> Query, int? LimitCount = ActiveDirectory.DefaultSearchResultLimit)
{ {
if (LimitCount.HasValue) if (LimitCount.HasValue)
+24 -7
View File
@@ -83,7 +83,7 @@ namespace Disco.Web.Controllers
var vm = Database.DeviceModels.Find(deviceModelId); var vm = Database.DeviceModels.Find(deviceModelId);
if (vm != null) if (vm != null)
{ {
m.FriendlyTerm = string.Format("Device Model: {0}", vm.ToString()); m.FriendlyTerm = $"Device Model: {vm.ToString()}";
m.Devices = Services.Searching.Search.SearchDeviceModel(Database, vm.Id); m.Devices = Services.Searching.Search.SearchDeviceModel(Database, vm.Id);
break; break;
} }
@@ -100,7 +100,7 @@ namespace Disco.Web.Controllers
var dp = Database.DeviceProfiles.Find(deviceProfileId); var dp = Database.DeviceProfiles.Find(deviceProfileId);
if (dp != null) if (dp != null)
{ {
m.FriendlyTerm = string.Format("Device Profile: {0}", dp.ToString()); m.FriendlyTerm = $"Device Profile: {dp.ToString()}";
m.Devices = Services.Searching.Search.SearchDeviceProfile(Database, dp.Id); m.Devices = Services.Searching.Search.SearchDeviceProfile(Database, dp.Id);
break; break;
} }
@@ -117,7 +117,7 @@ namespace Disco.Web.Controllers
var db = Database.DeviceBatches.Find(deviceBatchId); var db = Database.DeviceBatches.Find(deviceBatchId);
if (db != null) if (db != null)
{ {
m.FriendlyTerm = string.Format("Device Batch: {0}", db.ToString()); m.FriendlyTerm = $"Device Batch: {db.ToString()}";
m.Devices = Services.Searching.Search.SearchDeviceBatch(Database, db.Id); m.Devices = Services.Searching.Search.SearchDeviceBatch(Database, db.Id);
break; break;
} }
@@ -233,10 +233,10 @@ namespace Disco.Web.Controllers
} }
case "userflag": case "userflag":
Authorization.RequireAll(Claims.User.Search, Claims.User.ShowFlagAssignments); Authorization.RequireAll(Claims.User.Search, Claims.User.ShowFlagAssignments);
int flagId; int userFlagId;
if (int.TryParse(term, out flagId)) if (int.TryParse(term, out userFlagId))
{ {
var flag = Database.UserFlags.Find(flagId); var flag = Database.UserFlags.Find(userFlagId);
if (flag != null) if (flag != null)
{ {
m.FriendlyTerm = string.Format("User Flag: {0}", flag.ToString()); m.FriendlyTerm = string.Format("User Flag: {0}", flag.ToString());
@@ -244,10 +244,27 @@ namespace Disco.Web.Controllers
break; break;
} }
} }
m.FriendlyTerm = string.Format("User Flag: {0}", term); m.FriendlyTerm = $"User Flag: {term}";
m.Success = false; m.Success = false;
m.ErrorMessage = "Invalid User Flag Id"; m.ErrorMessage = "Invalid User Flag Id";
break; break;
case "deviceflag":
Authorization.RequireAll(Claims.Device.Search, Claims.Device.ShowFlagAssignments);
int deviceFlagId;
if (int.TryParse(term, out deviceFlagId))
{
var flag = Database.DeviceFlags.Find(deviceFlagId);
if (flag != null)
{
m.FriendlyTerm = string.Format("Device Flag: {0}", flag.ToString());
m.Devices = Services.Searching.Search.SearchDeviceFlag(Database, flag.Id);
break;
}
}
m.FriendlyTerm = $"Device Flag: {term}";
m.Success = false;
m.ErrorMessage = "Invalid Device Flag Id";
break;
} }
} }