From ae01d2d88ee84ba1422db23b35716ba8799ddbfb Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sat, 25 Oct 2014 16:01:51 +0200 Subject: [PATCH] Added new Change Organizations --- Site5/App_GlobalResources/Pages.Security.resx | 5 +- .../clipart-panda-free-sandbox-icon-64px.png | Bin 0 -> 3376 bytes .../v5/Security/ChangeOrganizations.aspx | 94 +++++++++++++----- .../v5/Security/ChangeOrganizations.aspx.cs | 61 ++++++++---- .../Security/ChangeOrganizationsAdvanced.aspx | 36 +++++++ .../ChangeOrganizationsAdvanced.aspx.cs | 39 ++++++++ .../v5/Security/SetCurrentOrganization.aspx | 1 + .../Security/SetCurrentOrganization.aspx.cs | 48 +++++++++ 8 files changed, 241 insertions(+), 43 deletions(-) create mode 100644 Site5/Images/Other/clipart-panda-free-sandbox-icon-64px.png create mode 100644 Site5/Pages/v5/Security/ChangeOrganizationsAdvanced.aspx create mode 100644 Site5/Pages/v5/Security/ChangeOrganizationsAdvanced.aspx.cs create mode 100644 Site5/Pages/v5/Security/SetCurrentOrganization.aspx create mode 100644 Site5/Pages/v5/Security/SetCurrentOrganization.aspx.cs diff --git a/Site5/App_GlobalResources/Pages.Security.resx b/Site5/App_GlobalResources/Pages.Security.resx index 2d8e98ba..8cb73a8b 100644 --- a/Site5/App_GlobalResources/Pages.Security.resx +++ b/Site5/App_GlobalResources/Pages.Security.resx @@ -133,11 +133,14 @@ Current organization - Do you want to work with another organization in this Swarmops installation which you can access in a member, staff, or activist role? No problem, just select it and switch. + You can be taking part in several organizations on this Swarmops installation. Here is where you switch between them. New organization + + You're not part of any other organizations on this Swarmops installation, so you can't switch to something else. Therefore, we're going back to Dashboard instead. + Change Organizations diff --git a/Site5/Images/Other/clipart-panda-free-sandbox-icon-64px.png b/Site5/Images/Other/clipart-panda-free-sandbox-icon-64px.png new file mode 100644 index 0000000000000000000000000000000000000000..af9422bfdf20e5f1369e4b5c52f9886f44e727d9 GIT binary patch literal 3376 zcmV-04bSq4P)@F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hX)53EZ>IG5pDABMEb5vZWU7bH1jedmXP9Sm}J z^t;KHkxZ$ld@JlnIn^)$a7ut1fa@g0IYS;YEG66r%e&gIeh`Lw{WaX*4Bf-)9F49_ z@+&7IZPB{q(;t?OANt$j?#8$UOmo>B3r29u5#T4l zJ<+;k?}x45NAddr6Rk@=7p+TP0bB@d1>Qc6@81A!0=^KfOD+X^KLXu8o}b8cH^#>x z%*W;j1V{pR0Z&Eil5Y*)>lLIR1t~~D3Q~}Q6r>;@j{G0L6aLSZXf~<<0000=? literal 0 HcmV?d00001 diff --git a/Site5/Pages/v5/Security/ChangeOrganizations.aspx b/Site5/Pages/v5/Security/ChangeOrganizations.aspx index 49330ac2..b74704c6 100644 --- a/Site5/Pages/v5/Security/ChangeOrganizations.aspx +++ b/Site5/Pages/v5/Security/ChangeOrganizations.aspx @@ -1,36 +1,84 @@ -<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="ChangeOrganizations.aspx.cs" Inherits="Swarmops.Frontend.Pages.Security.ChangeOrganizations" %> -<%@ Register TagPrefix="Swarmops5" TagName="ExternalScripts" Src="~/Controls/v5/UI/ExternalScripts.ascx" %> -<%@ Register TagPrefix="Swarmops5" TagName="ComboBudgets" Src="~/Controls/v5/Financial/ComboBudgets.ascx" %> +<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="ChangeOrganizations.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Security.ChangeOrganizations" %> +<%@ Import Namespace="Swarmops.Logic.Support" %> +<%@ Register src="~/Controls/v5/UI/ExternalScripts.ascx" tagname="ExternalScripts" tagprefix="Swarmops5" %> - + + + + + - + var organizationCount = <%=this.OrganizationCount %>; + + + + + - -
-  
- - - + <% if (!PilotInstallationIds.IsPilot(PilotInstallationIds.PiratePartySE)) // at the first pilot installation, the first live org was #1 and there was no sandbox + { %> +
+ +
Sandbox
- -
+
+ <% } %> + + +
';"> + +
<%# Eval("OrganizationName") %>
+
+
+
- diff --git a/Site5/Pages/v5/Security/ChangeOrganizations.aspx.cs b/Site5/Pages/v5/Security/ChangeOrganizations.aspx.cs index 7f6e0b03..96c4a8bc 100644 --- a/Site5/Pages/v5/Security/ChangeOrganizations.aspx.cs +++ b/Site5/Pages/v5/Security/ChangeOrganizations.aspx.cs @@ -1,39 +1,62 @@ using System; +using System.Collections.Generic; +using System.Drawing; using System.Globalization; -using System.Web.Security; +using System.ServiceModel.Security; +using System.Web; +using System.Web.Services; +using Swarmops.Logic.Financial; +using Swarmops.Logic.Support; +using Swarmops.Logic.Swarm; -namespace Swarmops.Frontend.Pages.Security +namespace Swarmops.Frontend.Pages.v5.Security { public partial class ChangeOrganizations : PageV5Base { protected void Page_Load(object sender, EventArgs e) { - if (!Page.IsPostBack) - { - Localize(); - } - - // this.PageAccessRequired = new Access(AccessAspect.Bookkeeping, AccessType.Write); // bogus, but will prevent bad ppl from entering until real security done - this.PageTitle = Resources.Pages.Security.ChangeOrganizations_PageTitle; this.PageIcon = "iconshock-organizations"; this.InfoBoxLiteral = Resources.Pages.Security.ChangeOrganizations_Info; - this.LabelCurrentOrganizationName.Text = CurrentOrganization.Name; + this.LabelNoOrganizations.Text = Resources.Pages.Security.ChangeOrganizations_NothingToChange; + + PopulateRepeater(); } - private void Localize() + private void PopulateRepeater() { - this.LabelCurrentOrganization.Text = Resources.Pages.Security.ChangeOrganizations_CurrentOrganization; - this.LabelNewOrganization.Text = Resources.Pages.Security.ChangeOrganizations_NewOrganization; + Memberships memberships = CurrentUser.GetMemberships(); + + List availableOrganizations = new List(); + foreach (Membership membership in memberships) + { + if (membership.OrganizationId == 1 && !PilotInstallationIds.IsPilot(PilotInstallationIds.PiratePartySE)) + { + // sandbox. Ignore. + continue; + } + + OrganizationParameters newOrganization = new OrganizationParameters(); + newOrganization.LogoUrl = "/Images/Flags/txl-64px.png"; + newOrganization.OrganizationId = membership.OrganizationId; + newOrganization.OrganizationName = membership.Organization.Name; + + availableOrganizations.Add(newOrganization); + } + + this.OrganizationCount = availableOrganizations.Count; + + this.RepeaterOrganizations.DataSource = availableOrganizations; + this.RepeaterOrganizations.DataBind(); } - protected void ButtonSwitch_Click(object sender, EventArgs e) + public int OrganizationCount { get; set; } + + private class OrganizationParameters { - int newOrganizationId = Int32.Parse(this.Request.Form["DropOrganizations"]); - - // TODO: Re-authorize user's ability to log onto this org - - FormsAuthentication.RedirectFromLoginPage(this.CurrentUser.Identity.ToString(CultureInfo.InvariantCulture) + "," + newOrganizationId.ToString(CultureInfo.InvariantCulture), true); + public string LogoUrl { get; set; } + public int OrganizationId { get; set; } + public string OrganizationName { get; set; } } } } \ No newline at end of file diff --git a/Site5/Pages/v5/Security/ChangeOrganizationsAdvanced.aspx b/Site5/Pages/v5/Security/ChangeOrganizationsAdvanced.aspx new file mode 100644 index 00000000..89c00e47 --- /dev/null +++ b/Site5/Pages/v5/Security/ChangeOrganizationsAdvanced.aspx @@ -0,0 +1,36 @@ +<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="ChangeOrganizationsAdvanced.aspx.cs" Inherits="Swarmops.Frontend.Pages.Security.ChangeOrganizationsAdvanced" %> +<%@ Register TagPrefix="Swarmops5" TagName="ExternalScripts" Src="~/Controls/v5/UI/ExternalScripts.ascx" %> +<%@ Register TagPrefix="Swarmops5" TagName="ComboBudgets" Src="~/Controls/v5/Financial/ComboBudgets.ascx" %> + + + + + + + + + + +
+  
+ + + +
+ +
+
+ + + + diff --git a/Site5/Pages/v5/Security/ChangeOrganizationsAdvanced.aspx.cs b/Site5/Pages/v5/Security/ChangeOrganizationsAdvanced.aspx.cs new file mode 100644 index 00000000..193e00f5 --- /dev/null +++ b/Site5/Pages/v5/Security/ChangeOrganizationsAdvanced.aspx.cs @@ -0,0 +1,39 @@ +using System; +using System.Globalization; +using System.Web.Security; + +namespace Swarmops.Frontend.Pages.Security +{ + public partial class ChangeOrganizationsAdvanced : PageV5Base + { + protected void Page_Load(object sender, EventArgs e) + { + if (!Page.IsPostBack) + { + Localize(); + } + + // this.PageAccessRequired = new Access(AccessAspect.Bookkeeping, AccessType.Write); // bogus, but will prevent bad ppl from entering until real security done + + this.PageTitle = Resources.Pages.Security.ChangeOrganizations_PageTitle; + this.PageIcon = "iconshock-organizations"; + this.InfoBoxLiteral = Resources.Pages.Security.ChangeOrganizations_Info; + this.LabelCurrentOrganizationName.Text = CurrentOrganization.Name; + } + + private void Localize() + { + this.LabelCurrentOrganization.Text = Resources.Pages.Security.ChangeOrganizations_CurrentOrganization; + this.LabelNewOrganization.Text = Resources.Pages.Security.ChangeOrganizations_NewOrganization; + } + + protected void ButtonSwitch_Click(object sender, EventArgs e) + { + int newOrganizationId = Int32.Parse(this.Request.Form["DropOrganizations"]); + + // TODO: Re-authorize user's ability to log onto this org + + FormsAuthentication.RedirectFromLoginPage(this.CurrentUser.Identity.ToString(CultureInfo.InvariantCulture) + "," + newOrganizationId.ToString(CultureInfo.InvariantCulture), true); + } + } +} \ No newline at end of file diff --git a/Site5/Pages/v5/Security/SetCurrentOrganization.aspx b/Site5/Pages/v5/Security/SetCurrentOrganization.aspx new file mode 100644 index 00000000..ea6565dc --- /dev/null +++ b/Site5/Pages/v5/Security/SetCurrentOrganization.aspx @@ -0,0 +1 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SetCurrentOrganization.aspx.cs" MasterPageFile="~/Master-v5.master" Inherits="Swarmops.Frontend.Pages.v5.Security.SetCurrentOrganization" %> diff --git a/Site5/Pages/v5/Security/SetCurrentOrganization.aspx.cs b/Site5/Pages/v5/Security/SetCurrentOrganization.aspx.cs new file mode 100644 index 00000000..d803ba74 --- /dev/null +++ b/Site5/Pages/v5/Security/SetCurrentOrganization.aspx.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Web; +using System.Web.Security; +using System.Web.UI; +using System.Web.UI.WebControls; +using Swarmops.Logic.Structure; + +namespace Swarmops.Frontend.Pages.v5.Security +{ + public partial class SetCurrentOrganization : PageV5Base + { + protected void Page_Load(object sender, EventArgs e) + { + if (CurrentUser == null) + { + throw new UnauthorizedAccessException("No"); // may cause problems on login screen? + } + + string organizationIdString = Request.QueryString["OrganizationId"]; + int organizationId = Int32.Parse(organizationIdString); + Organization suggestedOrganization = null; + try + { + suggestedOrganization = Organization.FromIdentity(organizationId); + } + catch (ArgumentException) + { + suggestedOrganization = null; + } + + if (suggestedOrganization == null || !CurrentUser.MemberOf(suggestedOrganization)) + { + // Some work here on PPSE pilot - we want everybody to be able to switch to Sandbox, which is #1 + // except for in PPSE installation, where it is... #3 or something + + throw new UnauthorizedAccessException(); + } + + FormsAuthentication.RedirectFromLoginPage( + CurrentUser.Identity.ToString(CultureInfo.InvariantCulture) + "," + + suggestedOrganization.Identity.ToString(CultureInfo.InvariantCulture), true); // we're not using the original input for security reasons + + } + } +} \ No newline at end of file