Renaissance

_,,ad8888888888bba,_
                  ,ad88888I888888888888888ba,
                ,88888888I88888888888888888888a,
              ,d888888888I8888888888888888888888b,
             d88888PP"""" ""YY88888888888888888888b,
           ,d88"'__,,--------,,,,.;ZZZY8888888888888,
          ,8IIl'"                ;;l"ZZZIII8888888888,
         ,I88l;'                  ;lZZZZZ888III8888888,
       ,II88Zl;.                  ;llZZZZZ888888I888888,
      ,II888Zl;.                .;;;;;lllZZZ888888I8888b
     ,II8888Z;;                 `;;;;;''llZZ8888888I8888,
     II88888Z;'                        .;lZZZ8888888I888b
     II88888Z; _,aaa,      .,aaaaa,__.l;llZZZ88888888I888
     II88888IZZZZZZZZZ,  .ZZZZZZZZZZZZZZ;llZZ88888888I888,
     II88888IZZ<'(@@>Z|  |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
    ,II88888;   `""" ;|  |ZZ; `"""     ;;llZ8888888888I888
    II888888l            `;;          .;llZZ8888888888I888,
   ,II888888Z;           ;;;        .;;llZZZ8888888888I888I
   III888888Zl;    ..,   `;;       ,;;lllZZZ88888888888I888
   II88888888Z;;...;(_    _)      ,;;;llZZZZ88888888888I888,
   II88888888Zl;;;;;' `--'Z;.   .,;;;;llZZZZ88888888888I888b
   ]I888888888Z;;;;'   ";llllll;..;;;lllZZZZ88888888888I8888,
   II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
   II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
   II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
   `II8888888888888Zl;.    ,;;lllZZZZZZZZWMZ88888888888I88888
    II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
    `II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
     `II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
      `II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
       II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
      ,II8888888888888888b   .;;lllllll;;;.;..88888888I88888888b,
      II888888888888888PZI;.  .`;;;.;;;..; ...88888888I8888888888,
      II888888888888PZ;;';;.   ;. .;.  .;. .. Y8888888I88888888888b,
     ,II888888888PZ;;'                        `8888888I8888888888888b,
     II888888888'                              888888I8888888888888888
    ,II888888888                              ,888888I8888888888888888
   ,d88888888888                              d888888I8888888888ZZZZZZ
,ad888888888888I                              8888888I8888ZZZZZZZZZZZZ
888888888888888'                              888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P'                               Y888ZZZZZZZZZZZZZZZZZZZZ
888888888,  "                                 ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888,                                ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a,      _                    ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d'                  ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand  8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
This commit is contained in:
Maxime Quandalle 2015-05-12 19:20:58 +02:00
commit 2dbea30842
128 changed files with 10521 additions and 0 deletions

8
server/lib/utils.js Normal file
View file

@ -0,0 +1,8 @@
allowIsBoardAdmin = function(userId, board) {
var admins = _.pluck(_.where(board.members, {isAdmin: true}), 'userId');
return _.contains(admins, userId);
};
allowIsBoardMember = function(userId, board) {
return _.contains(_.pluck(board.members, 'userId'), userId);
};

113
server/migrations.js Normal file
View file

