From 85c68b1f5157c9ccb81593ee2ca3b1dc0806eb66 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 7 Apr 2013 16:28:28 +0100 Subject: [PATCH 1/7] 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 85efb0083..b463c9b75 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 From 12a2da2884895fa7e1afb25b5e1384d53af20730 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 7 Apr 2013 18:40:55 +0100 Subject: [PATCH 2/7] attempting to get right client authorid sent with changeset --- src/static/js/changesettracker.js | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/static/js/changesettracker.js b/src/static/js/changesettracker.js index 58ef21cb5..e641cff76 100644 --- a/src/static/js/changesettracker.js +++ b/src/static/js/changesettracker.js @@ -26,6 +26,8 @@ var Changeset = require('./Changeset'); function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) { +//console.log("CS", Changeset); + // latest official text from server var baseAText = Changeset.makeAText("\n"); // changes applied to baseText that have been submitted @@ -161,6 +163,40 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) } else { + // Get my authorID + var authorId = parent.parent.pad.myUserInfo.userId; + // Rewrite apool authors with my author information + + // We need to replace apool numToAttrib array where first value is author + // With thisSession.author + var numToAttr = apool.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 + apool.numToAttrib[attr][1] = authorId; + } + } + } + + // Make sure the actual author is the AuthorID + // We need to replace apool attrToNum value where the first value before + // the comma is author with authorId + var attrToNum = apool.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,'+authorId; // Create a new value + var key = attrToNum[attr]; // Key is actually the value + delete apool.attribToNum[attr]; // Delete the old value + apool.attribToNum[newValue] = key; // Write a new value + } + } + } + if (Changeset.isIdentity(userChangeset)) toSubmit = null; else toSubmit = userChangeset; } From 6c47e29e07392cdd26c70bc89227cefe34b80cef Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 7 Apr 2013 18:43:49 +0100 Subject: [PATCH 3/7] restore PMH original --- src/node/handler/PadMessageHandler.js | 46 ++++++++------------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index b463c9b75..85efb0083 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -579,6 +579,20 @@ 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) { @@ -588,38 +602,6 @@ 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 From ffc8f61a2ffd6d3cd0cdaa17481d5f93f49e705f Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 7 Apr 2013 18:44:13 +0100 Subject: [PATCH 4/7] remove cruft --- src/static/js/changesettracker.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/static/js/changesettracker.js b/src/static/js/changesettracker.js index e641cff76..bd11a2b79 100644 --- a/src/static/js/changesettracker.js +++ b/src/static/js/changesettracker.js @@ -26,8 +26,6 @@ var Changeset = require('./Changeset'); function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) { -//console.log("CS", Changeset); - // latest official text from server var baseAText = Changeset.makeAText("\n"); // changes applied to baseText that have been submitted From 49013b18c739788622e15dca834269265765985a Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Thu, 11 Apr 2013 21:12:59 +0200 Subject: [PATCH 5/7] We need to replace all new author attribs with thisSession.author, in case someone copy/pasted or otherwise inserted other peoples changes --- src/static/js/changesettracker.js | 47 +++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/src/static/js/changesettracker.js b/src/static/js/changesettracker.js index bd11a2b79..da87253c1 100644 --- a/src/static/js/changesettracker.js +++ b/src/static/js/changesettracker.js @@ -165,18 +165,43 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) var authorId = parent.parent.pad.myUserInfo.userId; // Rewrite apool authors with my author information - // We need to replace apool numToAttrib array where first value is author - // With thisSession.author - var numToAttr = apool.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 - apool.numToAttrib[attr][1] = authorId; - } + // We need to replace all new author attribs with thisSession.author, in case someone copy/pasted or otherwise inserted other peoples changes + if(apool.numToAttrib){ + for (var attr in apool.numToAttrib){ + if (apool.numToAttrib[attr][0] == 'author' && apool.numToAttrib[attr][1] == authorId) authorAttr = attr } + + // Replace all added 'author' attribs with the value of the current user + var cs = Changeset.unpack(userChangeset) + , iterator = Changeset.opIterator(cs.ops) + , op + , assem = Changeset.mergingOpAssembler(); +console.log(cs.ops) + while(iterator.hasNext()) { + op = iterator.next() + if(op.opcode == '+') { + var newAttrs = [] +console.log('\nold attribs', op.attribs) + op.attribs.split('*').forEach(function(attrNum) { + if(!attrNum) return + attr = apool.getAttrib(attrNum) + if(!attr) return + if('author' == attr[0] && !~newAttrs.indexOf(authorAttr)) {newAttrs += '*'+authorAttr; console.log('replacing author attribute ', attrNum, '(', attr[1], ') with', authorAttr) } + else newAttrs += '*'+attrNum + }) + op.attribs = newAttrs + } +console.log('new attribs', op.attribs) + assem.append(op) +console.log('opstring', assem.toString()) + } + assem.endDocument(); + console.log(assem.toString()) + userChangeset = Changeset.pack(cs.oldLen, cs.newLen, assem.toString(), cs.charBank) + Changeset.checkRep(userChangeset) + console.log(userChangeset) } - +/* // Make sure the actual author is the AuthorID // We need to replace apool attrToNum value where the first value before // the comma is author with authorId @@ -193,7 +218,7 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) apool.attribToNum[newValue] = key; // Write a new value } } - } + }*/ if (Changeset.isIdentity(userChangeset)) toSubmit = null; else toSubmit = userChangeset; From f4de7f6a9068356a93beec43617d903458c0a784 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Thu, 11 Apr 2013 21:23:38 +0200 Subject: [PATCH 6/7] Use a string instead of an array! --- src/static/js/changesettracker.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/static/js/changesettracker.js b/src/static/js/changesettracker.js index da87253c1..8444fb9c3 100644 --- a/src/static/js/changesettracker.js +++ b/src/static/js/changesettracker.js @@ -180,8 +180,8 @@ console.log(cs.ops) while(iterator.hasNext()) { op = iterator.next() if(op.opcode == '+') { - var newAttrs = [] -console.log('\nold attribs', op.attribs) + var newAttrs = '' + op.attribs.split('*').forEach(function(attrNum) { if(!attrNum) return attr = apool.getAttrib(attrNum) @@ -191,15 +191,13 @@ console.log('\nold attribs', op.attribs) }) op.attribs = newAttrs } -console.log('new attribs', op.attribs) assem.append(op) -console.log('opstring', assem.toString()) } assem.endDocument(); - console.log(assem.toString()) +console.log(assem.toString()) userChangeset = Changeset.pack(cs.oldLen, cs.newLen, assem.toString(), cs.charBank) Changeset.checkRep(userChangeset) - console.log(userChangeset) +console.log(userChangeset) } /* // Make sure the actual author is the AuthorID From 337179fddd6f7a5cb00544029dd8623271fc6b98 Mon Sep 17 00:00:00 2001 From: John McLear Date: Fri, 12 Apr 2013 14:34:07 +0100 Subject: [PATCH 7/7] remove console logs and cruft --- src/static/js/changesettracker.js | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/src/static/js/changesettracker.js b/src/static/js/changesettracker.js index 8444fb9c3..d0c91e3d3 100644 --- a/src/static/js/changesettracker.js +++ b/src/static/js/changesettracker.js @@ -176,7 +176,6 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) , iterator = Changeset.opIterator(cs.ops) , op , assem = Changeset.mergingOpAssembler(); -console.log(cs.ops) while(iterator.hasNext()) { op = iterator.next() if(op.opcode == '+') { @@ -186,7 +185,10 @@ console.log(cs.ops) if(!attrNum) return attr = apool.getAttrib(attrNum) if(!attr) return - if('author' == attr[0] && !~newAttrs.indexOf(authorAttr)) {newAttrs += '*'+authorAttr; console.log('replacing author attribute ', attrNum, '(', attr[1], ') with', authorAttr) } + if('author' == attr[0] && !~newAttrs.indexOf(authorAttr)) { + newAttrs += '*'+authorAttr; + // console.log('replacing author attribute ', attrNum, '(', attr[1], ') with', authorAttr) + } else newAttrs += '*'+attrNum }) op.attribs = newAttrs @@ -194,30 +196,9 @@ console.log(cs.ops) assem.append(op) } assem.endDocument(); -console.log(assem.toString()) userChangeset = Changeset.pack(cs.oldLen, cs.newLen, assem.toString(), cs.charBank) Changeset.checkRep(userChangeset) -console.log(userChangeset) } -/* - // Make sure the actual author is the AuthorID - // We need to replace apool attrToNum value where the first value before - // the comma is author with authorId - var attrToNum = apool.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,'+authorId; // Create a new value - var key = attrToNum[attr]; // Key is actually the value - delete apool.attribToNum[attr]; // Delete the old value - apool.attribToNum[newValue] = key; // Write a new value - } - } - }*/ - if (Changeset.isIdentity(userChangeset)) toSubmit = null; else toSubmit = userChangeset; }