diff options
author | Justin Reynolds <justinr1234@gmail.com> | 2019-06-28 12:52:09 -0500 |
---|---|---|
committer | Justin Reynolds <justinr1234@gmail.com> | 2019-06-28 12:56:51 -0500 |
commit | 3eb4d2c341b712268bd321173909e0a7b19a88c9 (patch) | |
tree | 25a8fcb088f3984e72a5bd3ded9e6a45376e0693 /server/publications | |
parent | a0a482aa8efb3255a523de4524c8e09453d5571f (diff) | |
download | wekan-3eb4d2c341b712268bd321173909e0a7b19a88c9.tar.gz wekan-3eb4d2c341b712268bd321173909e0a7b19a88c9.tar.bz2 wekan-3eb4d2c341b712268bd321173909e0a7b19a88c9.zip |
Prettier & eslint project style update
Diffstat (limited to 'server/publications')
-rw-r--r-- | server/publications/activities.js | 15 | ||||
-rw-r--r-- | server/publications/boards.js | 290 | ||||
-rw-r--r-- | server/publications/cards.js | 2 | ||||
-rw-r--r-- | server/publications/people.js | 27 | ||||
-rw-r--r-- | server/publications/rules.js | 2 | ||||
-rw-r--r-- | server/publications/settings.js | 32 | ||||
-rw-r--r-- | server/publications/users.js | 13 |
7 files changed, 211 insertions, 170 deletions
diff --git a/server/publications/activities.js b/server/publications/activities.js index 14459bf8..90be1a39 100644 --- a/server/publications/activities.js +++ b/server/publications/activities.js @@ -4,16 +4,21 @@ // We use this publication to paginate for these two publications. Meteor.publish('activities', (kind, id, limit, hideSystem) => { - check(kind, Match.Where((x) => { - return ['board', 'card'].indexOf(x) !== -1; - })); + check( + kind, + Match.Where(x => { + return ['board', 'card'].indexOf(x) !== -1; + }), + ); check(id, String); check(limit, Number); check(hideSystem, Boolean); - const selector = (hideSystem) ? {$and: [{activityType: 'addComment'}, {[`${kind}Id`]: id}]} : {[`${kind}Id`]: id}; + const selector = hideSystem + ? { $and: [{ activityType: 'addComment' }, { [`${kind}Id`]: id }] } + : { [`${kind}Id`]: id }; return Activities.find(selector, { limit, - sort: {createdAt: -1}, + sort: { createdAt: -1 }, }); }); diff --git a/server/publications/boards.js b/server/publications/boards.js index cec03858..96ef3054 100644 --- a/server/publications/boards.js +++ b/server/publications/boards.js @@ -5,58 +5,62 @@ Meteor.publish('boards', function() { // Ensure that the user is connected. If it is not, we need to return an empty // array to tell the client to remove the previously published docs. - if (!Match.test(this.userId, String)) - return []; + if (!Match.test(this.userId, String)) return []; // Defensive programming to verify that starredBoards has the expected // format -- since the field is in the `profile` a user can modify it. - const {starredBoards = []} = Users.findOne(this.userId).profile || {}; + const { starredBoards = [] } = Users.findOne(this.userId).profile || {}; check(starredBoards, [String]); - return Boards.find({ - archived: false, - $or: [ - { - _id: { $in: starredBoards }, - permission: 'public', + return Boards.find( + { + archived: false, + $or: [ + { + _id: { $in: starredBoards }, + permission: 'public', + }, + { members: { $elemMatch: { userId: this.userId, isActive: true } } }, + ], + }, + { + fields: { + _id: 1, + archived: 1, + slug: 1, + title: 1, + description: 1, + color: 1, + members: 1, + permission: 1, + type: 1, }, - { members: { $elemMatch: { userId: this.userId, isActive: true }}}, - ], - }, { - fields: { - _id: 1, - archived: 1, - slug: 1, - title: 1, - description: 1, - color: 1, - members: 1, - permission: 1, - type: 1, }, - }); + ); }); Meteor.publish('archivedBoards', function() { - if (!Match.test(this.userId, String)) - return []; + if (!Match.test(this.userId, String)) return []; - return Boards.find({ - archived: true, - members: { - $elemMatch: { - userId: this.userId, - isAdmin: true, + return Boards.find( + { + archived: true, + members: { + $elemMatch: { + userId: this.userId, + isAdmin: true, + }, }, }, - }, { - fields: { - _id: 1, - archived: 1, - slug: 1, - title: 1, + { + fields: { + _id: 1, + archived: 1, + slug: 1, + title: 1, + }, }, - }); + ); }); // If isArchived = false, this will only return board elements which are not archived. @@ -67,106 +71,130 @@ Meteor.publishRelations('board', function(boardId, isArchived) { check(isArchived, Boolean); const thisUserId = this.userId; - this.cursor(Boards.find({ - _id: boardId, - archived: false, - // If the board is not public the user has to be a member of it to see - // it. - $or: [ - { permission: 'public' }, - { members: { $elemMatch: { userId: this.userId, isActive: true }}}, - ], - // Sort required to ensure oplog usage - }, { limit: 1, sort: { _id: 1 } }), function(boardId, board) { - this.cursor(Lists.find({ boardId, archived: isArchived })); - this.cursor(Swimlanes.find({ boardId, archived: isArchived })); - this.cursor(Integrations.find({ boardId })); - this.cursor(CustomFields.find({ boardIds: {$in: [boardId]} }, { sort: { name: 1 } })); + this.cursor( + Boards.find( + { + _id: boardId, + archived: false, + // If the board is not public the user has to be a member of it to see + // it. + $or: [ + { permission: 'public' }, + { members: { $elemMatch: { userId: this.userId, isActive: true } } }, + ], + // Sort required to ensure oplog usage + }, + { limit: 1, sort: { _id: 1 } }, + ), + function(boardId, board) { + this.cursor(Lists.find({ boardId, archived: isArchived })); + this.cursor(Swimlanes.find({ boardId, archived: isArchived })); + this.cursor(Integrations.find({ boardId })); + this.cursor( + CustomFields.find( + { boardIds: { $in: [boardId] } }, + { sort: { name: 1 } }, + ), + ); - // Cards and cards comments - // XXX Originally we were publishing the card documents as a child of the - // list publication defined above using the following selector `{ listId: - // list._id }`. But it was causing a race condition in publish-composite, - // that I documented here: - // - // https://github.com/englue/meteor-publish-composite/issues/29 - // - // cottz:publish had a similar problem: - // - // https://github.com/Goluis/cottz-publish/issues/4 - // - // The current state of relational publishing in meteor is a bit sad, - // there are a lot of various packages, with various APIs, some of them - // are unmaintained. Fortunately this is something that will be fixed by - // meteor-core at some point: - // - // https://trello.com/c/BGvIwkEa/48-easy-joins-in-subscriptions - // - // And in the meantime our code below works pretty well -- it's not even a - // hack! + // Cards and cards comments + // XXX Originally we were publishing the card documents as a child of the + // list publication defined above using the following selector `{ listId: + // list._id }`. But it was causing a race condition in publish-composite, + // that I documented here: + // + // https://github.com/englue/meteor-publish-composite/issues/29 + // + // cottz:publish had a similar problem: + // + // https://github.com/Goluis/cottz-publish/issues/4 + // + // The current state of relational publishing in meteor is a bit sad, + // there are a lot of various packages, with various APIs, some of them + // are unmaintained. Fortunately this is something that will be fixed by + // meteor-core at some point: + // + // https://trello.com/c/BGvIwkEa/48-easy-joins-in-subscriptions + // + // And in the meantime our code below works pretty well -- it's not even a + // hack! - // Gather queries and send in bulk - const cardComments = this.join(CardComments); - cardComments.selector = (_ids) => ({ cardId: _ids }); - const attachments = this.join(Attachments); - attachments.selector = (_ids) => ({ cardId: _ids }); - const checklists = this.join(Checklists); - checklists.selector = (_ids) => ({ cardId: _ids }); - const checklistItems = this.join(ChecklistItems); - checklistItems.selector = (_ids) => ({ cardId: _ids }); - const parentCards = this.join(Cards); - parentCards.selector = (_ids) => ({ parentId: _ids }); - const boards = this.join(Boards); - const subCards = this.join(Cards); - subCards.selector = (_ids) => ({ archived: isArchived }); + // Gather queries and send in bulk + const cardComments = this.join(CardComments); + cardComments.selector = _ids => ({ cardId: _ids }); + const attachments = this.join(Attachments); + attachments.selector = _ids => ({ cardId: _ids }); + const checklists = this.join(Checklists); + checklists.selector = _ids => ({ cardId: _ids }); + const checklistItems = this.join(ChecklistItems); + checklistItems.selector = _ids => ({ cardId: _ids }); + const parentCards = this.join(Cards); + parentCards.selector = _ids => ({ parentId: _ids }); + const boards = this.join(Boards); + const subCards = this.join(Cards); + subCards.selector = () => ({ archived: isArchived }); - this.cursor(Cards.find({ boardId: {$in: [boardId, board.subtasksDefaultBoardId]}, archived: isArchived }), function(cardId, card) { - if (card.type === 'cardType-linkedCard') { - const impCardId = card.linkedId; - subCards.push(impCardId); - cardComments.push(impCardId); - attachments.push(impCardId); - checklists.push(impCardId); - checklistItems.push(impCardId); - } else if (card.type === 'cardType-linkedBoard') { - boards.push(card.linkedId); - } - cardComments.push(cardId); - attachments.push(cardId); - checklists.push(cardId); - checklistItems.push(cardId); - parentCards.push(cardId); - }); + this.cursor( + Cards.find({ + boardId: { $in: [boardId, board.subtasksDefaultBoardId] }, + archived: isArchived, + }), + function(cardId, card) { + if (card.type === 'cardType-linkedCard') { + const impCardId = card.linkedId; + subCards.push(impCardId); + cardComments.push(impCardId); + attachments.push(impCardId); + checklists.push(impCardId); + checklistItems.push(impCardId); + } else if (card.type === 'cardType-linkedBoard') { + boards.push(card.linkedId); + } + cardComments.push(cardId); + attachments.push(cardId); + checklists.push(cardId); + checklistItems.push(cardId); + parentCards.push(cardId); + }, + ); - // Send bulk queries for all found ids - subCards.send(); - cardComments.send(); - attachments.send(); - checklists.send(); - checklistItems.send(); - boards.send(); - parentCards.send(); + // Send bulk queries for all found ids + subCards.send(); + cardComments.send(); + attachments.send(); + checklists.send(); + checklistItems.send(); + boards.send(); + parentCards.send(); - if (board.members) { - // Board members. This publication also includes former board members that - // aren't members anymore but may have some activities attached to them in - // the history. - const memberIds = _.pluck(board.members, 'userId'); + if (board.members) { + // Board members. This publication also includes former board members that + // aren't members anymore but may have some activities attached to them in + // the history. + const memberIds = _.pluck(board.members, 'userId'); - // We omit the current user because the client should already have that data, - // and sending it triggers a subtle bug: - // https://github.com/wefork/wekan/issues/15 - this.cursor(Users.find({ - _id: { $in: _.without(memberIds, thisUserId)}, - }, { fields: { - 'username': 1, - 'profile.fullname': 1, - 'profile.avatarUrl': 1, - }})); + // We omit the current user because the client should already have that data, + // and sending it triggers a subtle bug: + // https://github.com/wefork/wekan/issues/15 + this.cursor( + Users.find( + { + _id: { $in: _.without(memberIds, thisUserId) }, + }, + { + fields: { + username: 1, + 'profile.fullname': 1, + 'profile.avatarUrl': 1, + }, + }, + ), + ); - this.cursor(presences.find({ userId: { $in: memberIds } })); - } - }); + this.cursor(presences.find({ userId: { $in: memberIds } })); + } + }, + ); return this.ready(); }); diff --git a/server/publications/cards.js b/server/publications/cards.js index c9abc421..61210ce5 100644 --- a/server/publications/cards.js +++ b/server/publications/cards.js @@ -1,4 +1,4 @@ -Meteor.publish('card', (cardId) => { +Meteor.publish('card', cardId => { check(cardId, String); return Cards.find({ _id: cardId }); }); diff --git a/server/publications/people.js b/server/publications/people.js index 56187732..cc8e3fc9 100644 --- a/server/publications/people.js +++ b/server/publications/people.js @@ -7,19 +7,22 @@ Meteor.publish('people', function(limit) { const user = Users.findOne(this.userId); if (user && user.isAdmin) { - return Users.find({}, { - limit, - sort: {createdAt: -1}, - fields: { - 'username': 1, - 'profile.fullname': 1, - 'isAdmin': 1, - 'emails': 1, - 'createdAt': 1, - 'loginDisabled': 1, - 'authenticationMethod': 1, + return Users.find( + {}, + { + limit, + sort: { createdAt: -1 }, + fields: { + username: 1, + 'profile.fullname': 1, + isAdmin: 1, + emails: 1, + createdAt: 1, + loginDisabled: 1, + authenticationMethod: 1, + }, }, - }); + ); } else { return []; } diff --git a/server/publications/rules.js b/server/publications/rules.js index d0864893..2a593067 100644 --- a/server/publications/rules.js +++ b/server/publications/rules.js @@ -1,4 +1,4 @@ -Meteor.publish('rules', (ruleId) => { +Meteor.publish('rules', ruleId => { check(ruleId, String); return Rules.find({ _id: ruleId, diff --git a/server/publications/settings.js b/server/publications/settings.js index a8f8a969..d273fe62 100644 --- a/server/publications/settings.js +++ b/server/publications/settings.js @@ -1,23 +1,25 @@ Meteor.publish('setting', () => { - return Settings.find({}, { - fields:{ - disableRegistration: 1, - productName: 1, - hideLogo: 1, - customHTMLafterBodyStart: 1, - customHTMLbeforeBodyEnd: 1, - displayAuthenticationMethod: 1, - defaultAuthenticationMethod: 1, + return Settings.find( + {}, + { + fields: { + disableRegistration: 1, + productName: 1, + hideLogo: 1, + customHTMLafterBodyStart: 1, + customHTMLbeforeBodyEnd: 1, + displayAuthenticationMethod: 1, + defaultAuthenticationMethod: 1, + }, }, - }); + ); }); -Meteor.publish('mailServer', function () { - if (!Match.test(this.userId, String)) - return []; +Meteor.publish('mailServer', function() { + if (!Match.test(this.userId, String)) return []; const user = Users.findOne(this.userId); - if(user && user.isAdmin){ - return Settings.find({}, {fields: {mailServer: 1}}); + if (user && user.isAdmin) { + return Settings.find({}, { fields: { mailServer: 1 } }); } return []; }); diff --git a/server/publications/users.js b/server/publications/users.js index f0c94153..59411ca0 100644 --- a/server/publications/users.js +++ b/server/publications/users.js @@ -3,7 +3,7 @@ Meteor.publish('user-miniprofile', function(userId) { return Users.find(userId, { fields: { - 'username': 1, + username: 1, 'profile.fullname': 1, 'profile.avatarUrl': 1, }, @@ -20,9 +20,12 @@ Meteor.publish('user-admin', function() { Meteor.publish('user-authenticationMethod', function(match) { check(match, String); - return Users.find({$or: [{_id: match}, {email: match}, {username: match}]}, { - fields: { - 'authenticationMethod': 1, + return Users.find( + { $or: [{ _id: match }, { email: match }, { username: match }] }, + { + fields: { + authenticationMethod: 1, + }, }, - }); + ); }); |