Преглед изворни кода

W3.9: fixed public/private/owner doc access and checkbox visibility.

Frederic G. MARAND пре 9 година
родитељ
комит
c84f28e209
2 измењених фајлова са 17 додато и 7 уклоњено
  1. 7 5
      textcircle.html
  2. 10 2
      textcircle.js

+ 7 - 5
textcircle.html

@@ -72,11 +72,13 @@
   {{#with document }}
     <span class="h1">{{> editableText collection="documents" field="title" }}</span>
   {{/with}}
-  <div class="checkbox">
-    <label>
-      <input type="checkbox" class="js-tog-private" />Private
-    </label>
-  </div>
+  {{#if canEdit }}
+    <div class="checkbox">
+      <label>
+        <input type="checkbox" class="js-tog-private" />Private
+      </label>
+    </div>
+  {{/if}}
 </template>
 
 <template name="editingUsers">

+ 10 - 2
textcircle.js

@@ -65,6 +65,10 @@ if (Meteor.isClient) {
   Template.docMeta.helpers({
     document: function () {
       return Documents.findOne({ _id: Session.get("docid") });
+    },
+    canEdit: function () {
+      let doc = Documents.findOne({ _id: Session.get("docid") });
+      return doc && doc.owner === Meteor.userId();
     }
   });
 
@@ -112,13 +116,17 @@ if (Meteor.isClient) {
       }
     }
   });
-
 } // end isClient...
 
 if (Meteor.isServer) {
   Meteor.publish("documents", function () {
     Meteor._debug("Publishing documents");
-    return Documents.find({ isPrivate: false });
+    return Documents.find({
+      $or: [
+        { isPrivate: false },
+        { owner: this.userId }
+      ]
+    });
   });
   Meteor.publish("editingUsers", function () {
     Meteor._debug("Publishing all editingUsers");