Added ability to set bitcoin payout address; significant work on Todos needed

This commit is contained in:
Rick Falkvinge
2015-09-05 15:58:37 +02:00
parent fbefd916eb
commit 825353e126
18 changed files with 323 additions and 31 deletions
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NBitcoin" version="2.1.4.7" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net45" />
<package id="protobuf-net" version="2.0.0.668" targetFramework="net45" />
</packages>
+5
View File
@@ -326,6 +326,11 @@ namespace Swarmops.Common.Enums
/// </summary>
BitcoinPayoutAddress,
/// <summary>
/// When the bitcoin address was set (to enable quarantine)
/// </summary>
BitcoinPayoutAddressTimeSet,
/// <summary>
/// If there's a hotwallet, its private root key (encrypted with file and db keys)
/// </summary>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NBitcoin" version="2.1.4.7" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net45" />
<package id="protobuf-net" version="2.0.0.668" targetFramework="net45" />
</packages>
+57 -7
View File
@@ -106,13 +106,36 @@ namespace Swarmops.Logic.Communications
}
public static OutboundComm CreateNotification (Organization organization, NotificationResource notification)
public static OutboundComm CreateNotification (NotificationResource notification)
{
return CreateNotification (organization, notification.ToString());
return CreateNotification (null, notification, new NotificationStrings(), new NotificationCustomStrings());
}
public static OutboundComm CreateNotification(Organization organization, NotificationResource notification, People recipients = null)
{
return CreateNotification(organization, notification, new NotificationStrings(), new NotificationCustomStrings(), recipients);
}
public static OutboundComm CreateParticipantMail (ParticipantMailType mailType, Participation participation,
public static OutboundComm CreateNotification(Organization organization, NotificationResource notification, NotificationStrings strings, People recipients = null)
{
return CreateNotification(organization, notification, strings, new NotificationCustomStrings(), recipients);
}
public static OutboundComm CreateNotification(Organization organization, NotificationResource notification, NotificationCustomStrings customStrings, People recipients = null)
{
return CreateNotification(organization, notification, new NotificationStrings(), customStrings, recipients);
}
public static OutboundComm CreateNotification(Organization organization, NotificationResource notification, NotificationStrings strings, NotificationCustomStrings customStrings, People recipients = null)
{
return CreateNotification(organization, notification.ToString(), strings, customStrings);
}
public static OutboundComm CreateParticipantMail(ParticipantMailType mailType, Participation participation,
Person actingPerson)
{
List<Person> recipients = People.FromSingle (participation.Person);
@@ -156,18 +179,45 @@ namespace Swarmops.Logic.Communications
}
public static OutboundComm CreateNotification (Organization organization, string notificationResourceString)
public static OutboundComm CreateNotification (Organization organization, string notificationResourceString, People recipients = null)
{
List<Person> recipients = People.FromSingle (Person.FromIdentity (1)); // Initial Admin recipient
return CreateNotification (organization, notificationResourceString, new NotificationStrings(),
new NotificationCustomStrings(), recipients);
}
public static OutboundComm CreateNotification (Organization organization, string notificationResourceString,
NotificationStrings strings, People recipients = null)
{
return CreateNotification (organization, notificationResourceString, strings,
new NotificationCustomStrings(), recipients);
}
public static OutboundComm CreateNotification (Organization organization, string notificationResourceString,
NotificationCustomStrings customStrings, People recipients = null)
{
return CreateNotification (organization, notificationResourceString, new NotificationStrings(),
customStrings, recipients);
}
public static OutboundComm CreateNotification (Organization organization, string notificationResourceString, NotificationStrings strings, NotificationCustomStrings customStrings, People recipients = null)
{
if (recipients == null)
{
recipients = People.FromSingle (Person.FromIdentity (1)); // Initial Admin recipient
}
if (organization != null)
{
strings[NotificationString.OrganizationName] = organization.Name; // since we're sending the org anyway, kind of pointless to require callers to set this
// TODO: Change to org admins
}
OutboundComm comm = OutboundComm.Create (null, null, organization, CommResolverClass.Unknown, null,
CommTransmitterClass.CommsTransmitterMail,
new PayloadEnvelope (new NotificationPayload (notificationResourceString)).ToXml(),
new PayloadEnvelope (new NotificationPayload (notificationResourceString, strings, customStrings)).ToXml(),
OutboundCommPriority.Low);
foreach (Person person in recipients)
@@ -25,16 +25,30 @@ namespace Swarmops.Logic.Communications.Transmission
// redirect to main ctor
}
public NotificationPayload (string notificationResource, NotificationStrings strings)
public NotificationPayload(string notificationResource, NotificationStrings strings) :
this(notificationResource, strings, new NotificationCustomStrings())
{
// also redirect to main ctor
}
public NotificationPayload(string notificationResource, NotificationCustomStrings customStrings) :
this(notificationResource, new NotificationStrings(), customStrings)
{
// also redirect to main ctor
}
public NotificationPayload(string notificationResource, NotificationStrings strings, NotificationCustomStrings customStrings)
{
SubjectResource = notificationResource + "_Subject";
BodyResource = notificationResource + "_Body";
Strings = strings;
CustomStrings = customStrings;
}
public string SubjectResource { get; set; }
public string BodyResource { get; set; }
public NotificationStrings Strings { get; set; }
public NotificationCustomStrings CustomStrings { get; set; }
public string GetSubject(string cultureId)
{
@@ -66,7 +80,12 @@ namespace Swarmops.Logic.Communications.Transmission
{
// TODO: Check if string ends in Float, and if so, parse and culturize it
input = input.Replace ("[" + notificationString + "]", Strings[notificationString]);
input = input.Replace ("[" + notificationString /* this is an enum converted to string */ + "]", Strings[notificationString]);
}
foreach (string notificationCustomString in CustomStrings.Keys)
{
input = input.Replace ("[" + notificationCustomString /* this is a System.String as opposed to above */ + "]", CustomStrings[notificationCustomString]);
}
return input;
@@ -165,4 +184,10 @@ namespace Swarmops.Logic.Communications.Transmission
{
// typeset
}
[Serializable]
public class NotificationCustomStrings : SerializableDictionary<string, string>
{
// typeset
}
}
@@ -61,7 +61,7 @@ namespace Swarmops.Logic.Resources {
}
/// <summary>
/// Looks up a localized string similar to You have changed your bitcoin payout address from [BitcoinOldAddress] to [BitcoinAddress]. As a security precaution, all payouts are quarantied for the next 24 hours.
/// Looks up a localized string similar to You have changed your bitcoin payout address from [BitcoinOldAddress] to [BitcoinAddress]. As a security precaution, all payouts are quarantied for the next 48 hours.
///
///If you did NOT change the payout address and there has been a security breach, please click this link immediately to lock down your account: [LockdownLink]
///
@@ -103,7 +103,9 @@ namespace Swarmops.Logic.Resources {
}
/// <summary>
/// Looks up a localized string similar to You have set a bitcoin payout address: [BitcoinAddress]..
/// Looks up a localized string similar to You have set a bitcoin payout address: [BitcoinAddress]. As a security precaution, all payouts are quarantined for the next 48 hours, and will proceed to be paid out to the new address after that.
///
///If you did not set your payout address, contact [OrganizationName] immediately..
/// </summary>
internal static string BitcoinPayoutAddress_Set_Body {
get {
@@ -111,6 +113,24 @@ namespace Swarmops.Logic.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to A bitcoin payout address was set by [ConcernedPersonName]. Payouts will begin after 48 hours when the quarantine period has elapsed..
/// </summary>
internal static string BitcoinPayoutAddress_Set_OfficerNotify_Body {
get {
return ResourceManager.GetString("BitcoinPayoutAddress_Set_OfficerNotify_Body", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to [[OrganizationName]] [ConcernedPersonName] has set a bitcoin payout address.
/// </summary>
internal static string BitcoinPayoutAddress_Set_OfficerNotify_Subject {
get {
return ResourceManager.GetString("BitcoinPayoutAddress_Set_OfficerNotify_Subject", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to [[OrganizationName]] Bitcoin payout address set.
/// </summary>
@@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="BitcoinPayoutAddress_Changed_Body" xml:space="preserve">
<value>You have changed your bitcoin payout address from [BitcoinOldAddress] to [BitcoinAddress]. As a security precaution, all payouts are quarantied for the next 24 hours.
<value>You have changed your bitcoin payout address from [BitcoinOldAddress] to [BitcoinAddress]. As a security precaution, all payouts are quarantied for the next 48 hours.
If you did NOT change the payout address and there has been a security breach, please click this link immediately to lock down your account: [LockdownLink]
@@ -136,7 +136,15 @@ Please log on to [InstallationName] at [InstallationUrl] and follow the link to
<value>[[OrganizationName]] Please set your bitcoin payout address</value>
</data>
<data name="BitcoinPayoutAddress_Set_Body" xml:space="preserve">
<value>You have set a bitcoin payout address: [BitcoinAddress].</value>
<value>You have set a bitcoin payout address: [BitcoinAddress]. As a security precaution, all payouts are quarantined for the next 48 hours, and will proceed to be paid out to the new address after that.
If you did not set your payout address, contact [OrganizationName] immediately.</value>
</data>
<data name="BitcoinPayoutAddress_Set_OfficerNotify_Body" xml:space="preserve">
<value>A bitcoin payout address was set by [ConcernedPersonName]. Payouts will begin after 48 hours when the quarantine period has elapsed.</value>
</data>
<data name="BitcoinPayoutAddress_Set_OfficerNotify_Subject" xml:space="preserve">
<value>[[OrganizationName]] [ConcernedPersonName] has set a bitcoin payout address</value>
</data>
<data name="BitcoinPayoutAddress_Set_Subject" xml:space="preserve">
<value>[[OrganizationName]] Bitcoin payout address set</value>
+28 -1
View File
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18444
// Runtime Version:4.0.30319.34209
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -96,6 +96,24 @@ namespace Swarmops.Logic.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Set bitcoin payout address.
/// </summary>
internal static string Bitcoin_SetPayoutAddress {
get {
return ResourceManager.GetString("Bitcoin_SetPayoutAddress", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Please set your bitcoin address for payouts from [InstallationName]:.
/// </summary>
internal static string Bitcoin_SetPayoutAddress_Prompt {
get {
return ResourceManager.GetString("Bitcoin_SetPayoutAddress_Prompt", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Settle {0} payouts.
/// </summary>
@@ -150,6 +168,15 @@ namespace Swarmops.Logic.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Enable two-factor authentication.
/// </summary>
internal static string Security_Set2FA {
get {
return ResourceManager.GetString("Security_Set2FA", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Validate claims {0}.
/// </summary>
@@ -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="Attest_CashAdvance_Many" xml:space="preserve">
<value>Attest cash advances {0}</value>
@@ -129,6 +129,12 @@
<data name="Attest_ExpenseClaim_One" xml:space="preserve">
<value>Attest expense claim #{0}</value>
</data>
<data name="Bitcoin_SetPayoutAddress" xml:space="preserve">
<value>Set bitcoin payout address</value>
</data>
<data name="Bitcoin_SetPayoutAddress_Prompt" xml:space="preserve">
<value>Please set your bitcoin address for payouts from [InstallationName]:</value>
</data>
<data name="Payout_Many" xml:space="preserve">
<value>Settle {0} payouts</value>
<comment>Instead of "Pay out payout". That sounds too repetitititive.</comment>
@@ -148,6 +154,9 @@
<data name="Payout_Urgent_One" xml:space="preserve">
<value>Settle one urgent payout</value>
</data>
<data name="Security_Set2FA" xml:space="preserve">
<value>Enable two-factor authentication</value>
</data>
<data name="Validate_Receipts_Many" xml:space="preserve">
<value>Validate claims {0}</value>
</data>
+14
View File
@@ -5,7 +5,21 @@
public string Icon { get; set; }
public string Description { get; set; }
public string Url { get; set; }
public string JavaScript { get; set; }
public TodoUrgency Urgency { get; set; }
public string OnClick
{
get
{
if (string.IsNullOrEmpty (this.JavaScript))
{
return "document.location='" + this.Url + "'; return false;";
}
return this.JavaScript;
}
}
}
public enum TodoUrgency
+32
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using NBitcoin.BouncyCastle.Crypto.Digests;
using Swarmops.Logic.Resources;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
@@ -14,6 +15,8 @@ namespace Swarmops.Logic.Swarm
{
DashboardTodos result = new DashboardTodos();
result.AddBitcoinChecks (authority);
result.AddExpenseClaimAttestations(authority);
result.AddCashAdvanceAttestations(authority);
//result.AddSalaryAttestations(person, organization); TODO!
@@ -26,6 +29,35 @@ namespace Swarmops.Logic.Swarm
}
private void AddBitcoinChecks (Authority authority)
{
// Does this person have a bitcoin address set in an org with bitcoin hotwallets?
if (string.IsNullOrEmpty (authority.Person.BitcoinPayoutAddress))
{
if (authority.Organization.FinancialAccounts.AssetsBitcoinHot != null)
{
DashboardTodo todo = new DashboardTodo();
todo.Description = Logic_Swarm_DashboardTodos.Bitcoin_SetPayoutAddress;
todo.Icon = "/Images/Icons/bitcoin-icon-16px.png";
todo.JavaScript = "alertify.prompt(decodeURIComponent('" +
Uri.EscapeDataString (
Logic_Swarm_DashboardTodos.Bitcoin_SetPayoutAddress_Prompt.Replace (
"[SwarmopsInstallationName]", SystemSettings.InstallationName)) +
"' + '<br/><br/>'), function(okPressed, enteredData) { " +
" if (okPressed) { " +
"SwarmopsJS.ajaxCall('/Automation/FinancialFunctions.aspx/SetBitcoinPayoutAddress', { bitcoinAddress: 'test' }, function (result) { " +
"if (result.Success) { alert ('for great justice!'); $('div#divDashboardTodo').fadeOut(); } else { alertify.alert('Could not set payout address: ' + result.DisplayMessage); } " +
"} ); " +
" }}); return false;";
Add (todo);
}
}
}
private void AddReceiptValidations (Authority authority)
{
if (!authority.HasAccess (new Access (authority.Organization, AccessAspect.Financials, AccessType.Write)))
+10 -3
View File
@@ -888,12 +888,19 @@ namespace Swarmops.Logic.Swarm
public string BitcoinPayoutAddress
{
get { return OptionalData.GetOptionalDataString (ObjectOptionalDataType.BitcoinPayoutAddress); }
set { OptionalData.SetOptionalDataString (ObjectOptionalDataType.BitcoinPayoutAddress, value ); }
get { return OptionalData.GetOptionalDataString(ObjectOptionalDataType.BitcoinPayoutAddress); }
set { OptionalData.SetOptionalDataString(ObjectOptionalDataType.BitcoinPayoutAddress, value); }
}
public virtual void SetPassword (string newPassword)
public string BitcoinPayoutAddressTimeSet
{
get { return OptionalData.GetOptionalDataString(ObjectOptionalDataType.BitcoinPayoutAddressTimeSet); }
set { OptionalData.SetOptionalDataString(ObjectOptionalDataType.BitcoinPayoutAddressTimeSet, value); }
}
public virtual void SetPassword(string newPassword)
{
string hash = Authentication.GenerateNewPasswordHash (this, newPassword);
SwarmDb.GetDatabaseForWriting().SetPersonPasswordHash (Identity, hash);
+3
View File
@@ -0,0 +1,3 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FinancialFunctions.aspx.cs" Inherits="Swarmops.Frontend.Automation.FinancialFunctions" %>
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using NBitcoin;
using Swarmops.Logic.Communications;
using Swarmops.Logic.Communications.Transmission;
using Swarmops.Logic.Swarm;
namespace Swarmops.Frontend.Automation
{
public partial class FinancialFunctions : DataV5Base
{
protected void Page_Load (object sender, EventArgs e)
{
// do nothing
}
[WebMethod]
public static AjaxCallResult SetBitcoinPayoutAddress(string bitcoinAddress)
{
AuthenticationData authData = GetAuthenticationDataAndCulture();
if (authData == null)
{
throw new UnauthorizedAccessException();
}
// Remove whitespace from submitted address (whitespace will probably be entered in some cases)
bitcoinAddress = bitcoinAddress.Replace (" ", string.Empty);
if (string.IsNullOrEmpty (authData.CurrentUser.BitcoinPayoutAddress))
{
try
{
BitcoinAddress testBitcoinAddress = new BitcoinAddress (bitcoinAddress); // if this throws, the address wasn't valid
}
catch (Exception)
{
return new AjaxCallResult {Success = false, DisplayMessage = "Invalid address"};
}
authData.CurrentUser.BitcoinPayoutAddress = bitcoinAddress;
authData.CurrentUser.BitcoinPayoutAddressTimeSet = DateTime.UtcNow.ToString (CultureInfo.InvariantCulture);
// TODO: Create notifications for CEO and for user
NotificationCustomStrings strings = new NotificationCustomStrings();
strings["BitcoinAddress"] = bitcoinAddress;
OutboundComm userNotify = OutboundComm.CreateNotification (authData.CurrentOrganization,
"BitcoinPayoutAddress_Set", strings, People.FromSingle (authData.CurrentUser));
strings["ConcernedPersonName"] = authData.CurrentUser.Canonical;
OutboundComm adminNotify = OutboundComm.CreateNotification (authData.CurrentOrganization,
"BitcoinPayoutAddress_Set_OfficerNotify", strings); // will send to admins of org as no people specified
return new AjaxCallResult {Success = true};
}
else
{
// If the address is already set
return new AjaxCallResult {Success = false, DisplayMessage = "Address already set"};
}
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 884 B

+12 -12
View File
@@ -192,22 +192,22 @@
</div>
<asp:ContentPlaceHolder ID="PlaceHolderSide" runat="server" />
<h2 class="orange"><asp:Label ID="LabelSidebarTodo" runat="server" /><span class="arrow"></span></h2>
<div id="DivDashboardTodo">
<h2 class="orange"><asp:Label ID="LabelSidebarTodo" runat="server" /><span class="arrow"></span></h2>
<div class="box">
<div class="content">
<asp:Repeater runat="server" ID="RepeaterTodoItems"><ItemTemplate>
<div class="link-row-encaps" onclick="document.location='<%# DataBinder.Eval(Container.DataItem, "Url") %>';" >
<div class="link-row-icon" style="background-image:url('<%# DataBinder.Eval(Container.DataItem, "Icon") %>')"></div>
<asp:Label ID="Label1" Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>' runat="server" />
<div class="box">
<div class="content">
<asp:Repeater runat="server" ID="RepeaterTodoItems"><ItemTemplate>
<div class="link-row-encaps" onclick="<%# DataBinder.Eval(Container.DataItem, "OnClick") %>" >
<div class="link-row-icon" style="background-image:url('<%# DataBinder.Eval(Container.DataItem, "Icon") %>')"></div>
<asp:Label ID="Label1" Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>' runat="server" />
</div>
</ItemTemplate></asp:Repeater>
<asp:Label ID="LabelNoTodoItems" runat="server" Visible="False" />
</div>
</ItemTemplate></asp:Repeater>
<asp:Label ID="LabelNoTodoItems" runat="server" Visible="False" />
</div>
</div>
</div>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NBitcoin" version="2.1.4.7" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net45" />
<package id="protobuf-net" version="2.0.0.668" targetFramework="net45" />
</packages>