@ -0,0 +1,113 @@
// Anytime you change the schema of one of the collection in a non-backward
// compatible way you have to write a migration in this file using the following
// API:
//
// Migrations.add(name, migrationCallback, optionalOrder);
Migrations.add('board-background-color', function() {
var defaultColor = '#16A085';
Boards.update({
background: {
$exists: false
}
}, {
$set: {
background: {
type: 'color',
color: defaultColor
}
}
}, {
multi: true
});
});
Migrations.add('lowercase-board-permission', function() {
_.forEach(['Public', 'Private'], function(permission) {
Boards.update(
{ permission: permission },
{ $set: { permission: permission.toLowerCase() } },
{ multi: true }
);
});
});
// Security migration: see https://github.com/libreboard/libreboard/issues/99
Migrations.add('change-attachments-type-for-non-images', function() {
var newTypeForNonImage = 'application/octet-stream';
Attachments.find().forEach(function(file) {
if (! file.isImage()) {
Attachments.update(file._id, {
$set: {
'original.type': newTypeForNonImage,
'copies.attachments.type': newTypeForNonImage
}
});
}
});
});
Migrations.add('card-covers', function() {
Cards.find().forEach(function(card) {
var cover = Attachments.findOne({ cardId: card._id, cover: true });
if (cover) {
Cards.update(card._id, {$set: {coverId: cover._id}});
}
});
Attachments.update({}, {$unset: {cover: ''}}, {multi: true});
});
Migrations.add('use-css-class-for-boards-colors', function() {
var associationTable = {
'#27AE60': 'nephritis',
'#C0392B': 'pomegranate',
'#2980B9': 'belize',
'#8E44AD': 'wisteria',
'#2C3E50': 'midnight',
'#E67E22': 'pumpkin'
};
Boards.find().forEach(function(board) {
var oldBoardColor = board.background.color;
var newBoardColor = associationTable[oldBoardColor];
Boards._collection.update({ _id: board._id }, {
$set: { color: newBoardColor },
$unset: { background: '' }
});
});
});
Migrations.add('denormalize-star-number-per-board', function() {
Boards.find().forEach(function(board) {
var nStars = Users.find({'profile.starredBoards': board._id}).count();
Boards.update(board._id, {$set: {stars: nStars}});
});
});
// We want to keep a trace of former members so we can efficiently publish their
// infos in the general board publication.
Migrations.add('add-member-isactive-field', function() {
Boards.find({}, {fields: {members: 1}}).forEach(function(board) {
var allUsersWithSomeActivity = _.chain(
Activities.find({boardId: board._id}, {fields:{userId:1}}).fetch())
.pluck('userId')
.uniq()
.value();
var currentUsers = _.pluck(board.members, 'userId');
var formerUsers = _.difference(allUsersWithSomeActivity, currentUsers);
var newMemberSet = [];
_.forEach(board.members, function(member) {
member.isActive = true;
newMemberSet.push(member);
});
_.forEach(formerUsers, function(userId) {
newMemberSet.push({
userId: userId,
isAdmin: false,
isActive: false
});
});
Boards._collection.update({_id: board._id},
{$set: {members: newMemberSet}});
});
});

View file

@ -0,0 +1,24 @@
// We use activities fields at three different places:
// 1. The home page that contains
// 2. The board
// 3.
// We use publish paginate for these three publications.
Meteor.publish('activities', function(mode, id, limit) {
check(mode, Match.Where(function(x) {
return ['board', 'card'].indexOf(x) !== -1;
}));
check(id, String);
check(limit, Number);
var selector = {};
if (mode === 'board')
selector.boardId = id;
else if (mode === 'card')
selector.cardId = id;
return Activities.find(selector, {
sort: {createdAt: -1},
limit: limit
});
});

View file

@ -0,0 +1,121 @@
// This is the publication used to display the board list. We publish all the
// non-archived boards:
// 1. that the user is a member of
// 2. the user has starred
Meteor.publish('boards', function() {
// Ensure that the user is connected
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.
var starredBoards = Users.findOne(this.userId).profile.starredBoards || [];
check(starredBoards, [String]);
return Boards.find({
archived: false,
$or: [
{ 'members.userId': this.userId },
{ _id: { $in: starredBoards } }
]
}, {
fields: {
_id: 1,
slug: 1,
title: 1,
color: 1,
permission: 1
}
});
});
Meteor.publishComposite('board', function(boardId, slug) {
check(boardId, String);
check(slug, String);
return {
find: function() {
return Boards.find({
_id: boardId,
slug: slug,
archived: false,
// If the board is not public the user has to be a member of it to see
// it.
$or: [
{ permission: 'public' },
{ 'members.userId': this.userId }
]
}, { limit: 1 });
},
children: [
// Lists
{
find: function(board) {
return Lists.find({
boardId: board._id
});
}
},
// 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
//
// I then tried to replace publish-composite by cottz:publish, but it had
// a similar problem:
//
// https://github.com/Goluis/cottz-publish/issues/4
// https://github.com/libreboard/libreboard/pull/78
//
// 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!
{
find: function(board) {
return Cards.find({
boardId: board._id
});
},
children: [
// comments
{
find: function(card) {
return CardComments.find({
cardId: card._id
});
}
},
// Attachments
{
find: function(card) {
return Attachments.find({
cardId: card._id
});
}
}
]
},
// Board members. This publication also includes former board members that
// are no more members of the board but may have some activities attached
// to them.
{
find: function(board) {
return Users.find({
_id: { $in: _.pluck(board.members, 'userId') }
});
}
}
]
};
});

View file

@ -0,0 +1,4 @@
Meteor.publish('card', function(cardId) {
check(cardId, String);
return Cards.find({ _id: cardId });
});

View file