diff --git a/Basic/Types/Security/BasicAuthority.cs b/Basic/Types/Security/BasicAuthority.cs index 551da9e2..1a55e9d9 100644 --- a/Basic/Types/Security/BasicAuthority.cs +++ b/Basic/Types/Security/BasicAuthority.cs @@ -18,7 +18,7 @@ namespace Swarmops.Basic.Types.Security BasicPersonRole[] organizationPersonRoles, BasicPersonRole[] nodePersonRoles) { - if (personId < 1) + if (personId < -1) { throw new ArgumentOutOfRangeException ("PersonId cannot be " + personId); } diff --git a/Logic/Swarm/Person.cs b/Logic/Swarm/Person.cs index 34697fda..4ad3ba44 100644 --- a/Logic/Swarm/Person.cs +++ b/Logic/Swarm/Person.cs @@ -594,7 +594,18 @@ namespace Swarmops.Logic.Swarm public static Person FromIdentity (int personId) { - return FromBasic (SwarmDb.GetDatabaseForReading().GetPerson (personId)); + if (personId > 0) + { + return FromBasic (SwarmDb.GetDatabaseForReading().GetPerson (personId)); + } + else if (personId == Person.OpenLedgersIdentity) + { + return + FromBasic (new BasicPerson (personId, string.Empty, "Open Ledgers", string.Empty, string.Empty, + string.Empty, string.Empty, 0, string.Empty, 0, DateTime.MinValue, PersonGender.Unknown)); + } + + throw new ArgumentException("No such PersonId: " + personId); } public static Person FromIdentityAggressive (int personId) @@ -1117,6 +1128,14 @@ namespace Swarmops.Logic.Swarm return true; } + // if Open Ledgers + + if ((access.Aspect == AccessAspect.Bookkeeping || access.Aspect == AccessAspect.Financials) && + access.Type == AccessType.Read && this.Identity == Person.OpenLedgersIdentity) + { + return true; + } + if (access.Type == AccessType.Write) { ids = access.Organization.Parameters.TemporaryAccessListWrite; diff --git a/Site5/App_Code/PageV5Base.cs b/Site5/App_Code/PageV5Base.cs index 28f6d151..efe3e5c3 100644 --- a/Site5/App_Code/PageV5Base.cs +++ b/Site5/App_Code/PageV5Base.cs @@ -96,7 +96,7 @@ public class PageV5Base : Page { // Check that the page has security defined - if (this.PageAccessRequired == null) + if (this.PageAccessRequired == null && !this.GetType().FullName.ToLowerInvariant().Contains ("accessdenied")) { throw new SecurityException("Page security is undefined at " + this.GetType().FullName + ". This is not permitted: minimum security must be defined for every page."); } diff --git a/Site5/Controls/v5/Base/MainMenu.ascx.cs b/Site5/Controls/v5/Base/MainMenu.ascx.cs index cf873582..fc79bcbb 100644 --- a/Site5/Controls/v5/Base/MainMenu.ascx.cs +++ b/Site5/Controls/v5/Base/MainMenu.ascx.cs @@ -32,7 +32,14 @@ namespace Swarmops.Controls.Base XmlSerializer serializer = new XmlSerializer (typeof (MainMenuItem[])); - using (TextReader reader = new StreamReader (Server.MapPath ("~/MainMenu-v5.xml"))) + string mainMenuFile = "~/MainMenu-v5.xml"; + + if (CurrentUser.Identity == Person.OpenLedgersIdentity) + { + mainMenuFile = "~/MainMenu-v5-OpenLedgers.xml"; + } + + using (TextReader reader = new StreamReader (Server.MapPath (mainMenuFile))) { MainMenuData = (MainMenuItem[]) serializer.Deserialize (reader); } @@ -90,9 +97,18 @@ namespace Swarmops.Controls.Base // TODO: More types here, and check with the CSS. Some work to get good looking case MenuItemType.Link: - output.Write ( - "{2}", - menuItem.ImageUrl, prettyNavUrl, localizedText, iconSize); + if (!string.IsNullOrEmpty (menuItem.ImageUrl)) + { + output.Write ( + "{2}", + menuItem.ImageUrl, prettyNavUrl, localizedText, iconSize); + } + else + { + output.Write( + "{1}", + prettyNavUrl, localizedText); + } break; case MenuItemType.Disabled: case MenuItemType.BuildNumber: diff --git a/Site5/MainMenu-v5-OpenLedgers.xml b/Site5/MainMenu-v5-OpenLedgers.xml new file mode 100644 index 00000000..bfeca3ab --- /dev/null +++ b/Site5/MainMenu-v5-OpenLedgers.xml @@ -0,0 +1,37 @@ + + + + + + + Ledgers_BalanceSheet + 3 + + + /Pages/v5/Ledgers/BalanceSheet.aspx + Link + + + + + Ledgers_ProfitLossStatement + 3 + + + /Pages/v5/Ledgers/ProfitLossStatement.aspx + Link + + + + + Ledgers_InspectLedgers + 3 + + + /Pages/v5/Ledgers/InspectLedgers.aspx + Link + + + + + \ No newline at end of file diff --git a/Site5/Pages/v5/User/SelectLanguage.aspx.cs b/Site5/Pages/v5/User/SelectLanguage.aspx.cs index 8c712fcd..38b4f40e 100644 --- a/Site5/Pages/v5/User/SelectLanguage.aspx.cs +++ b/Site5/Pages/v5/User/SelectLanguage.aspx.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using Swarmops.Logic.Security; namespace Swarmops.Frontend.Pages.v5.User { @@ -15,6 +16,8 @@ namespace Swarmops.Frontend.Pages.v5.User Localize(); } + PageAccessRequired = new Access (AccessAspect.Null, AccessType.Unknown); + PopulateRepeater(); } diff --git a/Site5/Pages/v5/User/SetCulture.aspx.cs b/Site5/Pages/v5/User/SetCulture.aspx.cs index 271527cc..c3fd64bd 100644 --- a/Site5/Pages/v5/User/SetCulture.aspx.cs +++ b/Site5/Pages/v5/User/SetCulture.aspx.cs @@ -1,5 +1,6 @@ using System; using System.Web; +using Swarmops.Logic.Security; namespace Swarmops.Frontend.Pages.v5.User { @@ -18,9 +19,10 @@ namespace Swarmops.Frontend.Pages.v5.User } Response.SetCookie(new HttpCookie("PreferredCulture", cultureId)); + PageAccessRequired = new Access(AccessAspect.Null, AccessType.Unknown); AuthenticationData authenticationData = GetAuthenticationDataAndCulture(); - if (authenticationData.CurrentUser != null) + if (authenticationData.CurrentUser != null && authenticationData.CurrentUser.PersonId > 0) { authenticationData.CurrentUser.PreferredCulture = cultureId; } diff --git a/Site5/Security/Login.aspx.cs b/Site5/Security/Login.aspx.cs index 1e76223f..f3780257 100644 --- a/Site5/Security/Login.aspx.cs +++ b/Site5/Security/Login.aspx.cs @@ -87,12 +87,13 @@ namespace Swarmops.Pages.Security // If we're on an Open Ledgers domain, autologin as Open Ledgers - Organization organization = Organization.FromOpenLedgersDomain(requestHost); // returns null if doesn't exist + Organization organizationOpenLedgers = Organization.FromOpenLedgersDomain(requestHost); // returns null if doesn't exist - if (organization != null) + if (organizationOpenLedgers != null) { - Response.AppendCookie(new HttpCookie("DashboardMessage", HttpUtility.UrlEncode(Resources.Pages.Security.Login_AsOpenLedgers))); - FormsAuthentication.SetAuthCookie(Person.OpenLedgersIdentity.ToString() + "," + organization.Identity.ToString(), true); + Response.AppendCookie(new HttpCookie("DashboardMessage", HttpUtility.UrlEncode(String.Format(Resources.Pages.Security.Login_AsOpenLedgers, organizationOpenLedgers.Name)))); + FormsAuthentication.SetAuthCookie(Person.OpenLedgersIdentity.ToString() + "," + organizationOpenLedgers.Identity.ToString(), true); + Response.Redirect ("/Ledgers/BalanceSheet"); } // Check for SSL and force it