From 512d19b0278a02524c7c39d10cd6f2fde6735187 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Wed, 19 Nov 2014 04:20:16 +0100 Subject: [PATCH] Hardened Sandbox to cope with dbresets --- Site5/App_Code/CommonV5.cs | 14 +++++++++++++- Site5/App_Code/ControlV5Base.cs | 14 +++++++++++++- Site5/App_Code/DataV5Base.cs | 14 +++++++++++++- Site5/Master-v5.master.cs | 14 +++++++++++++- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/Site5/App_Code/CommonV5.cs b/Site5/App_Code/CommonV5.cs index 77b7e79d..2c4e8854 100644 --- a/Site5/App_Code/CommonV5.cs +++ b/Site5/App_Code/CommonV5.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.Threading; using System.Web; using Swarmops.Logic.Structure; +using Swarmops.Logic.Support; using Swarmops.Logic.Swarm; /// @@ -92,7 +93,18 @@ public class CommonV5 int currentOrganizationId = Convert.ToInt32(organizationIdentityString); result.CurrentUser = Person.FromIdentity(currentUserId); - result.CurrentOrganization = Organization.FromIdentity(currentOrganizationId); + try + { + result.CurrentOrganization = Organization.FromIdentity(currentOrganizationId); + } + catch (ArgumentException) + { + if (PilotInstallationIds.IsPilot(PilotInstallationIds.DevelopmentSandbox)) + { + // It's possible this organization was deleted. Log on to Sandbox instead. + result.CurrentOrganization = Organization.Sandbox; + } + } CommonV5.CulturePreInit(HttpContext.Current.Request); // OnPreInit() isn't called in the static methods calling this fn diff --git a/Site5/App_Code/ControlV5Base.cs b/Site5/App_Code/ControlV5Base.cs index 852de2c8..7986fde2 100644 --- a/Site5/App_Code/ControlV5Base.cs +++ b/Site5/App_Code/ControlV5Base.cs @@ -4,6 +4,7 @@ using System.Web; using Swarmops.Logic.Cache; using Swarmops.Logic.Security; using Swarmops.Logic.Structure; +using Swarmops.Logic.Support; using Swarmops.Logic.Swarm; /// @@ -33,8 +34,19 @@ public class ControlV5Base : System.Web.UI.UserControl currentUserId = Convert.ToInt32(userIdentityString); currentOrganizationId = Convert.ToInt32(organizationIdentityString); _currentUser = Person.FromIdentity(currentUserId); - _currentOrganization = Organization.FromIdentity(currentOrganizationId); _authority = _currentUser.GetAuthority(); + try + { + _currentOrganization = Organization.FromIdentity(currentOrganizationId); + } + catch (ArgumentException) + { + if (PilotInstallationIds.IsPilot(PilotInstallationIds.DevelopmentSandbox)) + { + // It's possible this organization was deleted. Log on to Sandbox instead. + _currentOrganization = Organization.Sandbox; + } + } base.OnLoad(e); } diff --git a/Site5/App_Code/DataV5Base.cs b/Site5/App_Code/DataV5Base.cs index 8cb0186a..b27d4f58 100644 --- a/Site5/App_Code/DataV5Base.cs +++ b/Site5/App_Code/DataV5Base.cs @@ -4,6 +4,7 @@ using System.Web; using Swarmops.Basic.Enums; using Swarmops.Logic.Security; using Swarmops.Logic.Structure; +using Swarmops.Logic.Support; using Swarmops.Logic.Swarm; /// @@ -31,7 +32,18 @@ public class DataV5Base : System.Web.UI.Page string organizationIdentityString = identityTokens[1]; this.CurrentUser = Person.FromIdentity(Int32.Parse(userIdentityString)); - this.CurrentOrganization = Organization.FromIdentity(Int32.Parse(organizationIdentityString)); + try + { + this.CurrentOrganization = Organization.FromIdentity(Int32.Parse(organizationIdentityString)); + } + catch (ArgumentException) + { + if (PilotInstallationIds.IsPilot(PilotInstallationIds.DevelopmentSandbox)) + { + // It's possible this organization was deleted. Log on to Sandbox instead. + this.CurrentOrganization = Organization.Sandbox; + } + } } else { diff --git a/Site5/Master-v5.master.cs b/Site5/Master-v5.master.cs index d9b53c8d..7808df2d 100644 --- a/Site5/Master-v5.master.cs +++ b/Site5/Master-v5.master.cs @@ -9,6 +9,7 @@ using System.Web.UI; using System.Web.UI.WebControls; using Swarmops.Logic.Security; using Swarmops.Logic.Structure; +using Swarmops.Logic.Support; using Swarmops.Logic.Swarm; using Membership = Swarmops.Logic.Swarm.Membership; @@ -32,7 +33,18 @@ namespace Swarmops _currentUser = Person.FromIdentity(currentUserId); _authority = _currentUser.GetAuthority(); - _currentOrganization = Organization.FromIdentity(currentOrganizationId); + try + { + _currentOrganization = Organization.FromIdentity(currentOrganizationId); + } + catch (ArgumentException) + { + if (PilotInstallationIds.IsPilot(PilotInstallationIds.DevelopmentSandbox)) + { + // It's possible this organization was deleted. Log on to Sandbox instead. + _currentOrganization = Organization.Sandbox; + } + } } protected void Page_Load(object sender, EventArgs e)