From 50399f4f483716e5dc37c7594c9106e23f4cdd4d Mon Sep 17 00:00:00 2001 From: Gary Sharp Date: Mon, 2 Feb 2015 19:23:27 +1100 Subject: [PATCH] Bug Fix #82: Dereference managed groups on delete Managed Group references (and subscriptions) continued to exist after Device Profiles, Device Batches and Document Templates were deleted. This prevented assigning the same group to another Profile/Batch/Template without first recycling the IIS App Pool. --- .../BI/Extensions/DeviceBatchExtensions.cs | 16 +++++++++------ .../BI/Extensions/DeviceProfileExtensions.cs | 19 ++++++++++-------- .../Extensions/DocumentTemplateExtensions.cs | 20 +++++++++++-------- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/Disco.BI/BI/Extensions/DeviceBatchExtensions.cs b/Disco.BI/BI/Extensions/DeviceBatchExtensions.cs index 2fe39a4f..7634b28c 100644 --- a/Disco.BI/BI/Extensions/DeviceBatchExtensions.cs +++ b/Disco.BI/BI/Extensions/DeviceBatchExtensions.cs @@ -1,11 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using Disco.Data.Repository; using Disco.Models.Repository; -using Disco.Data.Repository; -using Disco.Services.Users; using Disco.Services.Authorization; +using Disco.Services.Devices.ManagedGroups; +using Disco.Services.Interop.ActiveDirectory; +using Disco.Services.Users; +using System; +using System.Linq; namespace Disco.BI.Extensions { @@ -29,6 +29,10 @@ namespace Disco.BI.Extensions if (!db.CanDelete(Database)) throw new InvalidOperationException("The state of this Device Batch doesn't allow it to be deleted"); + // Remove Linked Group + ActiveDirectory.Context.ManagedGroups.Remove(DeviceBatchDevicesManagedGroup.GetKey(db)); + ActiveDirectory.Context.ManagedGroups.Remove(DeviceBatchAssignedUsersManagedGroup.GetKey(db)); + // Delete Batch Database.DeviceBatches.Remove(db); } diff --git a/Disco.BI/BI/Extensions/DeviceProfileExtensions.cs b/Disco.BI/BI/Extensions/DeviceProfileExtensions.cs index c339317c..d9ae1454 100644 --- a/Disco.BI/BI/Extensions/DeviceProfileExtensions.cs +++ b/Disco.BI/BI/Extensions/DeviceProfileExtensions.cs @@ -1,13 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Disco.Models.Repository; -using Disco.Data.Repository; -using Disco.Data.Configuration.Modules; +using Disco.Data.Repository; using Disco.Models.BI.Config; -using Disco.Services.Users; +using Disco.Models.Repository; using Disco.Services.Authorization; +using Disco.Services.Devices.ManagedGroups; +using Disco.Services.Interop.ActiveDirectory; +using Disco.Services.Users; +using System; +using System.Linq; namespace Disco.BI.Extensions { @@ -58,6 +57,10 @@ namespace Disco.BI.Extensions if (Database.DiscoConfiguration.DeviceProfiles.DefaultAddDeviceOfflineDeviceProfileId == dp.Id) Database.DiscoConfiguration.DeviceProfiles.DefaultAddDeviceOfflineDeviceProfileId = 1; + // Remove Linked Group + ActiveDirectory.Context.ManagedGroups.Remove(DeviceProfileDevicesManagedGroup.GetKey(dp)); + ActiveDirectory.Context.ManagedGroups.Remove(DeviceProfileAssignedUsersManagedGroup.GetKey(dp)); + // Delete Profile Database.DeviceProfiles.Remove(dp); } diff --git a/Disco.BI/BI/Extensions/DocumentTemplateExtensions.cs b/Disco.BI/BI/Extensions/DocumentTemplateExtensions.cs index 62baa538..ffc07aaa 100644 --- a/Disco.BI/BI/Extensions/DocumentTemplateExtensions.cs +++ b/Disco.BI/BI/Extensions/DocumentTemplateExtensions.cs @@ -1,17 +1,17 @@ -using System; -using System.Collections.Concurrent; -using System.Linq; -using System.Web; +using Disco.BI.DocumentTemplateBI; +using Disco.BI.DocumentTemplateBI.ManagedGroups; +using Disco.BI.Expressions; using Disco.Data.Repository; using Disco.Models.BI.DocumentTemplates; using Disco.Models.Repository; -using System.Collections; -using System.Collections.Generic; +using Disco.Services.Interop.ActiveDirectory; using iTextSharp.text.pdf; -using Disco.BI.Expressions; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; using System.Drawing; using System.IO; -using Disco.BI.DocumentTemplateBI; +using System.Linq; namespace Disco.BI.Extensions { @@ -273,6 +273,10 @@ namespace Disco.BI.Extensions a.DocumentTemplate = null; } + // Remove Linked Group + ActiveDirectory.Context.ManagedGroups.Remove(DocumentTemplateDevicesManagedGroup.GetKey(dt)); + ActiveDirectory.Context.ManagedGroups.Remove(DocumentTemplateUsersManagedGroup.GetKey(dt)); + // Delete SubTypes dt.JobSubTypes.Clear();