Bug Fix #97 - Removed Organisation Address References
Remove Device Profile references to an address when its removed, and anticipate missing addresses where referenced.
This commit is contained in:
@@ -16,7 +16,7 @@ namespace Disco.Data.Configuration.Modules
|
|||||||
|
|
||||||
public OrganisationAddress GetAddress(int Id)
|
public OrganisationAddress GetAddress(int Id)
|
||||||
{
|
{
|
||||||
return this.Get<OrganisationAddress>(null, Id.ToString());
|
return Get<OrganisationAddress>(null, Id.ToString());
|
||||||
}
|
}
|
||||||
public OrganisationAddress SetAddress(OrganisationAddress Address)
|
public OrganisationAddress SetAddress(OrganisationAddress Address)
|
||||||
{
|
{
|
||||||
@@ -25,21 +25,21 @@ namespace Disco.Data.Configuration.Modules
|
|||||||
Address.Id = NextOrganisationAddressId;
|
Address.Id = NextOrganisationAddressId;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Set(Address, Address.Id.ToString());
|
Set(Address, Address.Id.ToString());
|
||||||
|
|
||||||
return Address;
|
return Address;
|
||||||
}
|
}
|
||||||
public void RemoveAddress(int Id)
|
public void RemoveAddress(int Id)
|
||||||
{
|
{
|
||||||
// Remove Configuration Item
|
// Remove Configuration Item
|
||||||
this.RemoveItem(Id.ToString());
|
RemoveItem(Id.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrganisationAddress> Addresses
|
public List<OrganisationAddress> Addresses
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return this.ItemKeys.Select(key => this.Get<OrganisationAddress>(null, key)).ToList();
|
return ItemKeys.Select(key => Get<OrganisationAddress>(null, key)).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ namespace Disco.Data.Configuration.Modules
|
|||||||
int nextId = 0;
|
int nextId = 0;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (this.Get<string>(null, nextId.ToString()) == null)
|
if (Get<string>(null, nextId.ToString()) == null)
|
||||||
break;
|
break;
|
||||||
nextId++;
|
nextId++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ namespace Disco.Services
|
|||||||
j.OpenedTechUserFriendlyId = ActiveDirectory.FriendlyAccountId(j.OpenedTechUserId);
|
j.OpenedTechUserFriendlyId = ActiveDirectory.FriendlyAccountId(j.OpenedTechUserId);
|
||||||
|
|
||||||
if (j.DeviceAddressId.HasValue)
|
if (j.DeviceAddressId.HasValue)
|
||||||
j.DeviceAddress = Database.DiscoConfiguration.OrganisationAddresses.GetAddress(j.DeviceAddressId.Value).Name;
|
j.DeviceAddress = Database.DiscoConfiguration.OrganisationAddresses.GetAddress(j.DeviceAddressId.Value)?.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
|
|||||||
@@ -53,9 +53,7 @@ namespace Disco.Services.Jobs.Noticeboards
|
|||||||
if (DeviceAddressId.HasValue)
|
if (DeviceAddressId.HasValue)
|
||||||
{
|
{
|
||||||
var config = new OrganisationAddressesConfiguration(null);
|
var config = new OrganisationAddressesConfiguration(null);
|
||||||
var address = config.GetAddress(DeviceAddressId.Value);
|
return config.GetAddress(DeviceAddressId.Value)?.ShortName;
|
||||||
if (address != null)
|
|
||||||
return address.ShortName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ namespace Disco.Web.Areas.API.Controllers
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Update Properties
|
#region Update Properties
|
||||||
private void UpdateDescription(Disco.Models.Repository.DeviceProfile deviceProfile, string Description)
|
private void UpdateDescription(DeviceProfile deviceProfile, string Description)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(Description))
|
if (string.IsNullOrWhiteSpace(Description))
|
||||||
deviceProfile.Description = null;
|
deviceProfile.Description = null;
|
||||||
@@ -294,7 +294,7 @@ namespace Disco.Web.Areas.API.Controllers
|
|||||||
Database.SaveChanges();
|
Database.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateName(Disco.Models.Repository.DeviceProfile deviceProfile, string Name)
|
private void UpdateName(DeviceProfile deviceProfile, string Name)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(Name))
|
if (string.IsNullOrWhiteSpace(Name))
|
||||||
throw new Exception("Profile name cannot be empty");
|
throw new Exception("Profile name cannot be empty");
|
||||||
@@ -303,7 +303,7 @@ namespace Disco.Web.Areas.API.Controllers
|
|||||||
Database.SaveChanges();
|
Database.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateShortName(Disco.Models.Repository.DeviceProfile deviceProfile, string ShortName)
|
private void UpdateShortName(DeviceProfile deviceProfile, string ShortName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(ShortName))
|
if (string.IsNullOrWhiteSpace(ShortName))
|
||||||
throw new Exception("Profile short name cannot be empty");
|
throw new Exception("Profile short name cannot be empty");
|
||||||
@@ -312,12 +312,12 @@ namespace Disco.Web.Areas.API.Controllers
|
|||||||
Database.SaveChanges();
|
Database.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateDistributionType(Disco.Models.Repository.DeviceProfile deviceProfile, string DistributionType)
|
private void UpdateDistributionType(DeviceProfile deviceProfile, string DistributionType)
|
||||||
{
|
{
|
||||||
int iDt;
|
int iDt;
|
||||||
if (int.TryParse(DistributionType, out iDt))
|
if (int.TryParse(DistributionType, out iDt))
|
||||||
{
|
{
|
||||||
deviceProfile.DistributionType = (Disco.Models.Repository.DeviceProfile.DistributionTypes)iDt;
|
deviceProfile.DistributionType = (DeviceProfile.DistributionTypes)iDt;
|
||||||
Database.SaveChanges();
|
Database.SaveChanges();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -432,7 +432,7 @@ namespace Disco.Web.Areas.API.Controllers
|
|||||||
Database.SaveChanges();
|
Database.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateOrganisationalUnit(Disco.Models.Repository.DeviceProfile deviceProfile, string OrganisationalUnit)
|
private void UpdateOrganisationalUnit(DeviceProfile deviceProfile, string OrganisationalUnit)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(OrganisationalUnit))
|
if (string.IsNullOrWhiteSpace(OrganisationalUnit))
|
||||||
OrganisationalUnit = ActiveDirectory.Context.PrimaryDomain.DefaultComputerContainer;
|
OrganisationalUnit = ActiveDirectory.Context.PrimaryDomain.DefaultComputerContainer;
|
||||||
@@ -444,7 +444,7 @@ namespace Disco.Web.Areas.API.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateComputerNameTemplate(Disco.Models.Repository.DeviceProfile deviceProfile, string ComputerNameTemplate)
|
private void UpdateComputerNameTemplate(DeviceProfile deviceProfile, string ComputerNameTemplate)
|
||||||
{
|
{
|
||||||
Authorization.Require(Claims.Config.DeviceProfile.ConfigureComputerNameTemplate);
|
Authorization.Require(Claims.Config.DeviceProfile.ConfigureComputerNameTemplate);
|
||||||
|
|
||||||
@@ -458,7 +458,7 @@ namespace Disco.Web.Areas.API.Controllers
|
|||||||
deviceProfile.ComputerNameInvalidateCache();
|
deviceProfile.ComputerNameInvalidateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateDefaultOrganisationAddress(Disco.Models.Repository.DeviceProfile deviceProfile, string DefaultOrganisationAddress)
|
private void UpdateDefaultOrganisationAddress(DeviceProfile deviceProfile, string DefaultOrganisationAddress)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(DefaultOrganisationAddress))
|
if (string.IsNullOrEmpty(DefaultOrganisationAddress))
|
||||||
{
|
{
|
||||||
@@ -490,7 +490,7 @@ namespace Disco.Web.Areas.API.Controllers
|
|||||||
Database.SaveChanges();
|
Database.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateEnforceComputerNameConvention(Disco.Models.Repository.DeviceProfile deviceProfile, string EnforceComputerNameConvention)
|
private void UpdateEnforceComputerNameConvention(DeviceProfile deviceProfile, string EnforceComputerNameConvention)
|
||||||
{
|
{
|
||||||
bool bValue;
|
bool bValue;
|
||||||
if (bool.TryParse(EnforceComputerNameConvention, out bValue))
|
if (bool.TryParse(EnforceComputerNameConvention, out bValue))
|
||||||
@@ -503,7 +503,7 @@ namespace Disco.Web.Areas.API.Controllers
|
|||||||
throw new Exception("Invalid Boolean Value");
|
throw new Exception("Invalid Boolean Value");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateEnforceOrganisationalUnit(Disco.Models.Repository.DeviceProfile deviceProfile, string EnforceOrganisationalUnit)
|
private void UpdateEnforceOrganisationalUnit(DeviceProfile deviceProfile, string EnforceOrganisationalUnit)
|
||||||
{
|
{
|
||||||
bool bValue;
|
bool bValue;
|
||||||
if (bool.TryParse(EnforceOrganisationalUnit, out bValue))
|
if (bool.TryParse(EnforceOrganisationalUnit, out bValue))
|
||||||
@@ -516,7 +516,7 @@ namespace Disco.Web.Areas.API.Controllers
|
|||||||
throw new Exception("Invalid Boolean Value");
|
throw new Exception("Invalid Boolean Value");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateProvisionADAccount(Disco.Models.Repository.DeviceProfile deviceProfile, string ProvisionADAccount)
|
private void UpdateProvisionADAccount(DeviceProfile deviceProfile, string ProvisionADAccount)
|
||||||
{
|
{
|
||||||
bool bValue;
|
bool bValue;
|
||||||
if (bool.TryParse(ProvisionADAccount, out bValue))
|
if (bool.TryParse(ProvisionADAccount, out bValue))
|
||||||
|
|||||||
@@ -167,6 +167,11 @@ namespace Disco.Web.Areas.API.Controllers
|
|||||||
[DiscoAuthorize(Claims.Config.Organisation.ConfigureAddresses)]
|
[DiscoAuthorize(Claims.Config.Organisation.ConfigureAddresses)]
|
||||||
public virtual ActionResult DeleteOrganisationAddress(int Id, bool redirect = false)
|
public virtual ActionResult DeleteOrganisationAddress(int Id, bool redirect = false)
|
||||||
{
|
{
|
||||||
|
// Remove References in Device Profiles
|
||||||
|
Database.DeviceProfiles
|
||||||
|
.Where(dp => dp.DefaultOrganisationAddress == Id).ToList()
|
||||||
|
.ForEach(dp => dp.DefaultOrganisationAddress = null);
|
||||||
|
|
||||||
Database.DiscoConfiguration.OrganisationAddresses.RemoveAddress(Id);
|
Database.DiscoConfiguration.OrganisationAddresses.RemoveAddress(Id);
|
||||||
Database.SaveChanges();
|
Database.SaveChanges();
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,12 @@ namespace Disco.Web.Areas.Config.Models.DeviceProfile
|
|||||||
if (DiscoApplication.MultiSiteMode)
|
if (DiscoApplication.MultiSiteMode)
|
||||||
{
|
{
|
||||||
foreach (var dp in m.DeviceProfiles)
|
foreach (var dp in m.DeviceProfiles)
|
||||||
|
{
|
||||||
if (dp.Address.HasValue)
|
if (dp.Address.HasValue)
|
||||||
dp.AddressName = Database.DiscoConfiguration.OrganisationAddresses.GetAddress(dp.Address.Value).Name;
|
{
|
||||||
|
dp.AddressName = Database.DiscoConfiguration.OrganisationAddresses.GetAddress(dp.Address.Value)?.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace Disco.Web.Areas.Public.Models.UserHeldDevices
|
|||||||
ReadyForReturn = this.ReadyForReturn,
|
ReadyForReturn = this.ReadyForReturn,
|
||||||
WaitingForUserAction = this.WaitingForUserAction,
|
WaitingForUserAction = this.WaitingForUserAction,
|
||||||
DeviceProfileId = this.DeviceProfileId,
|
DeviceProfileId = this.DeviceProfileId,
|
||||||
DeviceAddress = (this.DeviceAddressId.HasValue ? Database.DiscoConfiguration.OrganisationAddresses.GetAddress(this.DeviceAddressId.Value).ShortName : string.Empty)
|
DeviceAddress = (this.DeviceAddressId.HasValue ? Database.DiscoConfiguration.OrganisationAddresses.GetAddress(this.DeviceAddressId.Value)?.ShortName : string.Empty)
|
||||||
};
|
};
|
||||||
var n = DateTime.Now;
|
var n = DateTime.Now;
|
||||||
if (!this.ReadyForReturn && this.EstimatedReturnTime.HasValue && this.EstimatedReturnTime.Value > n)
|
if (!this.ReadyForReturn && this.EstimatedReturnTime.HasValue && this.EstimatedReturnTime.Value > n)
|
||||||
|
|||||||
Reference in New Issue
Block a user