Merge pull request #1750 from ether/fix/authorship-once-and-4-all

Fix authorship sanitization
This commit is contained in:
John McLear 2013-04-17 08:13:22 -07:00
commit f478f99995
1 changed files with 9 additions and 8 deletions

View File

@ -163,19 +163,20 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider)
{
// Get my authorID
var authorId = parent.parent.pad.myUserInfo.userId;
// Rewrite apool authors with my author information
// We need to replace all new author attribs with thisSession.author, in case someone copy/pasted or otherwise inserted other peoples changes
// Sanitize authorship
// We need to replace all author attribs with thisSession.author, in case they 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
if (apool.numToAttrib[attr][0] == 'author' && apool.numToAttrib[attr][1] == authorId) authorAttr = Number(attr).toString(36)
}
// 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();
while(iterator.hasNext()) {
op = iterator.next()
if(op.opcode == '+') {
@ -183,13 +184,13 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider)
op.attribs.split('*').forEach(function(attrNum) {
if(!attrNum) return
attr = apool.getAttrib(attrNum)
var attr = apool.getAttrib(parseInt(attrNum, 36))
if(!attr) return
if('author' == attr[0] && !~newAttrs.indexOf(authorAttr)) {
if('author' == attr[0]) {
// replace that author with the current one
newAttrs += '*'+authorAttr;
// console.log('replacing author attribute ', attrNum, '(', attr[1], ') with', authorAttr)
}
else newAttrs += '*'+attrNum
else newAttrs += '*'+attrNum // overtake all other attribs as is
})
op.attribs = newAttrs
}