From 9d86cb8bee1a8590bc285fdab37569689940d384 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Mon, 11 Feb 2019 10:21:11 +0200 Subject: [PATCH] Added the copy character method --- app/lib/methods/characterCopyPaste.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 app/lib/methods/characterCopyPaste.js diff --git a/app/lib/methods/characterCopyPaste.js b/app/lib/methods/characterCopyPaste.js new file mode 100644 index 00000000..d078b45b --- /dev/null +++ b/app/lib/methods/characterCopyPaste.js @@ -0,0 +1,22 @@ +// Uses '/lib/functions/backupRestoreCharacter.js' to do most the work + +Meteor.methods({ + copyCharacter: function(charId) { + const userId = Meteor.userId(); + let character = Characters.findOne(charId); + + // Need at least view level permission to make a copy for yourself + if (!canViewCharacter(character, userId)) return; + + let characterDump = dumpCharacter(charId); + giveCharacterDumpNewIds(characterDump); + + // Remove all readers and writers, make this user the new owner + characterDump.character.readers = []; + characterDump.character.writers = []; + characterDump.character.owner = userId; + + // Write the character back to the database + restoreCharacter(characterDump); + }, +});