Procházet zdrojové kódy

ability to store comment only, actual prevention next

Ryan Helsing před 8 roky
rodič
revize
e6276271b1

+ 7 - 1
client/components/sidebar/sidebar.jade

@@ -138,9 +138,15 @@ template(name="changePermissionsPopup")
     li
     li
       a(class="{{#if isLastAdmin}}disabled{{else}}js-set-normal{{/if}}")
       a(class="{{#if isLastAdmin}}disabled{{else}}js-set-normal{{/if}}")
         | {{_ 'normal'}}
         | {{_ 'normal'}}
-        unless isAdmin
+        if isNormal
           i.fa.fa-check
           i.fa.fa-check
         span.sub-name {{_ 'normal-desc'}}
         span.sub-name {{_ 'normal-desc'}}
+    li
+      a(class="{{#if isLastAdmin}}disabled{{else}}js-set-comment-only{{/if}}")
+        | {{_ 'comment-only'}}
+        if isCommentOnly
+          i.fa.fa-check
+        span.sub-name {{_ 'comment-only-desc'}}
   if isLastAdmin
   if isLastAdmin
     hr
     hr
     p.quiet.bottom {{_ 'last-admin-desc'}}
     p.quiet.bottom {{_ 'last-admin-desc'}}

+ 25 - 3
client/components/sidebar/sidebar.js

@@ -121,7 +121,17 @@ Template.memberPopup.helpers({
   },
   },
   memberType() {
   memberType() {
     const type = Users.findOne(this.userId).isBoardAdmin() ? 'admin' : 'normal';
     const type = Users.findOne(this.userId).isBoardAdmin() ? 'admin' : 'normal';
-    return TAPi18n.__(type).toLowerCase();
+    if(type == 'normal'){
+      const currentBoard = Boards.findOne(Session.get('currentBoard'));
+      const commentOnly = currentBoard.hasCommentOnly(this.userId)
+      if(commentOnly){
+        return TAPi18n.__('comment-only').toLowerCase();
+      } else {
+        return TAPi18n.__(type).toLowerCase();
+      }
+    } else {
+      return TAPi18n.__(type).toLowerCase();
+    }
   },
   },
   isInvited() {
   isInvited() {
     return Users.findOne(this.userId).isInvitedTo(Session.get('currentBoard'));
     return Users.findOne(this.userId).isInvitedTo(Session.get('currentBoard'));
@@ -308,11 +318,13 @@ BlazeComponent.extendComponent({
 }).register('addMemberPopup');
 }).register('addMemberPopup');
 
 
 Template.changePermissionsPopup.events({
 Template.changePermissionsPopup.events({
-  'click .js-set-admin, click .js-set-normal'(event) {
+  'click .js-set-admin, click .js-set-normal, click .js-set-comment-only'(event) {
     const currentBoard = Boards.findOne(Session.get('currentBoard'));
     const currentBoard = Boards.findOne(Session.get('currentBoard'));
     const memberId = this.userId;
     const memberId = this.userId;
     const isAdmin = $(event.currentTarget).hasClass('js-set-admin');
     const isAdmin = $(event.currentTarget).hasClass('js-set-admin');
-    currentBoard.setMemberPermission(memberId, isAdmin);
+    const isCommentOnly = $(event.currentTarget).hasClass('js-set-comment-only');
+    console.log(isCommentOnly)
+    currentBoard.setMemberPermission(memberId, isAdmin, isCommentOnly);
     Popup.back(1);
     Popup.back(1);
   },
   },
 });
 });
@@ -323,6 +335,16 @@ Template.changePermissionsPopup.helpers({
     return currentBoard.hasAdmin(this.userId);
     return currentBoard.hasAdmin(this.userId);
   },
   },
 
 
+  isNormal() {
+    const currentBoard = Boards.findOne(Session.get('currentBoard'));
+    return !currentBoard.hasAdmin(this.userId) && !currentBoard.hasCommentOnly(this.userId);
+  },
+
+  isCommentOnly() {
+    const currentBoard = Boards.findOne(Session.get('currentBoard'));
+    return !currentBoard.hasAdmin(this.userId) && currentBoard.hasCommentOnly(this.userId);
+  },
+
   isLastAdmin() {
   isLastAdmin() {
     const currentBoard = Boards.findOne(Session.get('currentBoard'));
     const currentBoard = Boards.findOne(Session.get('currentBoard'));
     return currentBoard.hasAdmin(this.userId) && (currentBoard.activeAdmins() === 1);
     return currentBoard.hasAdmin(this.userId) && (currentBoard.activeAdmins() === 1);

+ 2 - 2
i18n/en.i18n.json

@@ -137,8 +137,8 @@
     "color-yellow": "yellow",
     "color-yellow": "yellow",
     "comment": "Comment",
     "comment": "Comment",
     "comment-placeholder": "Write a comment",
     "comment-placeholder": "Write a comment",
-    "comment-only": "Comment",
-    "comment-only-desc": "Can only comment on cards on this board, nothing else.",
+    "comment-only": "Limited",
+    "comment-only-desc": "Can comment on cards only.",
     "computer": "Computer",
     "computer": "Computer",
     "create": "Create",
     "create": "Create",
     "createBoardPopup-title": "Create Board",
     "createBoardPopup-title": "Create Board",

+ 10 - 1
models/boards.js

@@ -107,6 +107,7 @@ Boards.attachSchema(new SimpleSchema({
           userId: this.userId,
           userId: this.userId,
           isAdmin: true,
           isAdmin: true,
           isActive: true,
           isActive: true,
+          isCommentOnly: false,
         }];
         }];
       }
       }
     },
     },
@@ -120,6 +121,9 @@ Boards.attachSchema(new SimpleSchema({
   'members.$.isActive': {
   'members.$.isActive': {
     type: Boolean,
     type: Boolean,
   },
   },
+  'members.$.isCommentOnly': {
+    type: Boolean,
+  },
   permission: {
   permission: {
     type: String,
     type: String,
     allowedValues: ['public', 'private'],
     allowedValues: ['public', 'private'],
@@ -219,6 +223,10 @@ Boards.helpers({
     return !!_.findWhere(this.members, {userId: memberId, isActive: true, isAdmin: true});
     return !!_.findWhere(this.members, {userId: memberId, isActive: true, isAdmin: true});
   },
   },
 
 
+  hasCommentOnly(memberId) {
+    return !!_.findWhere(this.members, {userId: memberId, isActive: true, isAdmin: false, isCommentOnly: true});
+  },
+
   absoluteUrl() {
   absoluteUrl() {
     return FlowRouter.url('board', { id: this._id, slug: this.slug });
     return FlowRouter.url('board', { id: this._id, slug: this.slug });
   },
   },
@@ -332,7 +340,7 @@ Boards.mutations({
     };
     };
   },
   },
 
 
-  setMemberPermission(memberId, isAdmin) {
+  setMemberPermission(memberId, isAdmin, isCommentOnly) {
     const memberIndex = this.memberIndex(memberId);
     const memberIndex = this.memberIndex(memberId);
 
 
     // do not allow change permission of self
     // do not allow change permission of self
@@ -343,6 +351,7 @@ Boards.mutations({
     return {
     return {
       $set: {
       $set: {
         [`members.${memberIndex}.isAdmin`]: isAdmin,
         [`members.${memberIndex}.isAdmin`]: isAdmin,
+        [`members.${memberIndex}.isCommentOnly`]: isCommentOnly,
       },
       },
     };
     };
   },
   },