From 85c68b1f5157c9ccb81593ee2ca3b1dc0806eb66 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 7 Apr 2013 16:28:28 +0100 Subject: [PATCH] rewrite author to actual author on changes --- src/node/handler/PadMessageHandler.js | 46 +++++++++++++++++++-------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index 85efb008..b463c9b7 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -579,20 +579,6 @@ function handleUserChanges(client, message) throw "Attribute pool is missing attribute "+n+" for changeset "+changeset; } }); - - // Validate all added 'author' attribs to be the same value as the current user - var iterator = Changeset.opIterator(Changeset.unpack(changeset).ops) - , op - while(iterator.hasNext()) { - op = iterator.next() - if(op.opcode != '+') continue; - op.attribs.split('*').forEach(function(attr) { - if(!attr) return - attr = wireApool.getAttrib(attr) - if(!attr) return - if('author' == attr[0] && attr[1] != thisSession.author) throw "Trying to submit changes as another author" - }) - } } catch(e) { @@ -602,6 +588,38 @@ function handleUserChanges(client, message) return; } + // Force the change to be by the author session + // Make sure the actual author is this session AuthorID + + // We need to replace wireApool numToAttrib array where first value is author + // With thisSession.author + var numToAttr = wireApool.numToAttrib; + if(numToAttr){ + for (var attr in numToAttr){ + if (numToAttr[attr][0] === 'author'){ + // We force write the author over a change, for sanity n stuff + wireApool.numToAttrib[attr][1] = thisSession.author; + } + } + } + + // We need to replace wireApool attrToNum value where the first value before + // the comma is author with thisSession.author + var attrToNum = wireApool.attribToNum; + if(attrToNum){ + for (var attr in attrToNum){ + var splitAttr = attr.split(','); + var isAuthor = (splitAttr[0] === 'author'); // Is it an author val? + if (isAuthor){ + // We force write the author over a change, for sanity n stuff + var newValue = 'author,'+thisSession.author; // Create a new value + var key = attrToNum[attr]; // Key is actually the value + delete wireApool.attribToNum[attr]; // Delete the old value + wireApool.attribToNum[newValue] = key; // Write a new value + } + } + } + //ex. adoptChangesetAttribs //Afaik, it copies the new attributes from the changeset, to the global Attribute Pool