From aaab58f4bd3ae95f199c3ff76925c4b791904ee3 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sat, 11 Jan 2014 09:39:07 +0000 Subject: [PATCH] Lots of work on log; half-ready Change Organizations; added sanitation of Json data --- Database/Database-Documents.cs | 2 +- Database/Database-SwarmopsLog.cs | 3 +- Logic/Support/Document.cs | 11 ++++-- .../CashAdvanceRequestedLogEntry.cs | 2 +- .../LogEntries/ExpenseClaimFiledLogEntry.cs | 2 +- .../Support/LogEntries/FinancialActionBase.cs | 2 +- Logic/Support/LogEntries/LogEntryBase.cs | 10 ++--- Logic/Support/SwarmopsLog.cs | 4 +- Logic/Support/SwarmopsLogEntry.cs | 2 +- Site5/App_Code/DataV5Base.cs | 5 +++ Site5/App_GlobalResources/Pages.Security.resx | 15 ++++++++ .../Json-ExpensableBudgetsTree.aspx.cs | 2 +- .../Json-TransactionTagsTree.aspx.cs | 2 +- .../iconshock-organizations-16px.png | Bin 0 -> 939 bytes .../iconshock-organizations-40px.png | Bin 0 -> 3786 bytes Site5/Master-v5.master | 6 +-- .../v5/Financial/Json-AttestableCosts.aspx.cs | 2 +- .../v5/Financial/Json-PayableCosts.aspx.cs | 8 ++-- .../Json-ValidatableReceipts.aspx.cs | 4 +- .../v5/Ledgers/Json-BalanceSheetData.aspx.cs | 2 +- .../Ledgers/Json-OutstandingAccounts.aspx.cs | 4 +- .../v5/Ledgers/Json-ProfitLossData.aspx.cs | 35 ++++------------- .../v5/Security/ChangeOrganizations.aspx | 33 ++++++++++++++++ .../v5/Security/ChangeOrganizations.aspx.cs | 36 ++++++++++++++++++ 24 files changed, 132 insertions(+), 60 deletions(-) create mode 100644 Site5/Images/PageIcons/iconshock-organizations-16px.png create mode 100644 Site5/Images/PageIcons/iconshock-organizations-40px.png create mode 100644 Site5/Pages/v5/Security/ChangeOrganizations.aspx create mode 100644 Site5/Pages/v5/Security/ChangeOrganizations.aspx.cs diff --git a/Database/Database-Documents.cs b/Database/Database-Documents.cs index 0a1f2cc8..e4f7d3db 100644 --- a/Database/Database-Documents.cs +++ b/Database/Database-Documents.cs @@ -30,7 +30,7 @@ namespace Swarmops.Database return ReadDocumentFromDataReader(reader); } - throw new ArgumentException("Unknown Account Id"); + throw new ArgumentException("Unknown Document Id"); } } } diff --git a/Database/Database-SwarmopsLog.cs b/Database/Database-SwarmopsLog.cs index d6c0c84f..c5b5b0b9 100644 --- a/Database/Database-SwarmopsLog.cs +++ b/Database/Database-SwarmopsLog.cs @@ -15,7 +15,7 @@ namespace Swarmops.Database private const string swarmopsLogFieldSequence = " SwarmopsLogEntryId,DateTime,PersonId,EntryTypeId,EntryXml " + // 0-4 - "FROM SwarmopsLog"; + "FROM SwarmopsLog "; private static BasicSwarmopsLogEntry ReadSwarmopsLogEntryFromDataReader(IDataRecord reader) { @@ -104,6 +104,7 @@ namespace Swarmops.Database AddParameterWithName(command, "personId", personId); AddParameterWithName(command, "entryType", entryType); AddParameterWithName(command, "entryXml", entryXml); + AddParameterWithName(command, "dateTime", DateTime.UtcNow); return Convert.ToInt32(command.ExecuteScalar()); } diff --git a/Logic/Support/Document.cs b/Logic/Support/Document.cs index 7007b15f..0b220794 100644 --- a/Logic/Support/Document.cs +++ b/Logic/Support/Document.cs @@ -18,12 +18,17 @@ namespace Swarmops.Logic.Support } - public static Document FromIdentity (int documentId) + public static Document FromIdentity(int documentId) { return FromBasic(SwarmDb.GetDatabaseForReading().GetDocument(documentId)); } - public static Document FromBasic (BasicDocument basicDocument) + public static Document FromIdentityAggressive(int documentId) + { + return FromBasic(SwarmDb.GetDatabaseForWriting().GetDocument(documentId)); // "For writing" is intentional - bypasses a race condition in replication + } + + public static Document FromBasic(BasicDocument basicDocument) { return new Document(basicDocument); } @@ -34,7 +39,7 @@ namespace Swarmops.Logic.Support int newDocumentId = SwarmDb.GetDatabaseForWriting(). CreateDocument(serverFileName, clientFileName, fileSize, description, GetDocumentTypeForObject(identifiableObject), identifiableObject == null? 0: identifiableObject.Identity, uploader.Identity); - return FromIdentity(newDocumentId); + return FromIdentityAggressive(newDocumentId); } public static DocumentType GetDocumentTypeForObject (IHasIdentity foreignObject) diff --git a/Logic/Support/LogEntries/CashAdvanceRequestedLogEntry.cs b/Logic/Support/LogEntries/CashAdvanceRequestedLogEntry.cs index 6619b702..07343636 100644 --- a/Logic/Support/LogEntries/CashAdvanceRequestedLogEntry.cs +++ b/Logic/Support/LogEntries/CashAdvanceRequestedLogEntry.cs @@ -25,7 +25,7 @@ namespace Swarmops.Logic.Support.LogEntries this.FinancialAccountId = budget.Identity; this.FinancialAccountName = budget.Name; // redundancy in case of future name changes this.OwnerPersonId = budget.OwnerPersonId; - this.OwnerPersonName = budget.Owner.Name; + this.OwnerPersonName = budget.OwnerPersonId != 0 ? budget.Owner.Name : string.Empty; this.ActingPersonId = actingPerson.Identity; // do not save name for data retention reasons this.BeneficiaryPersonId = beneficiaryPerson.Identity; } diff --git a/Logic/Support/LogEntries/ExpenseClaimFiledLogEntry.cs b/Logic/Support/LogEntries/ExpenseClaimFiledLogEntry.cs index 44ae9871..c4b8d428 100644 --- a/Logic/Support/LogEntries/ExpenseClaimFiledLogEntry.cs +++ b/Logic/Support/LogEntries/ExpenseClaimFiledLogEntry.cs @@ -25,7 +25,7 @@ namespace Swarmops.Logic.Support.LogEntries this.FinancialAccountId = budget.Identity; this.FinancialAccountName = budget.Name; // redundancy in case of future name changes this.OwnerPersonId = budget.OwnerPersonId; - this.OwnerPersonName = budget.Owner.Name; + this.OwnerPersonName = budget.OwnerPersonId != 0 ? budget.Owner.Name : string.Empty; this.ActingPersonId = filingPerson.Identity; // do not save name for data retention reasons this.BeneficiaryPersonId = beneficiaryPerson.Identity; } diff --git a/Logic/Support/LogEntries/FinancialActionBase.cs b/Logic/Support/LogEntries/FinancialActionBase.cs index 344abc0a..e506c7a1 100644 --- a/Logic/Support/LogEntries/FinancialActionBase.cs +++ b/Logic/Support/LogEntries/FinancialActionBase.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using Swarmops.Logic.Support.Log; + namespace Swarmops.Logic.Support.LogEntries { diff --git a/Logic/Support/LogEntries/LogEntryBase.cs b/Logic/Support/LogEntries/LogEntryBase.cs index 94f67a12..bab06ee5 100644 --- a/Logic/Support/LogEntries/LogEntryBase.cs +++ b/Logic/Support/LogEntries/LogEntryBase.cs @@ -1,18 +1,16 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; using System.Xml.Serialization; -namespace Swarmops.Logic.Support.Log +namespace Swarmops.Logic.Support.LogEntries { [Serializable] public class LogEntryBase: IXmlPayload { - public string ToXml() + public virtual string ToXml() { - var serializer = new XmlSerializer(typeof(T)); + var serializer = new XmlSerializer(this.GetType()); var stream = new MemoryStream(); serializer.Serialize(stream, this); @@ -21,7 +19,7 @@ namespace Swarmops.Logic.Support.Log return Encoding.UTF8.GetString(xmlBytes); } - public static T FromXml (string xml) + public static T FromXml (string xml) // 'T' might not work here, like it didn't in ToXml() { // Compensate for stupid Mono encoding bugs diff --git a/Logic/Support/SwarmopsLog.cs b/Logic/Support/SwarmopsLog.cs index fe1fbbe9..a01f4680 100644 --- a/Logic/Support/SwarmopsLog.cs +++ b/Logic/Support/SwarmopsLog.cs @@ -13,9 +13,9 @@ namespace Swarmops.Logic.Support { string logEntryClass = logEntry.GetType().ToString(); - if (logEntryClass.StartsWith("Swarmops.Logic.Support.Logentries.")) + if (logEntryClass.StartsWith("Swarmops.Logic.Support.LogEntries.")) { - logEntryClass = logEntryClass.Substring("Swarmops.Logic.Support.Logentries.".Length); + logEntryClass = logEntryClass.Substring("Swarmops.Logic.Support.LogEntries.".Length); } int logEntryId = SwarmDb.GetDatabaseForWriting().CreateSwarmopsLogEntry( diff --git a/Logic/Support/SwarmopsLogEntry.cs b/Logic/Support/SwarmopsLogEntry.cs index a30ce3a5..0968ef57 100644 --- a/Logic/Support/SwarmopsLogEntry.cs +++ b/Logic/Support/SwarmopsLogEntry.cs @@ -54,7 +54,7 @@ namespace Swarmops.Logic.Support string className = affectedObject.GetType().ToString(); int dotIndex = className.LastIndexOf('.'); - className = className.Substring(dotIndex); // assumes there's always at least one dot in a class name + className = className.Substring(dotIndex + 1); // assumes there's always at least one dot in a class name SwarmDb.GetDatabaseForWriting().CreateSwarmopsLogEntryAffectedObject(this.Identity, className, affectedObject.Identity); diff --git a/Site5/App_Code/DataV5Base.cs b/Site5/App_Code/DataV5Base.cs index beb70ace..8d1feefd 100644 --- a/Site5/App_Code/DataV5Base.cs +++ b/Site5/App_Code/DataV5Base.cs @@ -215,5 +215,10 @@ public class DataV5Base : System.Web.UI.Page } + protected static string JsonSanitize (string input) + { + return input.Replace("\"", "\\\""); + } + } diff --git a/Site5/App_GlobalResources/Pages.Security.resx b/Site5/App_GlobalResources/Pages.Security.resx index 70cbd2dc..44bf5782 100644 --- a/Site5/App_GlobalResources/Pages.Security.resx +++ b/Site5/App_GlobalResources/Pages.Security.resx @@ -129,4 +129,19 @@ <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> + + 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. + + + New organization + + + Change Organizations + + + Switch + \ No newline at end of file diff --git a/Site5/Automation/Json-ExpensableBudgetsTree.aspx.cs b/Site5/Automation/Json-ExpensableBudgetsTree.aspx.cs index edc9917d..0347430a 100644 --- a/Site5/Automation/Json-ExpensableBudgetsTree.aspx.cs +++ b/Site5/Automation/Json-ExpensableBudgetsTree.aspx.cs @@ -78,7 +78,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial foreach (FinancialAccount account in treeMap[node]) { string element = string.Format("\"id\":{0},\"text\":\"{1}\"", account.Identity, - account.Name.Replace("\"", "\\\"")); + JsonSanitize(account.Name)); if (treeMap.ContainsKey(account.Identity)) { diff --git a/Site5/Automation/Json-TransactionTagsTree.aspx.cs b/Site5/Automation/Json-TransactionTagsTree.aspx.cs index a368973b..16b36688 100644 --- a/Site5/Automation/Json-TransactionTagsTree.aspx.cs +++ b/Site5/Automation/Json-TransactionTagsTree.aspx.cs @@ -88,7 +88,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial foreach (FinancialTransactionTagType tagType in treeMap[node]) { string element = string.Format("\"id\":{0},\"text\":\"{1}\"", tagType.Identity, - tagType.Name.Replace("\"", "\\\"")); + JsonSanitize(tagType.Name)); if (treeMap.ContainsKey(tagType.Identity)) { diff --git a/Site5/Images/PageIcons/iconshock-organizations-16px.png b/Site5/Images/PageIcons/iconshock-organizations-16px.png new file mode 100644 index 0000000000000000000000000000000000000000..51728bdd2f182d811cf28d31787d1ef83e0b52f8 GIT binary patch literal 939 zcmV;c162HpP)!4<*rRbRPf!12{=U zK~y-)g_3P(TLlz`pPRHvmh@}w(luS}itT9anypb=p>sHin=2?2Wr#RLR=+?hqN0Vm zO(xNS4it4PLd)u$&R@cq4okOAE3&m(9ILf+YtrVk$xYIm-kYyBxz``VvLC}ee_zgf z4u?nJe>nctx4iP)GkkvH^sa?eZvV`z*Rzy}jcv$@qpuxuWgRU|2;706#x4ayOSui< zgrr@c4+@eb@mNQzzvt;E>H%~B6PgCVJMXy~`dlA7ZY^l6vsp>WJlftOY+Ad9ib9&H z>6!e0xej3X*kI?$A1+*RY%}}i^St`&&0@? z#?=eF{*dbN_=MW>5*n+@$jM2POA2+{9uK!{Z8zE5Hd9e!CN9lZQxHx`qjG^rUS*MYvv zMF5egSWuP}#HdI%n_~Q*IUKE<$Q2UQmX~su&C0%=U0BR!h9{<|wiuSbKYeNdpy=i+ z)cSZlj+|1^>7iU#ARLLYsN|?wS4C1zan0kWW?d!Wh)Bv+zCe&2+dAz->Kl-7;f#KSQyC*!Mm@%D6 zH*MKs*Q=^3W)&rx%`UGM;|U6dJZ7_rk*l+qwH4<4f!w8^M~(pK9L_x)?tA0Mfg}BU zhd%khC@=UPe7E<7^|{=#FA^2WujH8ZdPztU&6Q?EF-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%h}MxtZ@Snc?`J3;&=e}=ltteGta(b3TJc`Hd z#^rRNsv1KhV>lg7qLCnezYn>h(AC_`*3J}ar9>(g#xf1YC#MMeylAJZsNWoW05)B8 zB~Lu~YBkW`A8c=JIww~w(l89VyO!hedXOt8tTQw+ zN+K2|nMfcAoX95C8j4cIFigOrP$)1xGfQ(SX>WbcxmzB1k8kh2Z|g-DU$QS43WxfKCkaQwjE_%XnkF8vheRw!G8Ly%sW3A$LnIm@6bz!& z>L}G3wq;Q+lqgjyeCCFav;93=gqcjv{;NB_6W!U{{>zts{#*jc|6bFrC!gMTOBwe+ zMgu|GlM!;cJn4l+@`VzIjtnDL6l~jKVrq(fzCc@B3&CIzf56Yq3(hB-T_Qa{&*t@K zuxY~?(a0#3S< z2}-4c?1}_Gb^RxA%Kf^c`JDilZN9*{@A(%S4a*|g)FNzJ(Z*|9-LBb!@W@LC$mjE@ zb(PJlI@x~C**F{$g<^?c9T;F}WQ^r)%_QP6zWw-f96mNm(k-&3qX|iX)_C}CpWF4X zx8L^FnWr9kh)b@x@^>F#ZoT+J!qD;QnAhc8f6b-mU%hGLnL9j@L{Gk|OT}V=qa$N> zc4NkbS|RpUvxf?WR;xXl`z0adDA}iSeHw863RjzwW*3z*{%} zuFR<4x`3x^lhfmJHGg>LxmN^yzCNeNySk^l+qtYcrTp-LpMLH;_xB=XZVZx*Ixw%M&|xomS`n0yLgLqpcM8-T(jq07*qoM6N<$f)9^R A%>V!Z literal 0 HcmV?d00001 diff --git a/Site5/Master-v5.master b/Site5/Master-v5.master index 1f12967b..96553fb8 100644 --- a/Site5/Master-v5.master +++ b/Site5/Master-v5.master @@ -33,7 +33,7 @@ + + + + +
+ ​
+ + + +
+ +
+ + + + diff --git a/Site5/Pages/v5/Security/ChangeOrganizations.aspx.cs b/Site5/Pages/v5/Security/ChangeOrganizations.aspx.cs new file mode 100644 index 00000000..0d50bcd2 --- /dev/null +++ b/Site5/Pages/v5/Security/ChangeOrganizations.aspx.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace Swarmops.Frontend.Pages.Security +{ + public partial class ChangeOrganizations : PageV5Base + { + protected void Page_Load(object sender, EventArgs e) + { + if (!Page.IsPostBack) + { + Localize(); + } + + 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) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file