From 625bb52ee4f3607ebbb8578f08cebc5232e736b0 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sun, 22 Jan 2017 09:50:03 +0100 Subject: [PATCH] Fixed an error that was in the db, not code --- Logic/Swarm/Positions.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Logic/Swarm/Positions.cs b/Logic/Swarm/Positions.cs index 413a0744..b617eb09 100644 --- a/Logic/Swarm/Positions.cs +++ b/Logic/Swarm/Positions.cs @@ -22,7 +22,9 @@ namespace Swarmops.Logic.Swarm public static Positions ForOrganization (Organization organization) { - return FromArray (SwarmDb.GetDatabaseForReading().GetPositions (organization)); + Positions result = FromArray (SwarmDb.GetDatabaseForReading().GetPositions (organization)); + + return result; } public static Tree ForOrganizationGeography (Organization organization, Geography geography) @@ -34,6 +36,23 @@ namespace Swarmops.Logic.Swarm if (geography.Identity == Geography.RootIdentity) { result = ForOrganization (organization).AtLevel (PositionLevel.OrganizationExecutive); + + if (result.Count == 0) + { + // Empty! This should never happen. + + if (organization.Identity == Organization.SandboxIdentity) + { + // If this is Sandbox, then recreate the positions in defensive coding. + + Positions.CreateOrganizationDefaultPositions(organization); + result = ForOrganization(organization).AtLevel(PositionLevel.OrganizationExecutive); + } + else + { + throw new InvalidOperationException("Position set is empty. This should not happen."); + } + } } else {