diff --git a/Basic/packages.config b/Basic/packages.config new file mode 100644 index 00000000..016ca340 --- /dev/null +++ b/Basic/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Common/Enums/ObjectOptionalDataType.cs b/Common/Enums/ObjectOptionalDataType.cs index 61b81a8c..a75c2ca0 100644 --- a/Common/Enums/ObjectOptionalDataType.cs +++ b/Common/Enums/ObjectOptionalDataType.cs @@ -326,6 +326,11 @@ namespace Swarmops.Common.Enums /// BitcoinPayoutAddress, + /// + /// When the bitcoin address was set (to enable quarantine) + /// + BitcoinPayoutAddressTimeSet, + /// /// If there's a hotwallet, its private root key (encrypted with file and db keys) /// diff --git a/Console/packages.config b/Console/packages.config new file mode 100644 index 00000000..016ca340 --- /dev/null +++ b/Console/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Logic/Communications/OutboundComm.cs b/Logic/Communications/OutboundComm.cs index 88344e5f..1ccac331 100644 --- a/Logic/Communications/OutboundComm.cs +++ b/Logic/Communications/OutboundComm.cs @@ -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 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 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) diff --git a/Logic/Communications/Transmission/NotificationPayload.cs b/Logic/Communications/Transmission/NotificationPayload.cs index 97fdb35e..4ab6f043 100644 --- a/Logic/Communications/Transmission/NotificationPayload.cs +++ b/Logic/Communications/Transmission/NotificationPayload.cs @@ -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 + { + // typeset + } } \ No newline at end of file diff --git a/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.Designer.cs b/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.Designer.cs index 0318d2f7..cd574a89 100644 --- a/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.Designer.cs +++ b/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.Designer.cs @@ -61,7 +61,7 @@ namespace Swarmops.Logic.Resources { } /// - /// 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 { } /// - /// 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.. /// internal static string BitcoinPayoutAddress_Set_Body { get { @@ -111,6 +113,24 @@ namespace Swarmops.Logic.Resources { } } + /// + /// 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.. + /// + internal static string BitcoinPayoutAddress_Set_OfficerNotify_Body { + get { + return ResourceManager.GetString("BitcoinPayoutAddress_Set_OfficerNotify_Body", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to [[OrganizationName]] [ConcernedPersonName] has set a bitcoin payout address. + /// + internal static string BitcoinPayoutAddress_Set_OfficerNotify_Subject { + get { + return ResourceManager.GetString("BitcoinPayoutAddress_Set_OfficerNotify_Subject", resourceCulture); + } + } + /// /// Looks up a localized string similar to [[OrganizationName]] Bitcoin payout address set. /// diff --git a/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.resx b/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.resx index 6f3ef130..df75fa76 100644 --- a/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.resx +++ b/Logic/Resources/Logic.Communications.Transmission.NotificationPayload.resx @@ -118,7 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - You have changed your bitcoin payout address from [BitcoinOldAddress] to [BitcoinAddress]. As a security precaution, all payouts are quarantied for the next 24 hours. + 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 [[OrganizationName]] Please set your bitcoin payout address - You have set a bitcoin payout address: [BitcoinAddress]. + 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. + + + A bitcoin payout address was set by [ConcernedPersonName]. Payouts will begin after 48 hours when the quarantine period has elapsed. + + + [[OrganizationName]] [ConcernedPersonName] has set a bitcoin payout address [[OrganizationName]] Bitcoin payout address set diff --git a/Logic/Resources/Logic.Swarm.DashboardTodos.Designer.cs b/Logic/Resources/Logic.Swarm.DashboardTodos.Designer.cs index 7104f23f..72703941 100644 --- a/Logic/Resources/Logic.Swarm.DashboardTodos.Designer.cs +++ b/Logic/Resources/Logic.Swarm.DashboardTodos.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // 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 { } } + /// + /// Looks up a localized string similar to Set bitcoin payout address. + /// + internal static string Bitcoin_SetPayoutAddress { + get { + return ResourceManager.GetString("Bitcoin_SetPayoutAddress", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Please set your bitcoin address for payouts from [InstallationName]:. + /// + internal static string Bitcoin_SetPayoutAddress_Prompt { + get { + return ResourceManager.GetString("Bitcoin_SetPayoutAddress_Prompt", resourceCulture); + } + } + /// /// Looks up a localized string similar to Settle {0} payouts. /// @@ -150,6 +168,15 @@ namespace Swarmops.Logic.Resources { } } + /// + /// Looks up a localized string similar to Enable two-factor authentication. + /// + internal static string Security_Set2FA { + get { + return ResourceManager.GetString("Security_Set2FA", resourceCulture); + } + } + /// /// Looks up a localized string similar to Validate claims {0}. /// diff --git a/Logic/Resources/Logic.Swarm.DashboardTodos.resx b/Logic/Resources/Logic.Swarm.DashboardTodos.resx index 80e08d89..7b39f5b5 100644 --- a/Logic/Resources/Logic.Swarm.DashboardTodos.resx +++ b/Logic/Resources/Logic.Swarm.DashboardTodos.resx @@ -112,10 +112,10 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Attest cash advances {0} @@ -129,6 +129,12 @@ Attest expense claim #{0} + + Set bitcoin payout address + + + Please set your bitcoin address for payouts from [InstallationName]: + Settle {0} payouts Instead of "Pay out payout". That sounds too repetitititive. @@ -148,6 +154,9 @@ Settle one urgent payout + + Enable two-factor authentication + Validate claims {0} diff --git a/Logic/Swarm/DashboardTodo.cs b/Logic/Swarm/DashboardTodo.cs index d8cb0e7c..50eac5e9 100644 --- a/Logic/Swarm/DashboardTodo.cs +++ b/Logic/Swarm/DashboardTodo.cs @@ -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 diff --git a/Logic/Swarm/DashboardTodos.cs b/Logic/Swarm/DashboardTodos.cs index 354dbbcc..f9cb0b06 100644 --- a/Logic/Swarm/DashboardTodos.cs +++ b/Logic/Swarm/DashboardTodos.cs @@ -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)) + + "' + '

