summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorguillaume <guillaume.cassou@orange.fr>2019-04-23 18:00:09 +0200
committerguillaume <guillaume.cassou@orange.fr>2019-04-23 18:00:09 +0200
commit8137f2692fe3e1d9f1c0a9b635ef15cdf36728f7 (patch)
treea054ec502113381363254b8d386de05bfd1626e4 /models
parent6933424fca56fc84b0060ff97b97303d36ab5fb0 (diff)
downloadwekan-8137f2692fe3e1d9f1c0a9b635ef15cdf36728f7.tar.gz
wekan-8137f2692fe3e1d9f1c0a9b635ef15cdf36728f7.tar.bz2
wekan-8137f2692fe3e1d9f1c0a9b635ef15cdf36728f7.zip
remove feature
Diffstat (limited to 'models')
-rw-r--r--models/boards.js19
-rw-r--r--models/cards.js4
-rw-r--r--models/checklists.js2
-rw-r--r--models/lists.js10
-rw-r--r--models/swimlanes.js20
5 files changed, 50 insertions, 5 deletions
diff --git a/models/boards.js b/models/boards.js
index 36651d54..b07d9e27 100644
--- a/models/boards.js
+++ b/models/boards.js
@@ -803,6 +803,13 @@ Boards.mutations({
},
});
+function boardRemover(userId, doc) {
+ [Cards, Lists, Swimlanes, Integrations, Rules, Activities].forEach((element) => {
+ element.remove({ boardId: doc._id });
+ });
+}
+
+
if (Meteor.isServer) {
Boards.allow({
insert: Meteor.userId,
@@ -966,6 +973,18 @@ if (Meteor.isServer) {
}
});
+ Boards.before.remove((userId, doc) => {
+ boardRemover(userId, doc);
+ // Add removeBoard activity to keep it
+ Activities.insert({
+ userId,
+ type: 'board',
+ activityTypeId: doc._id,
+ activityType: 'removeBoard',
+ boardId: doc._id,
+ });
+ });
+
// Add a new activity if we add or remove a member to the board
Boards.after.update((userId, doc, fieldNames, modifier) => {
if (!_.contains(fieldNames, 'members')) {
diff --git a/models/cards.js b/models/cards.js
index 7430ae52..d5a59377 100644
--- a/models/cards.js
+++ b/models/cards.js
@@ -1518,7 +1518,7 @@ function cardCreation(userId, doc) {
}
function cardRemover(userId, doc) {
- Activities.remove({
+ ChecklistItems.remove({
cardId: doc._id,
});
Checklists.remove({
@@ -1583,7 +1583,7 @@ if (Meteor.isServer) {
// Remove all activities associated with a card if we remove the card
// Remove also card_comments / checklists / attachments
- Cards.after.remove((userId, doc) => {
+ Cards.before.remove((userId, doc) => {
cardRemover(userId, doc);
});
}
diff --git a/models/checklists.js b/models/checklists.js
index d5063faf..33cb0f40 100644
--- a/models/checklists.js
+++ b/models/checklists.js
@@ -157,8 +157,6 @@ if (Meteor.isServer) {
listId: doc.listId,
swimlaneId: doc.swimlaneId,
});
-
-
});
}
diff --git a/models/lists.js b/models/lists.js
index a8e597ee..1a0910c2 100644
--- a/models/lists.js
+++ b/models/lists.js
@@ -217,6 +217,10 @@ Lists.helpers({
isTemplateList() {
return this.type === 'template-list';
},
+
+ remove() {
+ Lists.remove({ _id: this._id});
+ },
});
Lists.mutations({
@@ -310,6 +314,12 @@ if (Meteor.isServer) {
});
Lists.before.remove((userId, doc) => {
+ const cards = Cards.find({ listId: doc._id });
+ if (cards) {
+ cards.forEach((card) => {
+ Cards.remove(card._id);
+ });
+ }
Activities.insert({
userId,
type: 'list',
diff --git a/models/swimlanes.js b/models/swimlanes.js
index 9da4afb5..bd2565af 100644
--- a/models/swimlanes.js
+++ b/models/swimlanes.js
@@ -180,6 +180,10 @@ Swimlanes.helpers({
const user = Users.findOne(Meteor.userId());
return user.profile.boardTemplatesSwimlaneId === this._id;
},
+
+ remove() {
+ Swimlanes.remove({ _id: this._id});
+ },
});
Swimlanes.mutations({
@@ -234,7 +238,21 @@ if (Meteor.isServer) {
});
});
- Swimlanes.before.remove((userId, doc) => {
+ Swimlanes.before.remove(function(userId, doc) {
+ const lists = Lists.find({
+ boardId: doc.boardId,
+ swimlaneId: {$in: [doc._id, '']},
+ archived: false,
+ }, { sort: ['sort'] });
+
+ if (lists.count() < 2) {
+ lists.forEach((list) => {
+ list.remove();
+ });
+ } else {
+ Cards.remove({swimlaneId: doc._id});
+ }
+
Activities.insert({
userId,
type: 'swimlane',