Enabling edit of personal data

This commit is contained in:
Rick Falkvinge
2016-10-15 22:26:16 +02:00
parent 4361bc5d77
commit 1262e03a6e
4 changed files with 76 additions and 4 deletions
-2
View File
@@ -85,8 +85,6 @@ namespace Swarmops.Database
public int CreateSwarmopsLogEntry (int personId, string entryType, string entryXml)
{
DateTime now = DateTime.UtcNow;
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
+1
View File
@@ -193,6 +193,7 @@
<Compile Include="Communications\Payload\PayloadEnvelope.cs" />
<Compile Include="Communications\Payload\NotificationPayload.cs" />
<Compile Include="Support\BlockchainTransaction.cs" />
<Compile Include="Support\LogEntries\PersonalDataChangedLogEntry.cs" />
<Compile Include="Support\PayloadBase.cs" />
<Compile Include="Financial\BankDataReaders\SEPaymentsBankgiroReader.cs" />
<Compile Include="Financial\Currencies.cs" />
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Swarmops.Logic.Support.LogEntries
{
[Serializable]
public class PersonalDataChangedLogEntry: LogEntryBase<PersonalDataChangedLogEntry>
{
public int AffectedPersonId;
public int ActingPersonId;
public string IpAddress;
public string OldValue;
public string NewValue;
public string Field; // freetext field: "Name", "Mail", and so on
}
}
+56 -2
View File
@@ -8,6 +8,8 @@ using System.Web.UI.WebControls;
using Swarmops.Common.Enums;
using Swarmops.Logic.Security;
using Swarmops.Logic.Structure;
using Swarmops.Logic.Support;
using Swarmops.Logic.Support.LogEntries;
using Swarmops.Logic.Swarm;
using Swarmops.Common.Exceptions;
using Swarmops.Frontend;
@@ -284,12 +286,64 @@ namespace Swarmops.Frontend.Automation
}
}
// TODO: Verify authority to see and change personal data
Person affectedPerson = Person.FromIdentity (personId);
if (!self)
{
if (!authData.Authority.CanSeePerson (affectedPerson) ||
!authData.Authority.HasAccess (new Access (authData.CurrentOrganization, affectedPerson.Geography,
AccessAspect.PersonalData)))
{
throw new UnauthorizedAccessException();
}
}
string oldValue;
switch (field)
{
case "Name":
oldValue = affectedPerson.Name;
affectedPerson.Name = newValue;
break;
case "Mail":
oldValue = affectedPerson.Mail;
affectedPerson.Mail = newValue;
break;
case "Phone":
oldValue = affectedPerson.Phone;
affectedPerson.Phone = newValue;
break;
case "TwitterId":
oldValue = affectedPerson.TwitterId;
affectedPerson.TwitterId = newValue;
break;
default:
throw new ArgumentException("Unrecognized field in /Automation/SwarmFunctions.SetPersonEditorData");
}
SwarmopsLogEntry logEntry = SwarmopsLog.CreateEntry (affectedPerson, new PersonalDataChangedLogEntry
{
ActingPersonId = authData.CurrentUser.PersonId,
AffectedPersonId = affectedPerson.PersonId,
Field = field,
IpAddress = HttpContext.Current.Request.UserHostAddress,
OldValue = oldValue,
NewValue = newValue
});
if (!self)
{
logEntry.CreateAffectedObject (authData.CurrentUser);
}
return new AjaxInputCallResult
{
Success = true,
NewValue = field + ": (Work in progress) call successful"
NewValue = newValue
};
throw new NotImplementedException();
}
private static string GetPersonValue (int personId, string field)