From 47aad6d186053af0d439f2676eff0f95d3047444 Mon Sep 17 00:00:00 2001 From: Thaum Rystra Date: Wed, 20 May 2020 16:52:05 +0200 Subject: [PATCH] Added UI to unshare a view-only character with yourself --- .../character/CharacterSheetToolbarItems.vue | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/app/imports/ui/creature/character/CharacterSheetToolbarItems.vue b/app/imports/ui/creature/character/CharacterSheetToolbarItems.vue index 9a427040..8c95e493 100644 --- a/app/imports/ui/creature/character/CharacterSheetToolbarItems.vue +++ b/app/imports/ui/creature/character/CharacterSheetToolbarItems.vue @@ -21,7 +21,7 @@ more_vert - + delete Delete @@ -38,6 +38,13 @@ + + + + delete Unshare with me + + + @@ -49,11 +56,18 @@ import isDarkColor from '/imports/ui/utility/isDarkColor.js'; import { mapMutations } from 'vuex'; import { theme } from '/imports/ui/theme.js'; import { recomputeCreature } from '/imports/api/creature/computation/recomputeCreature.js'; +import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js'; +import { updateUserSharePermissions } from '/imports/api/sharing/sharing.js'; export default { data(){return { theme, }}, + computed: { + creatureId(){ + return this.$route.params.id; + }, + }, methods: { ...mapMutations([ 'toggleDrawer', @@ -103,12 +117,23 @@ export default { } }); }, - isDarkColor, - }, - computed: { - creatureId(){ - return this.$route.params.id; + unshareWithMe(){ + updateUserSharePermissions.call({ + docRef: { + collection: 'creatures', + id: this.creatureId, + }, + userId: Meteor.userId(), + role: 'none', + }, (error) => { + if (error) { + console.error(error); + } else { + this.$router.push('/characterList'); + } + }); }, + isDarkColor, }, meteor: { $subscribe: { @@ -119,6 +144,14 @@ export default { creature(){ return Creatures.findOne(this.creatureId) || {}; }, + editPermission(){ + try { + assertEditPermission(this.creature, Meteor.userId()); + return true; + } catch (e) { + return false; + } + }, }, }