Committing some new access controls

This commit is contained in:
Rick Falkvinge
2012-01-01 14:37:40 +00:00
parent a49a508359
commit 51431204a2
12 changed files with 187 additions and 43 deletions
+1
View File
@@ -64,6 +64,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Security\Accesses.cs" />
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Cache\MailTemplateCache.cs" />
<Compile Include="Cache\GeographyCache.cs" />
+31
View File
@@ -1009,5 +1009,36 @@ namespace Activizr.Logic.Pirates
{
return GetAvatarLink(pixelSize).Replace("http://www", "https://secure");
}
public bool HasAccess (Access access)
{
if (access == null)
{
return true;
}
bool result = false;
// TODO: Build access control list from org chart, compare against required access
// For now, return true if Anna, Janne, or Rick. Bad hack, bad, really bad.
if (this.Identity == 2)
{
return true;
}
if (this.Identity == 11443)
{
return true;
}
if (this.Identity == 378)
{
return true;
}
return result;
}
}
}
+49
View File
@@ -0,0 +1,49 @@
using Activizr.Basic.Enums;
using Activizr.Logic.Structure;
namespace Activizr.Logic.Security
{
public class Access
{
public Access (AccessAspect aspect, AccessType type)
{
this.Aspect = aspect;
this.Type = type;
}
public Access(Organization organization, AccessAspect aspect, AccessType type)
{
this.Organization = organization;
this.Aspect = aspect;
this.Type = type;
}
public Access(Organization organization, Geography geography, AccessAspect aspect, AccessType type)
{
this.Organization = organization;
this.Geography = geography;
this.Aspect = aspect;
this.Type = type;
}
public readonly Organization Organization;
public readonly Geography Geography;
public readonly AccessAspect Aspect;
public readonly AccessType Type;
}
public enum AccessAspect
{
Unknown = 0,
Bookkeeping,
Financials
}
public enum AccessType
{
Unknown = 0,
Read,
Write
}
}
+13 -2
View File
@@ -17,6 +17,7 @@ using Activizr.Logic.Structure;
public class PageV5Base : System.Web.UI.Page
{
public PermissionSet pagePermissionDefault = new PermissionSet(Permission.CanSeeSelf); //Use from menu;
public Access PageAccessRequired = null; // v5 mechanism
public Person _currentUser = null;
public Authority _authority = null;
@@ -109,10 +110,20 @@ public class PageV5Base : System.Web.UI.Page
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
base.OnPreInit(e);
}
protected override void OnPreRender(EventArgs e)
{
// Check security of page against users's credentials
if (!_currentUser.HasAccess (this.PageAccessRequired))
{
Response.Redirect("/Pages/v5/Security/AccessDenied.aspx");
}
base.OnPreRender(e);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 846 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 860 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

+13 -13
View File
@@ -116,14 +116,14 @@ div.BankUploadInstructionsImage
<asp:UpdatePanel ID="PanelFileTypeAccount" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<h2><asp:Label ID="LabelSelectBankUploadFilter" Text="Select Bank And Bookkeeping" runat="server"/></h2>
<h3><asp:Label ID="LabelBank" Text="Bank" runat="server" /></h3>
<h2><asp:Label ID="LabelSelectBankUploadFilter" Text="Select Bank And Bookkeeping LOC" runat="server"/></h2>
<h3><asp:Label ID="LabelBank" Text="Bank LOC" runat="server" /></h3>
<asp:ImageButton OnClick="ButtonSebAccountFile_Click" CssClass="FileTypeImage" ID="ButtonSebAccountFile" runat="server" ImageUrl="~/Images/Ledgers/uploadbankfiles-type-seb-kontoutdrag.png"/>
<asp:ImageButton CssClass="FileTypeImage" ID="ButtonSebPaymentFile" runat="server" ImageUrl="~/Images/Ledgers/uploadbankfiles-type-seb-bankgirofil.png"/>
<asp:HiddenField ID="HiddenFileType" runat="server"/>
<div style="clear:both;margin-bottom:10px"></div>
<div id="DivSelectAccount" <asp:Literal ID="LiteralSelectAccountDivStyle" runat="server" Text="style='opacity:0;display:none;'" />>
<h3><asp:Label ID="LabelSelectAccount" runat="server" Text="Bookkeeping Account" /></h3>
<div id="DivSelectAccount" <asp:Literal ID="LiteralSelectAccountDivStyle" runat="server" Text="style='opacity:0;display:none'" />>
<h3><asp:Label ID="LabelSelectAccount" runat="server" Text="Bookkeeping Account LOC" /></h3>
<asp:DropDownList runat="server" ID="DropAccounts" OnSelectedIndexChanged="DropAccounts_SelectedIndexChanged" AutoPostBack="true"/>
</div>
</ContentTemplate>
@@ -133,30 +133,30 @@ div.BankUploadInstructionsImage
</asp:UpdatePanel>
<asp:Panel ID="PanelResults" Visible="false" runat="server">
<h2><asp:Label ID="LabelProcessingResults" Text="Imported a Bank File" runat="server" /></h2>
<h2><asp:Label ID="LabelProcessingResults" Text="Imported a Bank File LOC" runat="server" /></h2>
<p>Todo...</p>
</asp:Panel>
<div style="opacity:0;display:none" id="DivUploadProgress">
<br/><h2><asp:Label ID="LabelProcessing" runat="server" Text="Processing Uploaded File..." /></h2>
<br/><br/><h2><asp:Label ID="LabelProcessing" runat="server" Text="Processing Uploaded File... LOC" /></h2>
</div>
<div style="opacity:0;display:none;padding-top:20px" id="DivInstructions">
<div id="DivInstructions" <asp:Literal ID="LiteralDivInstructionsStyle" runat="server" Text="style='display:none'" />>
<asp:UpdatePanel ID="PanelInstructions" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<br/><h2><asp:Label ID="LabelUploadH2Header" Text="Upload Bank File" runat="server" /></h2>
<a rel="leanModal" name="ModalDownloadInstructions" id="go" href="#ModalDownloadInstructions"><asp:Image ID="ImageDownloadInstructions" ImageUrl="~/Images/Ledgers/uploadbankfiles-seb-kontoutdrag-small.png" ImageAlign="Right" runat="server" /></a>
<h3><asp:Label ID="LabelDownloadInstructions" Text="Download File From Bank" runat="server" /></h3>
<p><asp:Literal ID="LiteralDownloadInstructions" runat="server" Text="Fooo!!!" /><asp:Literal ID="LiteralLastAccountRecord" runat="server" /></p><p><asp:Label ID="LabelClickImage" runat="server" /></p>
<br/><br/><h2><asp:Label ID="LabelUploadH2Header" Text="Upload Bank File LOC" runat="server" /></h2>
<div style="float:right;padding-left:10px;text-align:center"><a rel="leanModal" name="ModalDownloadInstructions" id="go" href="#ModalDownloadInstructions"><asp:Image ID="ImageDownloadInstructions" ImageUrl="~/Images/Ledgers/uploadbankfiles-seb-kontoutdrag-small.png" ImageAlign="Right" runat="server" /></a><small><br style="padding-bottom:2px"/><em><asp:Label ID="LabelClickImage" runat="server" /></em></small></div>
<h3><asp:Label ID="LabelDownloadInstructions" Text="Download File From Bank LOC" runat="server" /></h3>
<p><asp:Literal ID="LiteralDownloadInstructions" runat="server" Text="LOC" /><asp:Literal ID="LiteralLastAccountRecord" runat="server" /></p>
<div style="clear:both"></div>
<h3><asp:Label ID="LabelUploadH3Header" Text="Upload File To Activizr" runat="server" /></h3>
<h3><asp:Label ID="LabelUploadH3Header" Text="Upload File To Activizr LOC" runat="server" /></h3>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ButtonSebAccountFile" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<input type="file" id="file1" runat="server" name="file1" /> <asp:Button ID="Upload" OnClick="Submit_Click" Text="Upload" OnClientClick="onBeginUpload();" runat="server" />
<input type="file" id="FileSelector" runat="server" name="file1" /> <asp:Button ID="Upload" OnClick="Submit_Click" Text="Upload LOC" OnClientClick="onBeginUpload();" runat="server" ValidationGroup="Upload" /> <asp:Label ID="LabelNoFileUploaded" Text="" runat="server" />
</div>
<telerik:RadProgressManager ID="RadProgressManager1" runat="server" />
+43 -28
View File
@@ -5,6 +5,7 @@ using System.Web.UI;
using System.Web.UI.WebControls;
using Activizr.Basic.Enums;
using Activizr.Logic.Financial;
using Activizr.Logic.Security;
using Telerik.Web.UI;
using Telerik.Web.UI.Upload;
@@ -19,6 +20,7 @@ namespace Activizr.Site.Pages.Ledgers
{
this.PageTitle = Resources.Pages.Ledgers.UploadBankFiles_PageTitle;
this.PageIcon = "iconshock-bank";
this.PageAccessRequired = new Access(_currentOrganization, AccessAspect.Bookkeeping, AccessType.Write);
this.LabelSidebarInfo.Text = Resources.Pages.Global.Sidebar_Information;
this.LabelSidebarActions.Text = Resources.Pages.Global.Sidebar_Actions;
@@ -106,6 +108,8 @@ namespace Activizr.Site.Pages.Ledgers
protected void Submit_Click(object sender, EventArgs e)
{
bool fileWasUploaded = false;
foreach (string fileInputID in Request.Files)
{
UploadedFile file = UploadedFile.FromHttpPostedFile(Request.Files[fileInputID]);
@@ -113,41 +117,52 @@ namespace Activizr.Site.Pages.Ledgers
{
// TODO: PROCESS
// file.SaveAs("c:\\temp\\" + file.GetName());
RadProgressContext progress = RadProgressContext.Current;
progress.Speed = "N/A";
const int total = 100;
for (int i = 0; i < total; i++)
{
progress["PrimaryPercent"] = i.ToString();
progress["PrimaryTotal"] = total.ToString();
progress["PrimaryValue"] = i.ToString();
progress["SecondaryTotal"] = total.ToString();
progress["SecondaryValue"] = i.ToString();
progress["SecondaryPercent"] = i.ToString();
progress["PrimaryProgressBar"] = i.ToString();
progress["CurrentOperationText"] = "File is being processed...";
if (!Response.IsClientConnected)
{
//Cancel button was clicked or the browser was closed, so stop processing
break;
}
//Stall the current thread for 0.1 seconds
System.Threading.Thread.Sleep(100);
}
this.PanelFileTypeAccount.Visible = false;
this.PanelResults.Visible = true;
fileWasUploaded = true;
}
}
RadProgressContext progress = RadProgressContext.Current;
progress.Speed = "N/A";
const int total = 100;
for (int i = 0; i < total; i++)
if (!fileWasUploaded)
{
progress["PrimaryPercent"] = i.ToString();
progress["PrimaryTotal"] = total.ToString();
progress["PrimaryValue"] = i.ToString();
// If no file was uploaded, re-show the instructions div
progress["SecondaryTotal"] = total.ToString();
progress["SecondaryValue"] = i.ToString();
progress["SecondaryPercent"] = i.ToString();
progress["PrimaryProgressBar"] = i.ToString();
progress["CurrentOperationText"] = "File is being processed...";
if (!Response.IsClientConnected)
{
//Cancel button was clicked or the browser was closed, so stop processing
break;
}
//Stall the current thread for 0.1 seconds
System.Threading.Thread.Sleep(100);
this.LabelNoFileUploaded.Text = "Please upload a file LOC";
this.LiteralDivInstructionsStyle.Text = "style='display:inline'";
}
else
{
this.LabelNoFileUploaded.Text = string.Empty;
this.LiteralDivInstructionsStyle.Text = "style='display:none'";
}
this.PanelFileTypeAccount.Visible = false;
this.PanelResults.Visible = true;
}
}
}
+23
View File
@@ -0,0 +1,23 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="AccessDenied.aspx.cs" Inherits="Security_AccessDenied" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
<asp:Image runat="server" ImageAlign="Left" ID="DiscoImage" ImageUrl="~/Images/Icons/iconshock-disconnect-96px.png" /><h3>Access Denied [LOC]</h3><asp:Literal ID="LiteralAccessDeniedRant" Text="You have arrived at this page because you do not have the required clearance to access a page you selected. [LOC]" runat="server" />
<div style="clear:both"></div>
<br />Todo: Assist in changing organizations.
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderSide" Runat="Server">
<h2 class="blue"><asp:Label ID="LabelSidebarInfo" runat="server" Text="[LOC]" /><span class="arrow"></span></h2>
<div class="box">
<div class="content">
<asp:Label ID="LabelAccessDeniedInfo" runat="server" Text="[LOC]" />
</div>
</div>
</asp:Content>
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Security_AccessDenied : PageV5Base
{
protected void Page_Load(object sender, EventArgs e)
{
this.PageTitle = "Access Denied [LOC]";
this.PageIcon = "iconshock-disconnect";
}
}