Fix missing profile checks

This commit is contained in:
Justin Reynolds 2019-05-08 16:51:27 -05:00
parent 97ff2bd2fa
commit daf314b037
12 changed files with 39 additions and 35 deletions

View file

@ -30,6 +30,8 @@ template(name="boardBody")
+listsGroup(currentBoard) +listsGroup(currentBoard)
else if isViewCalendar else if isViewCalendar
+calendarView +calendarView
else
+listsGroup(currentBoard)
template(name="calendarView") template(name="calendarView")
if isViewCalendar if isViewCalendar

View file

@ -191,19 +191,19 @@ BlazeComponent.extendComponent({
isViewSwimlanes() { isViewSwimlanes() {
const currentUser = Meteor.user(); const currentUser = Meteor.user();
if (!currentUser) return false; if (!currentUser) return false;
return (currentUser.profile.boardView === 'board-view-swimlanes'); return ((currentUser.profile || {}).boardView === 'board-view-swimlanes');
}, },
isViewLists() { isViewLists() {
const currentUser = Meteor.user(); const currentUser = Meteor.user();
if (!currentUser) return true; if (!currentUser) return true;
return (currentUser.profile.boardView === 'board-view-lists'); return ((currentUser.profile || {}).boardView === 'board-view-lists');
}, },
isViewCalendar() { isViewCalendar() {
const currentUser = Meteor.user(); const currentUser = Meteor.user();
if (!currentUser) return false; if (!currentUser) return false;
return (currentUser.profile.boardView === 'board-view-cal'); return ((currentUser.profile || {}).boardView === 'board-view-cal');
}, },
openNewListForm() { openNewListForm() {
@ -335,6 +335,6 @@ BlazeComponent.extendComponent({
isViewCalendar() { isViewCalendar() {
const currentUser = Meteor.user(); const currentUser = Meteor.user();
if (!currentUser) return false; if (!currentUser) return false;
return (currentUser.profile.boardView === 'board-view-cal'); return ((currentUser.profile || {}).boardView === 'board-view-cal');
}, },
}).register('calendarView'); }).register('calendarView');

View file

@ -98,7 +98,7 @@ template(name="boardHeaderBar")
a.board-header-btn.js-toggle-board-view( a.board-header-btn.js-toggle-board-view(
title="{{_ 'board-view'}}") title="{{_ 'board-view'}}")
i.fa.fa-th-large i.fa.fa-th-large
span {{_ currentUser.profile.boardView}} span {{#if currentUser.profile.boardView}}{{_ currentUser.profile.boardView}}{{else}}{{_ 'board-view-lists'}}{{/if}}
if canModifyBoard if canModifyBoard
a.board-header-btn.js-multiselection-activate( a.board-header-btn.js-multiselection-activate(

View file

@ -89,12 +89,14 @@ BlazeComponent.extendComponent({
}, },
'click .js-toggle-board-view'() { 'click .js-toggle-board-view'() {
const currentUser = Meteor.user(); const currentUser = Meteor.user();
if (currentUser.profile.boardView === 'board-view-swimlanes') { if ((currentUser.profile || {}).boardView === 'board-view-swimlanes') {
currentUser.setBoardView('board-view-cal'); currentUser.setBoardView('board-view-cal');
} else if (currentUser.profile.boardView === 'board-view-lists') { } else if ((currentUser.profile || {}).boardView === 'board-view-lists') {
currentUser.setBoardView('board-view-swimlanes'); currentUser.setBoardView('board-view-swimlanes');
} else if (currentUser.profile.boardView === 'board-view-cal') { } else if ((currentUser.profile || {}).boardView === 'board-view-cal') {
currentUser.setBoardView('board-view-lists'); currentUser.setBoardView('board-view-lists');
} else {
currentUser.setBoardView('board-view-swimlanes');
} }
}, },
'click .js-toggle-sidebar'() { 'click .js-toggle-sidebar'() {

View file

@ -69,10 +69,10 @@ BlazeComponent.extendComponent({
const listId = Blaze.getData(ui.item.parents('.list').get(0))._id; const listId = Blaze.getData(ui.item.parents('.list').get(0))._id;
const currentBoard = Boards.findOne(Session.get('currentBoard')); const currentBoard = Boards.findOne(Session.get('currentBoard'));
let swimlaneId = ''; let swimlaneId = '';
const boardView = Meteor.user().profile.boardView; const boardView = (Meteor.user().profile || {}).boardView;
if (boardView === 'board-view-swimlanes' || currentBoard.isTemplatesBoard()) if (boardView === 'board-view-swimlanes' || currentBoard.isTemplatesBoard())
swimlaneId = Blaze.getData(ui.item.parents('.swimlane').get(0))._id; swimlaneId = Blaze.getData(ui.item.parents('.swimlane').get(0))._id;
else if ((boardView === 'board-view-lists') || (boardView === 'board-view-cal')) else if ((boardView === 'board-view-lists') || (boardView === 'board-view-cal') || !boardView)
swimlaneId = currentBoard.getDefaultSwimline()._id; swimlaneId = currentBoard.getDefaultSwimline()._id;
// Normally the jquery-ui sortable library moves the dragged DOM element // Normally the jquery-ui sortable library moves the dragged DOM element

View file

@ -48,7 +48,7 @@ BlazeComponent.extendComponent({
const board = this.data().board(); const board = this.data().board();
let linkedId = ''; let linkedId = '';
let swimlaneId = ''; let swimlaneId = '';
const boardView = Meteor.user().profile.boardView; const boardView = (Meteor.user().profile || {}).boardView;
let cardType = 'cardType-card'; let cardType = 'cardType-card';
if (title) { if (title) {
if (board.isTemplatesBoard()) { if (board.isTemplatesBoard()) {
@ -72,7 +72,7 @@ BlazeComponent.extendComponent({
} }
} else if (boardView === 'board-view-swimlanes') } else if (boardView === 'board-view-swimlanes')
swimlaneId = this.parentComponent().parentComponent().data()._id; swimlaneId = this.parentComponent().parentComponent().data()._id;
else if ((boardView === 'board-view-lists') || (boardView === 'board-view-cal')) else if ((boardView === 'board-view-lists') || (boardView === 'board-view-cal') || !boardView)
swimlaneId = board.getDefaultSwimline()._id; swimlaneId = board.getDefaultSwimline()._id;
const _id = Cards.insert({ const _id = Cards.insert({
@ -149,7 +149,7 @@ BlazeComponent.extendComponent({
idOrNull(swimlaneId) { idOrNull(swimlaneId) {
const currentUser = Meteor.user(); const currentUser = Meteor.user();
if (currentUser.profile.boardView === 'board-view-swimlanes' || if ((currentUser.profile || {}).boardView === 'board-view-swimlanes' ||
this.data().board().isTemplatesBoard()) this.data().board().isTemplatesBoard())
return swimlaneId; return swimlaneId;
return undefined; return undefined;
@ -356,10 +356,10 @@ BlazeComponent.extendComponent({
// Swimlane where to insert card // Swimlane where to insert card
const swimlane = $(Popup._getTopStack().openerElement).closest('.js-swimlane'); const swimlane = $(Popup._getTopStack().openerElement).closest('.js-swimlane');
this.swimlaneId = ''; this.swimlaneId = '';
const boardView = Meteor.user().profile.boardView; const boardView = (Meteor.user().profile || {}).boardView;
if (boardView === 'board-view-swimlanes') if (boardView === 'board-view-swimlanes')
this.swimlaneId = Blaze.getData(swimlane[0])._id; this.swimlaneId = Blaze.getData(swimlane[0])._id;
else if (boardView === 'board-view-lists') else if (boardView === 'board-view-lists' || !boardView)
this.swimlaneId = Swimlanes.findOne({boardId: this.boardId})._id; this.swimlaneId = Swimlanes.findOne({boardId: this.boardId})._id;
}, },
@ -485,13 +485,13 @@ BlazeComponent.extendComponent({
this.isBoardTemplateSearch; this.isBoardTemplateSearch;
let board = {}; let board = {};
if (this.isTemplateSearch) { if (this.isTemplateSearch) {
board = Boards.findOne(Meteor.user().profile.templatesBoardId); board = Boards.findOne((Meteor.user().profile || {}).templatesBoardId);
} else { } else {
// Prefetch first non-current board id // Prefetch first non-current board id
board = Boards.findOne({ board = Boards.findOne({
archived: false, archived: false,
'members.userId': Meteor.userId(), 'members.userId': Meteor.userId(),
_id: {$nin: [Session.get('currentBoard'), Meteor.user().profile.templatesBoardId]}, _id: {$nin: [Session.get('currentBoard'), (Meteor.user().profile || {}).templatesBoardId]},
}); });
} }
if (!board) { if (!board) {
@ -510,7 +510,7 @@ BlazeComponent.extendComponent({
this.swimlaneId = ''; this.swimlaneId = '';
// Swimlane where to insert card // Swimlane where to insert card
const swimlane = $(Popup._getTopStack().openerElement).parents('.js-swimlane'); const swimlane = $(Popup._getTopStack().openerElement).parents('.js-swimlane');
if (Meteor.user().profile.boardView === 'board-view-swimlanes') if ((Meteor.user().profile || {}).boardView === 'board-view-swimlanes')
this.swimlaneId = Blaze.getData(swimlane[0])._id; this.swimlaneId = Blaze.getData(swimlane[0])._id;
else else
this.swimlaneId = Swimlanes.findOne({boardId: this.boardId})._id; this.swimlaneId = Swimlanes.findOne({boardId: this.boardId})._id;
@ -620,7 +620,7 @@ BlazeComponent.extendComponent({
this.listId = this.parentComponent().data()._id; this.listId = this.parentComponent().data()._id;
this.swimlaneId = ''; this.swimlaneId = '';
const boardView = Meteor.user().profile.boardView; const boardView = (Meteor.user().profile || {}).boardView;
if (boardView === 'board-view-swimlanes') if (boardView === 'board-view-swimlanes')
this.swimlaneId = this.parentComponent().parentComponent().parentComponent().data()._id; this.swimlaneId = this.parentComponent().parentComponent().parentComponent().data()._id;
}, },

View file

@ -30,7 +30,7 @@ BlazeComponent.extendComponent({
cardsCount() { cardsCount() {
const list = Template.currentData(); const list = Template.currentData();
let swimlaneId = ''; let swimlaneId = '';
const boardView = Meteor.user().profile.boardView; const boardView = (Meteor.user().profile || {}).boardView;
if (boardView === 'board-view-swimlanes') if (boardView === 'board-view-swimlanes')
swimlaneId = this.parentComponent().parentComponent().data()._id; swimlaneId = this.parentComponent().parentComponent().data()._id;

View file

@ -8,7 +8,7 @@ function currentListIsInThisSwimlane(swimlaneId) {
function currentCardIsInThisList(listId, swimlaneId) { function currentCardIsInThisList(listId, swimlaneId) {
const currentCard = Cards.findOne(Session.get('currentCard')); const currentCard = Cards.findOne(Session.get('currentCard'));
const currentUser = Meteor.user(); const currentUser = Meteor.user();
if (currentUser && currentUser.profile.boardView === 'board-view-swimlanes') if (currentUser && currentUser.profile && currentUser.profile.boardView === 'board-view-swimlanes')
return currentCard && currentCard.listId === listId && currentCard.swimlaneId === swimlaneId; return currentCard && currentCard.listId === listId && currentCard.swimlaneId === swimlaneId;
else // Default view: board-view-lists else // Default view: board-view-lists
return currentCard && currentCard.listId === listId; return currentCard && currentCard.listId === listId;

View file

@ -172,7 +172,7 @@ export class Exporter {
}; };
result.users = Users.find(byUserIds, userFields).fetch().map((user) => { result.users = Users.find(byUserIds, userFields).fetch().map((user) => {
// user avatar is stored as a relative url, we export absolute // user avatar is stored as a relative url, we export absolute
if (user.profile.avatarUrl) { if ((user.profile || {}).avatarUrl) {
user.profile.avatarUrl = FlowRouter.url(user.profile.avatarUrl); user.profile.avatarUrl = FlowRouter.url(user.profile.avatarUrl);
} }
return user; return user;

View file

@ -168,17 +168,17 @@ Swimlanes.helpers({
isListTemplatesSwimlane() { isListTemplatesSwimlane() {
const user = Users.findOne(Meteor.userId()); const user = Users.findOne(Meteor.userId());
return user.profile.listTemplatesSwimlaneId === this._id; return (user.profile || {}).listTemplatesSwimlaneId === this._id;
}, },
isCardTemplatesSwimlane() { isCardTemplatesSwimlane() {
const user = Users.findOne(Meteor.userId()); const user = Users.findOne(Meteor.userId());
return user.profile.cardTemplatesSwimlaneId === this._id; return (user.profile || {}).cardTemplatesSwimlaneId === this._id;
}, },
isBoardTemplatesSwimlane() { isBoardTemplatesSwimlane() {
const user = Users.findOne(Meteor.userId()); const user = Users.findOne(Meteor.userId());
return user.profile.boardTemplatesSwimlaneId === this._id; return (user.profile || {}).boardTemplatesSwimlaneId === this._id;
}, },
remove() { remove() {

View file

@ -288,32 +288,32 @@ Users.helpers({
}, },
starredBoards() { starredBoards() {
const {starredBoards = []} = this.profile; const {starredBoards = []} = this.profile || {};
return Boards.find({archived: false, _id: {$in: starredBoards}}); return Boards.find({archived: false, _id: {$in: starredBoards}});
}, },
hasStarred(boardId) { hasStarred(boardId) {
const {starredBoards = []} = this.profile; const {starredBoards = []} = this.profile || {};
return _.contains(starredBoards, boardId); return _.contains(starredBoards, boardId);
}, },
invitedBoards() { invitedBoards() {
const {invitedBoards = []} = this.profile; const {invitedBoards = []} = this.profile || {};
return Boards.find({archived: false, _id: {$in: invitedBoards}}); return Boards.find({archived: false, _id: {$in: invitedBoards}});
}, },
isInvitedTo(boardId) { isInvitedTo(boardId) {
const {invitedBoards = []} = this.profile; const {invitedBoards = []} = this.profile || {};
return _.contains(invitedBoards, boardId); return _.contains(invitedBoards, boardId);
}, },
hasTag(tag) { hasTag(tag) {
const {tags = []} = this.profile; const {tags = []} = this.profile || {};
return _.contains(tags, tag); return _.contains(tags, tag);
}, },
hasNotification(activityId) { hasNotification(activityId) {
const {notifications = []} = this.profile; const {notifications = []} = this.profile || {};
return _.contains(notifications, activityId); return _.contains(notifications, activityId);
}, },
@ -323,7 +323,7 @@ Users.helpers({
}, },
getEmailBuffer() { getEmailBuffer() {
const {emailBuffer = []} = this.profile; const {emailBuffer = []} = this.profile || {};
return emailBuffer; return emailBuffer;
}, },
@ -358,11 +358,11 @@ Users.helpers({
}, },
getTemplatesBoardId() { getTemplatesBoardId() {
return this.profile.templatesBoardId; return (this.profile || {}).templatesBoardId;
}, },
getTemplatesBoardSlug() { getTemplatesBoardSlug() {
return Boards.findOne(this.profile.templatesBoardId).slug; return (Boards.findOne((this.profile || {}).templatesBoardId) || {}).slug;
}, },
}); });

View file

@ -10,7 +10,7 @@ Meteor.publish('boards', function() {
// Defensive programming to verify that starredBoards has the expected // Defensive programming to verify that starredBoards has the expected
// format -- since the field is in the `profile` a user can modify it. // 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]); check(starredBoards, [String]);
return Boards.find({ return Boards.find({