'), 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))) diff --git a/Logic/Swarm/Person.cs b/Logic/Swarm/Person.cs index 1899c2d4..103ea05d 100644 --- a/Logic/Swarm/Person.cs +++ b/Logic/Swarm/Person.cs @@ -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); diff --git a/Site5/Automation/FinancialFunctions.aspx b/Site5/Automation/FinancialFunctions.aspx new file mode 100644 index 00000000..8fe818d6 --- /dev/null +++ b/Site5/Automation/FinancialFunctions.aspx @@ -0,0 +1,3 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FinancialFunctions.aspx.cs" Inherits="Swarmops.Frontend.Automation.FinancialFunctions" %> + + diff --git a/Site5/Automation/FinancialFunctions.aspx.cs b/Site5/Automation/FinancialFunctions.aspx.cs new file mode 100644 index 00000000..5e4f5201 --- /dev/null +++ b/Site5/Automation/FinancialFunctions.aspx.cs @@ -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"}; + } + } + } +} \ No newline at end of file diff --git a/Site5/Images/Icons/bitcoin-icon-128px.png b/Site5/Images/Icons/bitcoin-icon-128px.png new file mode 100644 index 00000000..67e405a8 Binary files /dev/null and b/Site5/Images/Icons/bitcoin-icon-128px.png differ diff --git a/Site5/Images/Icons/bitcoin-icon-16px.png b/Site5/Images/Icons/bitcoin-icon-16px.png new file mode 100644 index 00000000..fdd0dc22 Binary files /dev/null and b/Site5/Images/Icons/bitcoin-icon-16px.png differ diff --git a/Site5/Master-v5.master b/Site5/Master-v5.master index a30ebdb9..783df0f9 100644 --- a/Site5/Master-v5.master +++ b/Site5/Master-v5.master @@ -192,22 +192,22 @@ - - - -

+
+ +

-
-
- -
diff --git a/Utility/packages.config b/Utility/packages.config new file mode 100644 index 00000000..016ca340 --- /dev/null +++ b/Utility/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file