Lots of work on Account Plan; Mono test required
This commit is contained in:
@@ -34,7 +34,7 @@ namespace Swarmops.Basic.Types.Financial
|
||||
public int OrganizationId { get; private set; }
|
||||
public FinancialAccountType AccountType { get; private set; }
|
||||
public int OwnerPersonId { get; protected set; }
|
||||
public int ParentFinancialAccountId { get; private set; }
|
||||
public int ParentFinancialAccountId { get; protected set; }
|
||||
public bool Open { get; protected set; }
|
||||
public int OpenedYear { get; protected set; }
|
||||
public int ClosedYear { get; protected set; }
|
||||
|
||||
@@ -49,6 +49,9 @@ namespace Swarmops.Database
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The actual revision of the database (as told by the database).
|
||||
/// </summary>
|
||||
public static int DbVersion
|
||||
{
|
||||
get
|
||||
@@ -67,6 +70,14 @@ namespace Swarmops.Database
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is the IN-CODE revision of the database. The version we expect to be running against.
|
||||
/// </summary>
|
||||
public static int DbVersionExpected
|
||||
{
|
||||
get { return 2; }
|
||||
}
|
||||
|
||||
|
||||
[Obsolete ("Do not use. Use SwarmDb.GetDatabaseForReading(), ...ForWriting() or ...ForAdmin().", true)]
|
||||
public static SwarmDb GetDatabase()
|
||||
|
||||
@@ -679,6 +679,134 @@ namespace Swarmops.Database
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFinancialAccountClosedYear(int financialAccountId, int closedYear)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetFinancialAccountClosedYear", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "financialAccountId", financialAccountId);
|
||||
AddParameterWithName(command, "closedYear", closedYear);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFinancialAccountParent(int financialAccountId, int parentFinancialAccountId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetFinancialAccountParent", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "financialAccountId", financialAccountId);
|
||||
AddParameterWithName(command, "parentFinancialAccountId", parentFinancialAccountId);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFinancialAccountActive(int financialAccountId, bool active)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetFinancialAccountActive", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "financialAccountId", financialAccountId);
|
||||
AddParameterWithName(command, "active", active);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFinancialAccountExpensable(int financialAccountId, bool expensable)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetFinancialAccountExpensable", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "financialAccountId", financialAccountId);
|
||||
AddParameterWithName(command, "expensable", expensable);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFinancialAccountOpen(int financialAccountId, bool open)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetFinancialAccountOpen", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "financialAccountId", financialAccountId);
|
||||
AddParameterWithName(command, "open", open);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFinancialAccountAdministrative(int financialAccountId, bool administrative)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetFinancialAccountOpen", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "financialAccountId", financialAccountId);
|
||||
AddParameterWithName(command, "administrative", administrative);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFinancialAccountLinkBackward(int financialAccountId, int linkBackward)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetFinancialAccountOwner", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "financialAccountId", financialAccountId);
|
||||
AddParameterWithName(command, "linkBackward", linkBackward);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFinancialAccountLinkForward(int financialAccountId, int linkForward)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetFinancialAccountOwner", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "financialAccountId", financialAccountId);
|
||||
AddParameterWithName(command, "linkForward", linkForward);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFinancialAccountOwner(int financialAccountId, int ownerPersonId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
0001 - Initial baseline, Rick Falkvinge
|
||||
0002 - Added functions for account plan maintenance and back/forward links to FinancialAccounts, Rick Falkvinge
|
||||
@@ -148,7 +148,31 @@ namespace Swarmops.Logic.Financial
|
||||
|
||||
public FinancialAccount Parent
|
||||
{
|
||||
get { return FromIdentity(this.ParentFinancialAccountId); }
|
||||
get
|
||||
{
|
||||
return FromIdentity(this.ParentFinancialAccountId);
|
||||
}
|
||||
set
|
||||
{
|
||||
// We do not change the parent lightly. It cannot be changed if this account has transactions
|
||||
// in closedledger space.
|
||||
|
||||
try
|
||||
{
|
||||
int yearClosed = this.Organization.Parameters.FiscalBooksClosedUntilYear;
|
||||
if (this.OpenedYear >= yearClosed)
|
||||
{
|
||||
throw new InvalidOperationException("Can't reparent an account with transactions in closedledger space");
|
||||
}
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// This is ok. OpenedYear can throw an ArgumentException if there aren't any transactions yet.
|
||||
}
|
||||
|
||||
base.ParentFinancialAccountId = value.Identity;
|
||||
SwarmDb.GetDatabaseForWriting().SetFinancialAccountParent(this.Identity, value.Identity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +195,7 @@ namespace Swarmops.Logic.Financial
|
||||
{
|
||||
// HACK HACK HACK HACK HACK for our pilots; this will be softcoded later TODO
|
||||
|
||||
if (this.OrganizationId != 1 || this.Organization.Name != "Piratpartiet SE")
|
||||
if (this.OrganizationId != 1 || !PilotInstallationIds.IsPilot(PilotInstallationIds.PiratePartySE))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -194,7 +218,19 @@ namespace Swarmops.Logic.Financial
|
||||
get { return base.Name; }
|
||||
set
|
||||
{
|
||||
// TODO: OPENEDYEAR TEST
|
||||
try
|
||||
{
|
||||
int yearClosed = this.Organization.Parameters.FiscalBooksClosedUntilYear;
|
||||
if (this.OpenedYear >= yearClosed)
|
||||
{
|
||||
throw new InvalidOperationException("Can't rename an account with transactions in closedledger space");
|
||||
}
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// This is ok and can be thrown if OpenedYear throws because there are no transactions yet.
|
||||
}
|
||||
|
||||
SwarmDb.GetDatabaseForWriting().SetFinancialAccountName(this.Identity, value);
|
||||
base.Name = value;
|
||||
}
|
||||
|
||||
@@ -56,8 +56,8 @@ namespace Swarmops.Logic.Support
|
||||
|
||||
static public void UpgradeSchemata()
|
||||
{
|
||||
int currentDbVersion = Int32.Parse(SwarmDb.GetDatabaseForReading().GetKeyValue("DbVersion"));
|
||||
int expectedDbVersion = SwarmDb.DbVersion;
|
||||
int currentDbVersion = SwarmDb.DbVersion;
|
||||
int expectedDbVersion = SwarmDb.DbVersionExpected;
|
||||
string sql;
|
||||
bool upgraded = false;
|
||||
|
||||
|
||||
@@ -126,6 +126,13 @@ public class PageV5Base : System.Web.UI.Page
|
||||
Response.Redirect("/Pages/v5/Security/AccessDenied.aspx");
|
||||
}
|
||||
|
||||
// Check necessary database revision
|
||||
|
||||
if (this.DbVersionRequired > SwarmDb.DbVersion)
|
||||
{
|
||||
Response.Redirect("/Pages/v5/Security/DatabaseUpgradeRequired.aspx");
|
||||
}
|
||||
|
||||
base.OnPreRender(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -112,10 +112,10 @@
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="AccessDenied_Header" xml:space="preserve">
|
||||
<value>Access to this page was denied</value>
|
||||
@@ -127,7 +127,7 @@
|
||||
<value>Access Denied</value>
|
||||
</data>
|
||||
<data name="AccessDenied_Rant" xml:space="preserve">
|
||||
<value><p>The Activizr security framework has denied you access to the page you were trying to go to. This usually means that its functions were above the access levels granted to you for the currently selected organization (<em>{0}</em>). This has not been logged nor reported anywhere.</p><p>There are several reasons why this may have happened:</p></value>
|
||||
<value><p>The Swarmops security framework has denied you access to the page you were trying to go to. This usually means that its functions were above the access levels granted to you for the currently selected organization (<em>{0}</em>). This has not been logged nor reported anywhere.</p><p>There are several reasons why this may have happened:</p></value>
|
||||
</data>
|
||||
<data name="ChangeOrganizations_CurrentOrganization" xml:space="preserve">
|
||||
<value>Current organization</value>
|
||||
@@ -144,4 +144,17 @@
|
||||
<data name="ChangeOrganizations_Switch" xml:space="preserve">
|
||||
<value>Switch</value>
|
||||
</data>
|
||||
<data name="DatabaseUpgradeRequired_Header" xml:space="preserve">
|
||||
<value>Database Upgrade Pending</value>
|
||||
</data>
|
||||
<data name="DatabaseUpgradeRequired_Info" xml:space="preserve">
|
||||
<value>This page requires an upgraded Swarmops database. </value>
|
||||
</data>
|
||||
<data name="DatabaseUpgradeRequired_PageTitle" xml:space="preserve">
|
||||
<value>Awaiting Database Upgrade</value>
|
||||
</data>
|
||||
<data name="DatabaseUpgradeRequired_Rant" xml:space="preserve">
|
||||
<value><p>There is a database upgrade pending that prevents your access to this page. <strong>This is a temporary condition</strong> and the Swarmops servers should already be working on performing the necessary upgrade.</p>
|
||||
<p>Retry loading the page in a few minutes. If the condition persists for more than fifteen minutes, contact your system administrator.</p></value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -7,8 +7,14 @@
|
||||
height: 30 <%
|
||||
if (!String.IsNullOrEmpty(this.OnClientLoaded))
|
||||
{
|
||||
Response.Write(", onLoadSuccess: " + this.OnClientLoaded + "()");
|
||||
}%>
|
||||
Response.Write(", onLoadSuccess: function() { " + this.OnClientLoaded + "(); }");
|
||||
}
|
||||
if (!String.IsNullOrEmpty(this.OnClientSelect))
|
||||
{
|
||||
Response.Write(", onSelect: function(account) { " + this.OnClientSelect + "(account.id); }");
|
||||
}
|
||||
|
||||
%>
|
||||
});
|
||||
|
||||
$('#<%=this.ClientID %>_SpanBudgets span.combo input.combo-text').click(function () {
|
||||
|
||||
@@ -15,5 +15,6 @@ namespace Swarmops.Controls.Financial
|
||||
}
|
||||
|
||||
public string OnClientLoaded { get; set; }
|
||||
public string OnClientSelect { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -330,8 +330,14 @@
|
||||
}
|
||||
|
||||
|
||||
function onAccountTreeSelect() {
|
||||
alert('bar');
|
||||
}
|
||||
|
||||
|
||||
function onAccountTreeLoaded() {
|
||||
// this didn't work much - not called on "reload"
|
||||
// this didn't work much - not called on "reload"
|
||||
alert('foo2');
|
||||
accountTreeLoaded = true;
|
||||
if (parentAccountName.length > 0) {
|
||||
$('#<%=DropParents.ClientID %>_DropBudgets').combotree('setText', parentAccountName);
|
||||
@@ -398,7 +404,7 @@
|
||||
<div class="content">
|
||||
<div style="float:right;margin-top: 2px;margin-right: -5px"><img id="IconCloseEdit" src="/Images/Icons/iconshock-cross-16px.png" /></div><h2 id="HeaderModal">Editing account (Under Construction/Test until next sprint)</h2>
|
||||
<div id="DivModalFields" class="entryFields"><input type="text" id="TextAccountName" /> <br />
|
||||
<Swarmops5:ComboBudgets ID="DropParents" runat="server" OnClientLoaded="onAccountTreeLoaded" /> <br/>
|
||||
<Swarmops5:ComboBudgets ID="DropParents" runat="server" OnClientLoaded="onAccountTreeLoaded" OnClientSelect="onAccountTreeSelect" /> <br/>
|
||||
<br/>
|
||||
<div id="DivEditProfitLossControls"><Swarmops5:ComboPeople ID="DropOwner" OnClientSelect="onOwnerChange" runat="server" /> <br/>
|
||||
<input type="text" id="TextAccountBudget" style="text-align: right"/> <br/>
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
this.PageTitle = Resources.Pages.Ledgers.AccountPlan_PageTitle;
|
||||
this.InfoBoxLiteral = Resources.Pages.Ledgers.AccountPlan_Info;
|
||||
this.PageAccessRequired = new Access(this.CurrentOrganization, AccessAspect.Bookkeeping, AccessType.Write);
|
||||
this.DbVersionRequired = 2; // Account reparenting
|
||||
}
|
||||
|
||||
|
||||
@@ -117,6 +118,27 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
return true;
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public static bool SetAccountParent (int accountId, int parentAccountId)
|
||||
{
|
||||
AuthenticationData authData = GetAuthenticationDataAndCulture();
|
||||
FinancialAccount account = FinancialAccount.FromIdentity(accountId);
|
||||
|
||||
if (!PrepareAccountChange(account, authData, true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
FinancialAccount newParent = FinancialAccount.FromIdentity(parentAccountId);
|
||||
if (newParent.OrganizationId != authData.CurrentOrganization.Identity)
|
||||
{
|
||||
throw new ArgumentException("Parent account mismatches with organization identity");
|
||||
}
|
||||
|
||||
account.Parent = newParent;
|
||||
return true;
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public static bool SetAccountOwner(int accountId, int newOwnerId)
|
||||
{
|
||||
@@ -128,7 +150,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Verify that authdata.AuthenticatedPerson can see personId, or this can be exploited to enumerate all people
|
||||
// TODO SECURITY: Verify that authdata.AuthenticatedPerson can see personId, or this can be exploited to enumerate all people
|
||||
|
||||
account.Owner = Person.FromIdentity(newOwnerId);
|
||||
return true;
|
||||
|
||||
@@ -13,12 +13,5 @@
|
||||
</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>
|
||||
|
||||
|
||||
@@ -12,8 +12,7 @@ public partial class Security_AccessDenied : PageV5Base
|
||||
this.PageIcon = "iconshock-disconnect";
|
||||
|
||||
this.LabelAccessDeniedHeader.Text = Resources.Pages.Security.AccessDenied_Header;
|
||||
this.LabelSidebarInfo.Text = Resources.Global.Sidebar_Information;
|
||||
this.LabelAccessDeniedInfo.Text = Resources.Pages.Security.AccessDenied_Info;
|
||||
this.InfoBoxLiteral = Resources.Pages.Security.AccessDenied_Info;
|
||||
this.LiteralAccessDeniedRant.Text = String.Format(Resources.Pages.Security.AccessDenied_Rant, this.CurrentOrganization.Name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="DatabaseUpgradeRequired.aspx.cs" Inherits="Security_DatabaseUpgradeRequired" %>
|
||||
|
||||
<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><asp:Label runat="server" ID="LabelDbUpgradeRequiredHeader" Text="[LOC]" /></h3><asp:Literal ID="LiteralDbUpgradeRequiredRant" Text="You have arrived at this page because a database upgrade is pending. [LOC]" runat="server" />
|
||||
|
||||
</asp:Content>
|
||||
|
||||
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderSide" Runat="Server">
|
||||
</asp:Content>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
public partial class Security_DatabaseUpgradeRequired : PageV5Base
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
this.PageTitle = Resources.Pages.Security.DatabaseUpgradeRequired_PageTitle;
|
||||
this.PageIcon = "iconshock-disconnect";
|
||||
|
||||
this.LabelDbUpgradeRequiredHeader.Text = Resources.Pages.Security.DatabaseUpgradeRequired_Header;
|
||||
this.InfoBoxLiteral = Resources.Pages.Security.DatabaseUpgradeRequired_Info;
|
||||
this.LiteralDbUpgradeRequiredRant.Text = Resources.Pages.Security.DatabaseUpgradeRequired_Rant;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user