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)
|
||||
{
|
||||
return this.Get<OrganisationAddress>(null, Id.ToString());
|
||||
return Get<OrganisationAddress>(null, Id.ToString());
|
||||
}
|
||||
public OrganisationAddress SetAddress(OrganisationAddress Address)
|
||||
{
|
||||
@@ -25,21 +25,21 @@ namespace Disco.Data.Configuration.Modules
|
||||
Address.Id = NextOrganisationAddressId;
|
||||
}
|
||||
|
||||
this.Set(Address, Address.Id.ToString());
|
||||
Set(Address, Address.Id.ToString());
|
||||
|
||||
return Address;
|
||||
}
|
||||
public void RemoveAddress(int Id)
|
||||
{
|
||||
// Remove Configuration Item
|
||||
this.RemoveItem(Id.ToString());
|
||||
RemoveItem(Id.ToString());
|
||||
}
|
||||
|
||||
public List<OrganisationAddress> Addresses
|
||||
{
|
||||
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;
|
||||
while (true)
|
||||
{
|
||||
if (this.Get<string>(null, nextId.ToString()) == null)
|
||||
if (Get<string>(null, nextId.ToString()) == null)
|
||||
break;
|
||||
nextId++;
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ namespace Disco.Services
|
||||
j.OpenedTechUserFriendlyId = ActiveDirectory.FriendlyAccountId(j.OpenedTechUserId);
|
||||
|
||||
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;
|
||||
|
||||
@@ -53,9 +53,7 @@ namespace Disco.Services.Jobs.Noticeboards
|
||||
if (DeviceAddressId.HasValue)
|
||||
{
|
||||
var config = new OrganisationAddressesConfiguration(null);
|
||||
var address = config.GetAddress(DeviceAddressId.Value);
|
||||
if (address != null)
|
||||
return address.ShortName;
|
||||
return config.GetAddress(DeviceAddressId.Value)?.ShortName;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -285,7 +285,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
#endregion
|
||||
|
||||
#region Update Properties
|
||||
private void UpdateDescription(Disco.Models.Repository.DeviceProfile deviceProfile, string Description)
|
||||
private void UpdateDescription(DeviceProfile deviceProfile, string Description)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Description))
|
||||
deviceProfile.Description = null;
|
||||
@@ -294,7 +294,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
Database.SaveChanges();
|
||||
}
|
||||
|
||||
private void UpdateName(Disco.Models.Repository.DeviceProfile deviceProfile, string Name)
|
||||
private void UpdateName(DeviceProfile deviceProfile, string Name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Name))
|
||||
throw new Exception("Profile name cannot be empty");
|
||||
@@ -303,7 +303,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
Database.SaveChanges();
|
||||
}
|
||||
|
||||
private void UpdateShortName(Disco.Models.Repository.DeviceProfile deviceProfile, string ShortName)
|
||||
private void UpdateShortName(DeviceProfile deviceProfile, string ShortName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(ShortName))
|
||||
throw new Exception("Profile short name cannot be empty");
|
||||
@@ -312,12 +312,12 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
Database.SaveChanges();
|
||||
}
|
||||
|
||||
private void UpdateDistributionType(Disco.Models.Repository.DeviceProfile deviceProfile, string DistributionType)
|
||||
private void UpdateDistributionType(DeviceProfile deviceProfile, string DistributionType)
|
||||
{
|
||||
int iDt;
|
||||
if (int.TryParse(DistributionType, out iDt))
|
||||
{
|
||||
deviceProfile.DistributionType = (Disco.Models.Repository.DeviceProfile.DistributionTypes)iDt;
|
||||
deviceProfile.DistributionType = (DeviceProfile.DistributionTypes)iDt;
|
||||
Database.SaveChanges();
|
||||
return;
|
||||
}
|
||||
@@ -432,7 +432,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
Database.SaveChanges();
|
||||
}
|
||||
|
||||
private void UpdateOrganisationalUnit(Disco.Models.Repository.DeviceProfile deviceProfile, string OrganisationalUnit)
|
||||
private void UpdateOrganisationalUnit(DeviceProfile deviceProfile, string OrganisationalUnit)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(OrganisationalUnit))
|
||||
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);
|
||||
|
||||
@@ -458,7 +458,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
deviceProfile.ComputerNameInvalidateCache();
|
||||
}
|
||||
|
||||
private void UpdateDefaultOrganisationAddress(Disco.Models.Repository.DeviceProfile deviceProfile, string DefaultOrganisationAddress)
|
||||
private void UpdateDefaultOrganisationAddress(DeviceProfile deviceProfile, string DefaultOrganisationAddress)
|
||||
{
|
||||
if (string.IsNullOrEmpty(DefaultOrganisationAddress))
|
||||
{
|
||||
@@ -490,7 +490,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
Database.SaveChanges();
|
||||
}
|
||||
|
||||
private void UpdateEnforceComputerNameConvention(Disco.Models.Repository.DeviceProfile deviceProfile, string EnforceComputerNameConvention)
|
||||
private void UpdateEnforceComputerNameConvention(DeviceProfile deviceProfile, string EnforceComputerNameConvention)
|
||||
{
|
||||
bool bValue;
|
||||
if (bool.TryParse(EnforceComputerNameConvention, out bValue))
|
||||
@@ -503,7 +503,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
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;
|
||||
if (bool.TryParse(EnforceOrganisationalUnit, out bValue))
|
||||
@@ -516,7 +516,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
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;
|
||||
if (bool.TryParse(ProvisionADAccount, out bValue))
|
||||
|
||||
@@ -167,6 +167,11 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
[DiscoAuthorize(Claims.Config.Organisation.ConfigureAddresses)]
|
||||
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.SaveChanges();
|
||||
|
||||
|
||||
@@ -27,8 +27,12 @@ namespace Disco.Web.Areas.Config.Models.DeviceProfile
|
||||
if (DiscoApplication.MultiSiteMode)
|
||||
{
|
||||
foreach (var dp in m.DeviceProfiles)
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Disco.Web.Areas.Public.Models.UserHeldDevices
|
||||
ReadyForReturn = this.ReadyForReturn,
|
||||
WaitingForUserAction = this.WaitingForUserAction,
|
||||
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;
|
||||
if (!this.ReadyForReturn && this.EstimatedReturnTime.HasValue && this.EstimatedReturnTime.Value > n)
|
||||
|
||||
Reference in New Issue
Block a user