Added new Change Organizations

This commit is contained in:
Rick Falkvinge
2014-10-25 16:01:51 +02:00
parent b96bf0a011
commit ae01d2d88e
8 changed files with 241 additions and 43 deletions
@@ -133,11 +133,14 @@
<value>Current organization</value>
</data>
<data name="ChangeOrganizations_Info" xml:space="preserve">
<value>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.</value>
<value>You can be taking part in several organizations on this Swarmops installation. Here is where you switch between them.</value>
</data>
<data name="ChangeOrganizations_NewOrganization" xml:space="preserve">
<value>New organization</value>
</data>
<data name="ChangeOrganizations_NothingToChange" xml:space="preserve">
<value>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.</value>
</data>
<data name="ChangeOrganizations_PageTitle" xml:space="preserve">
<value>Change Organizations</value>
</data>
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

@@ -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" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
<Swarmops5:ExternalScripts ID="ExternalScripts1" Package="easyui" Control="tree" runat="server" />
<Swarmops5:ExternalScripts ID="ExternalScripts1" Package="easyui" Control="datagrid" runat="server" />
<script type="text/javascript" src="/Scripts/fancybox/jquery.fancybox-1.3.4.js"></script>
<script type="text/javascript" src="/Scripts/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
<link rel="stylesheet" type="text/css" href="/Scripts/fancybox/jquery.fancybox-1.3.4.css" media="screen" />
<script type="text/javascript">
$(document).ready(function () {
$('#DropOrganizations').combotree({
animate: true,
height: 30
});
$(document).ready(function() {
if (organizationCount == 0) {
alertify.alert("<asp:Literal ID="LabelNoOrganizations" runat="server" />", function() {
document.location = "/";
});
}
});
</script>
<link rel="stylesheet" type="text/css" href="/Style/v5-easyui-elements.css">
var organizationCount = <%=this.OrganizationCount %>;
</script>
<style type="text/css">
div.divOrganizationEncapsulation {
border: solid 1px transparent;
padding-top: 1px;
}
div.divOrganizationEncapsulation:hover {
border-radius: 4px;
-moz-border-radius:4px;
border: solid 1px #FFBC37;
background: #FFD580;
background: -webkit-gradient(linear, left top, left bottom, from(#ffd98c), to(#f0c265));
background: -moz-linear-gradient(top, #ffd98c, #f0c265);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd98c', endColorstr='#f0c265');
color: #7F5500;
cursor: pointer;
-webkit-box-shadow: 0 1px 3px #C78B15;
-moz-box-shadow: 0 1px 3px #C78B15;
box-shadow: 0 1px 3px #C78B15;
}
div.divOrganizationLogo {
float: left;
background-position: left;
padding-left: 2px;
margin-left: 4px;
background-repeat: no-repeat;
width: 70px;
height: 48px;
}
div.spanOrganizationName {
padding-top: 10px;
font-size: 24px;
padding-bottom: 10px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
<div class="entryFields">
<span style="margin-left:12px"><asp:Label runat="server" ID="LabelCurrentOrganizationName" /></span>&nbsp;<br/>
<select class="easyui-combotree" url="Json-AccessibleOrganizationsTree.aspx" name="DropOrganizations" id="DropOrganizations" animate="true" style="width:300px" height="30"></select>
<asp:Button ID="ButtonSwitch" runat="server" CssClass="buttonAccentColor NoInputFocus" OnClick="ButtonSwitch_Click" Text="Switch"/>
<% if (!PilotInstallationIds.IsPilot(PilotInstallationIds.PiratePartySE)) // at the first pilot installation, the first live org was #1 and there was no sandbox
{ %>
<div class="divOrganizationEncapsulation" onclick="document.location='/Pages/v5/Security/SetCurrentOrganization.aspx?OrganizationId=1';">
<div class="divOrganizationLogo" style="background-image:url('/Images/Other/clipart-panda-free-sandbox-icon-64px.png')" ></div>
<div class="spanOrganizationName">Sandbox</div>
</div>
<div class="entryLabels">
<asp:Label runat="server" ID="LabelCurrentOrganization" /><br/>
<asp:Label runat="server" ID="LabelNewOrganization" />
</div>
<div style="clear:both"></div>
<hr/>
<% } %>
<asp:Repeater runat="server" ID="RepeaterOrganizations">
<ItemTemplate>
<div class="divOrganizationEncapsulation" onclick="document.location='/Pages/v5/Security/SetCurrentOrganization.aspx?OrganizationId=<%# Eval("OrganizationId") %>';">
<div class="divOrganizationLogo" style="background-image:url('<%# Eval("LogoUrl")%>')" ></div>
<div class="spanOrganizationName"><%# Eval("OrganizationName") %></div>
</div>
</ItemTemplate>
</asp:Repeater>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderSide" Runat="Server">
</asp:Content>
@@ -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<OrganizationParameters> availableOrganizations = new List<OrganizationParameters>();
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; }
}
}
}
@@ -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" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
<Swarmops5:ExternalScripts ID="ExternalScripts1" Package="easyui" Control="tree" runat="server" />
<script type="text/javascript">
$(document).ready(function () {
$('#DropOrganizations').combotree({
animate: true,
height: 30
});
});
</script>
<link rel="stylesheet" type="text/css" href="/Style/v5-easyui-elements.css">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
<div class="entryFields">
<span style="margin-left:12px"><asp:Label runat="server" ID="LabelCurrentOrganizationName" /></span>&nbsp;<br/>
<select class="easyui-combotree" url="Json-AccessibleOrganizationsTree.aspx" name="DropOrganizations" id="DropOrganizations" animate="true" style="width:300px" height="30"></select>
<asp:Button ID="ButtonSwitch" runat="server" CssClass="buttonAccentColor NoInputFocus" OnClick="ButtonSwitch_Click" Text="Switch"/>
</div>
<div class="entryLabels">
<asp:Label runat="server" ID="LabelCurrentOrganization" /><br/>
<asp:Label runat="server" ID="LabelNewOrganization" />
</div>
<div style="clear:both"></div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderSide" Runat="Server">
</asp:Content>
@@ -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);
}
}
}
@@ -0,0 +1 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SetCurrentOrganization.aspx.cs" MasterPageFile="~/Master-v5.master" Inherits="Swarmops.Frontend.Pages.v5.Security.SetCurrentOrganization" %>
@@ -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
}
}
}