In-progress implementing usernames for share dialog

This commit is contained in:
Stefan Zermatten
2015-04-24 12:16:12 +02:00
parent e0209df270
commit 31e7b8d610
3 changed files with 35 additions and 28 deletions

View File

@@ -1,18 +1,22 @@
<template name="shareDialog">
<div>
<div>
<div class="subhead">
Can View
</div>
{{#each readers}}
{{this}}<br>
{{/each}}
<div class="subhead">
Can Edit
</div>
{{#each writers}}
{{this}}<br>
{{/each}}
{{#if writers.count}}
<div class="subhead">
Can View
</div>
{{#each readers}}
{{username}}<br>
{{/each}}
{{/if}}
{{#if writers.count}}
<div class="subhead">
Can Edit
</div>
{{#each writers}}
{{username}}<br>
{{/each}}
{{/if}}
</div>
<paper-input id="userNameOrEmailInput" label="Username or email" floatinglabel></paper-input><br>
{{#if userFindError}}<p style="color: red;">{{userFindError}}</p>{{/if}}

View File

@@ -5,11 +5,11 @@ Template.shareDialog.onCreated(function(){
Template.shareDialog.helpers({
readers: function(){
var char = Characters.findOne(this._id, {fields: {readers: 1}});
return char && char.readers;
return Meteor.users.find({_id: {$in: char.readers}});
},
writers: function(){
var char = Characters.findOne(this._id, {fields: {writers: 1}});
return char && char.writers;
return Meteor.users.find({_id: {$in: char.writers}});
},
shareButtonDisabled: function(){
return !Template.instance().userId.get();
@@ -18,7 +18,7 @@ Template.shareDialog.helpers({
if (!Template.instance().userId.get()){
return "User not found";
}
}
},
});
Template.shareDialog.events({
@@ -44,13 +44,13 @@ Template.shareDialog.events({
if (permission === "write"){
Characters.update(self._id, {
$addToSet: {writers: userId},
$pull: {readers: userId}
$pull: {readers: userId},
});
} else {
Characters.update(self._id, {
$addToSet: {readers: userId},
$pull: {writers: userId}
$pull: {writers: userId},
});
}
}
},
});

View File

@@ -1,14 +1,13 @@
Meteor.publish("singleCharacter", function(characterId, userId){
if (
Characters.findOne({
_id: characterId,
$or: [
{readers: userId},
{writers: userId},
{owner: userId},
],
})
){
var char = Characters.findOne({
_id: characterId,
$or: [
{readers: userId},
{writers: userId},
{owner: userId},
],
});
if (char){
return [
Characters.find({_id: characterId}),
//get all the assets for this character including soft deleted ones
@@ -25,6 +24,10 @@ Meteor.publish("singleCharacter", function(characterId, userId){
SpellLists.find ({charId: characterId}, {removed: true}),
TemporaryHitPoints.find({charId: characterId}, {removed: true}),
Proficiencies.find ({charId: characterId}, {removed: true}),
Meteor.users.find (
{_id: {$in: _.union(char.readers, char.writers)}},
{fields: {username: 1}}
),
];
}
});