Lots of work on log; half-ready Change Organizations; added sanitation of Json data
This commit is contained in:
@@ -30,7 +30,7 @@ namespace Swarmops.Database
|
||||
return ReadDocumentFromDataReader(reader);
|
||||
}
|
||||
|
||||
throw new ArgumentException("Unknown Account Id");
|
||||
throw new ArgumentException("Unknown Document Id");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Swarmops.Logic.Support.Log;
|
||||
|
||||
|
||||
namespace Swarmops.Logic.Support.LogEntries
|
||||
{
|
||||
|
||||
@@ -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<T>: 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
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -215,5 +215,10 @@ public class DataV5Base : System.Web.UI.Page
|
||||
}
|
||||
|
||||
|
||||
protected static string JsonSanitize (string input)
|
||||
{
|
||||
return input.Replace("\"", "\\\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -129,4 +129,19 @@
|
||||
<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>
|
||||
</data>
|
||||
<data name="ChangeOrganizations_CurrentOrganization" xml:space="preserve">
|
||||
<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>
|
||||
</data>
|
||||
<data name="ChangeOrganizations_NewOrganization" xml:space="preserve">
|
||||
<value>New organization</value>
|
||||
</data>
|
||||
<data name="ChangeOrganizations_PageTitle" xml:space="preserve">
|
||||
<value>Change Organizations</value>
|
||||
</data>
|
||||
<data name="ChangeOrganizations_Switch" xml:space="preserve">
|
||||
<value>Switch</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 939 B |
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
@@ -33,7 +33,7 @@
|
||||
|
||||
<!-- initialize all jQuery stuff -->
|
||||
<script language="javascript" type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$(document).ready(function () {/*
|
||||
$('#LinkChangeOrganizations').qtip(
|
||||
{
|
||||
id: 'TooltipModalOrganizationChanger', // Since we're only creating one modal, give it an ID so we can style it
|
||||
@@ -64,7 +64,7 @@
|
||||
classes: 'qtip-light qtip-rounded qtip-modal',
|
||||
tip: false
|
||||
}
|
||||
});
|
||||
});*/
|
||||
|
||||
$("a[rel*=leanModal]").leanModal();
|
||||
|
||||
@@ -111,7 +111,7 @@
|
||||
<div class="center980px">
|
||||
<div class="currentuserinfo">
|
||||
<div style="background-image:url('/Images/Icons/iconshock-user-16px.png');background-repeat:no-repeat;padding-left:16px;float:left"><asp:Label ID="LabelCurrentUserName" runat="server" /> | </div>
|
||||
<div style="background-image:url('/Images/Icons/iconshock-workchair-16px.png');background-repeat:no-repeat;padding-left:17px;float:left"><span class="hasTooltip" rel="Logged into <%=this.CurrentOrganization.Name %>" title="Click here to switch to another organization."><a href="#" id="LinkChangeOrganizations"><asp:Label ID="LabelCurrentOrganizationName" runat="server" /></a></span> | </div>
|
||||
<div style="background-image:url('/Images/Icons/iconshock-workchair-16px.png');background-repeat:no-repeat;padding-left:17px;float:left"><span class="hasTooltip" rel="Logged into <%=this.CurrentOrganization.Name %>" title="Click here to switch to another organization."><a href="/Pages/v5/Security/ChangeOrganizations.aspx" id="LinkChangeOrganizations"><asp:Label ID="LabelCurrentOrganizationName" runat="server" /></a></span> | </div>
|
||||
<div style="background-image:url('/Images/Icons/iconshock-gamepad-16px.png');background-repeat:no-repeat;padding-left:20px;float:left"><asp:Label ID="LabelPreferences" runat="server" /> | </div>
|
||||
<div style="background-image:url('/Images/Icons/iconshock-lock-16px.png');background-repeat:no-repeat;padding-left:16px;float:left"><asp:LinkButton ID="LinkLogout" runat="server" OnClick="LinkLogout_Click" /> | </div>
|
||||
<asp:Image ID="ImageCultureIndicator" runat="server" ImageUrl="~/Images/Flags/uk.png" /> <asp:LinkButton ID="LinkTranslate" Visible="false" Text="Translate Into" OnClick="LinkTranslate_Click" runat="server" />
|
||||
|
||||
@@ -56,7 +56,7 @@ public partial class Pages_v5_Finance_Json_AttestableCosts : DataV5Base
|
||||
"<img id=\\\"IconApproved{5}\\\" class=\\\"LocalIconApproved\\\" baseid=\\\"{5}\\\" height=\\\"16\\\" width=\\\"16\\\" /> " +
|
||||
"<img id=\\\"IconDenial{5}\\\" class=\\\"LocalIconDenial\\\" baseid=\\\"{5}\\\" height=\\\"16\\\" width=\\\"16\\\" />" +
|
||||
"<img id=\\\"IconDenied{5}\\\" class=\\\"LocalIconDenied\\\" baseid=\\\"{5}\\\" height=\\\"16\\\" width=\\\"16\\\" /></span>\"",
|
||||
GetGlobalResourceObject("Global", item.IdentityDisplay).ToString(), item.Beneficiary, TryLocalize(item.Description), item.BudgetName,
|
||||
JsonSanitize(GetGlobalResourceObject("Global", item.IdentityDisplay).ToString()), JsonSanitize(item.Beneficiary), JsonSanitize(TryLocalize(item.Description)), JsonSanitize(item.BudgetName),
|
||||
item.AmountRequestedCents/100.0, item.Identity);
|
||||
result.Append("},");
|
||||
}
|
||||
|
||||
@@ -62,10 +62,10 @@ namespace Swarmops.Frontend.Pages.Financial
|
||||
"<img id=\\\"IconApproved{7}\\\" class=\\\"LocalIconApproved\\\" baseid=\\\"{0}\\\" height=\\\"16\\\" width=\\\"16\\\" />\"",
|
||||
payout.ProtoIdentity,
|
||||
(payout.ExpectedTransactionDate <= today? Resources.Global.Global_ASAP: payout.ExpectedTransactionDate.ToShortDateString()),
|
||||
TryLocalize(payout.Recipient),
|
||||
payout.Bank,
|
||||
payout.Account,
|
||||
TryLocalize(payout.Reference),
|
||||
JsonSanitize(TryLocalize(payout.Recipient)),
|
||||
JsonSanitize(payout.Bank),
|
||||
JsonSanitize(payout.Account),
|
||||
JsonSanitize(TryLocalize(payout.Reference)),
|
||||
payout.AmountCents/100.0,
|
||||
payout.ProtoIdentity.Replace("|", ""));
|
||||
result.Append("},");
|
||||
|
||||
@@ -69,8 +69,8 @@ public partial class Pages_v5_Finance_Json_ValidatableReceipts : DataV5Base
|
||||
"<img id=\\\"IconApprovedE{5}\\\" class=\\\"LocalIconApproved\\\" baseid=\\\"E{5}\\\" height=\\\"16\\\" width=\\\"16\\\" /> " +
|
||||
"<img id=\\\"IconDenialE{5}\\\" class=\\\"LocalIconDenial\\\" baseid=\\\"E{5}\\\" height=\\\"16\\\" width=\\\"16\\\" />" +
|
||||
"<img id=\\\"IconDeniedE{5}\\\" class=\\\"LocalIconDenied\\\" baseid=\\\"E{5}\\\" height=\\\"16\\\" width=\\\"16\\\" /></span>\"",
|
||||
"olditem", claim.ClaimerCanonical, claim.Description, claim.Budget.Name,
|
||||
claim.AmountCents/100.0, claim.Identity, extraTags.ToString());
|
||||
"olditem", JsonSanitize(claim.ClaimerCanonical), JsonSanitize(claim.Description), JsonSanitize(claim.Budget.Name),
|
||||
claim.AmountCents/100.0, claim.Identity, JsonSanitize(extraTags.ToString()));
|
||||
result.Append("},");
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ public partial class Pages_v5_Ledgers_Json_BalanceSheetData : DataV5Base
|
||||
foreach (YearlyReportLine line in reportLines)
|
||||
{
|
||||
string element = string.Format("\"id\":{0},\"name\":\"{1}\"", line.AccountId,
|
||||
line.AccountName.Replace("\"", "'"));
|
||||
JsonSanitize(line.AccountName));
|
||||
|
||||
if (line.Children.Count > 0)
|
||||
{
|
||||
|
||||
@@ -173,8 +173,8 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
account.Identity,
|
||||
account.CreatedDateTime.ToShortDateString(),
|
||||
(account.ExpectedClosed.Year <= 1950 ? Resources.Global.Global_NA : account.ExpectedClosed.ToShortDateString()),
|
||||
account.Recipient,
|
||||
account.Description,
|
||||
JsonSanitize(account.Recipient),
|
||||
JsonSanitize(account.Description),
|
||||
account.AmountCents / 100.0);
|
||||
result.Append("},");
|
||||
centsTotal += account.AmountCents;
|
||||
|
||||
@@ -11,36 +11,13 @@ using Swarmops.Logic.Security;
|
||||
using Swarmops.Logic.Structure;
|
||||
using System.Globalization;
|
||||
|
||||
public partial class Pages_v5_Ledgers_Json_ProfitLossData : System.Web.UI.Page
|
||||
public partial class Pages_v5_Ledgers_Json_ProfitLossData : DataV5Base
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
// Current authentication
|
||||
// Get auth data
|
||||
|
||||
string identity = HttpContext.Current.User.Identity.Name;
|
||||
string[] identityTokens = identity.Split(',');
|
||||
|
||||
string userIdentityString = identityTokens[0];
|
||||
string organizationIdentityString = identityTokens[1];
|
||||
|
||||
int currentUserId = Convert.ToInt32(userIdentityString);
|
||||
int currentOrganizationId = Convert.ToInt32(organizationIdentityString);
|
||||
|
||||
Person currentUser = Person.FromIdentity(currentUserId);
|
||||
Authority authority = currentUser.GetAuthority();
|
||||
Organization currentOrganization = Organization.FromIdentity(currentOrganizationId);
|
||||
|
||||
// Get culture
|
||||
|
||||
string cultureString = "en-US";
|
||||
HttpCookie cookie = Request.Cookies["PreferredCulture"];
|
||||
|
||||
if (cookie != null)
|
||||
{
|
||||
cultureString = cookie.Value;
|
||||
}
|
||||
|
||||
_renderCulture = new CultureInfo(cultureString);
|
||||
_authenticationData = GetAuthenticationDataAndCulture();
|
||||
|
||||
// Get current year
|
||||
|
||||
@@ -53,7 +30,7 @@ public partial class Pages_v5_Ledgers_Json_ProfitLossData : System.Web.UI.Page
|
||||
_year = Int32.Parse(yearParameter); // will throw if non-numeric - don't matter for app
|
||||
}
|
||||
|
||||
YearlyReport report = YearlyReport.Create(currentOrganization, _year, FinancialAccountType.Result);
|
||||
YearlyReport report = YearlyReport.Create(CurrentOrganization, _year, FinancialAccountType.Result);
|
||||
LocalizeRoot(report.ReportLines);
|
||||
|
||||
Response.ContentType = "application/json";
|
||||
@@ -63,6 +40,8 @@ public partial class Pages_v5_Ledgers_Json_ProfitLossData : System.Web.UI.Page
|
||||
Response.End();
|
||||
}
|
||||
|
||||
private AuthenticationData _authenticationData;
|
||||
|
||||
|
||||
private void LocalizeRoot(List<YearlyReportLine> lines)
|
||||
{
|
||||
@@ -110,7 +89,7 @@ public partial class Pages_v5_Ledgers_Json_ProfitLossData : System.Web.UI.Page
|
||||
foreach (YearlyReportLine line in reportLines)
|
||||
{
|
||||
string element = string.Format("\"id\":{0},\"name\":\"{1}\"", line.AccountId,
|
||||
line.AccountName.Replace("\"", "'"));
|
||||
JsonSanitize(line.AccountName));
|
||||
|
||||
if (line.Children.Count > 0)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<%@ 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" %>
|
||||
|
||||
<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 () {
|
||||
$('#OrganizationId').combotree({
|
||||
animate: true,
|
||||
height: 30
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</asp:Content>
|
||||
|
||||
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
|
||||
<div class="entryFields">
|
||||
<asp:Label runat="server" ID="LabelCurrentOrganizationName" />​<br/>
|
||||
<select class="easyui-combotree" url="Json-AccessibleOrganizationsTree.aspx" name="OrganizationId" id="OrganizationId" animate="true" style="width:300px"></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" /><br/>
|
||||
</div>
|
||||
<div style="clear:both"></div></asp:Content>
|
||||
|
||||
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderSide" Runat="Server">
|
||||
</asp:Content>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user