diff --git a/Database/Database-SwarmopsLog.cs b/Database/Database-SwarmopsLog.cs
index 279d8244..ce3808e7 100644
--- a/Database/Database-SwarmopsLog.cs
+++ b/Database/Database-SwarmopsLog.cs
@@ -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();
diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj
index b87e58ec..ff3ceb39 100644
--- a/Logic/Logic.csproj
+++ b/Logic/Logic.csproj
@@ -193,6 +193,7 @@
+
diff --git a/Logic/Support/LogEntries/PersonalDataChangedLogEntry.cs b/Logic/Support/LogEntries/PersonalDataChangedLogEntry.cs
new file mode 100644
index 00000000..67054054
--- /dev/null
+++ b/Logic/Support/LogEntries/PersonalDataChangedLogEntry.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
+ {
+ 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
+ }
+}
diff --git a/Site/Automation/SwarmFunctions.aspx.cs b/Site/Automation/SwarmFunctions.aspx.cs
index a215a1b9..10bdcee6 100644
--- a/Site/Automation/SwarmFunctions.aspx.cs
+++ b/Site/Automation/SwarmFunctions.aspx.cs
@@ -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)