summaryrefslogtreecommitdiffstats
path: root/models/cards.js
diff options
context:
space:
mode:
authorLauri Ojansivu <x@xet7.org>2019-03-08 20:48:49 +0200
committerGitHub <noreply@github.com>2019-03-08 20:48:49 +0200
commit951a9f81d6d98fda465c7dc724e7554353788956 (patch)
treeab07a4c14e97a6b0d307864dadbccb50346ce504 /models/cards.js
parent6f30c33f1119d68ded83f891146b86906e969c7b (diff)
parent6d6bb8fc5745300dedef85d4500e0a5ee3f9017f (diff)
downloadwekan-951a9f81d6d98fda465c7dc724e7554353788956.tar.gz
wekan-951a9f81d6d98fda465c7dc724e7554353788956.tar.bz2
wekan-951a9f81d6d98fda465c7dc724e7554353788956.zip
Merge pull request #2239 from bentiss/customFields-activities
Activities: register customFields changes in the activities
Diffstat (limited to 'models/cards.js')
-rw-r--r--models/cards.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/models/cards.js b/models/cards.js
index 43d2bbfe..eef62be1 100644
--- a/models/cards.js
+++ b/models/cards.js
@@ -1400,6 +1400,56 @@ function cardLabels(userId, doc, fieldNames, modifier) {
}
}
+function cardCustomFields(userId, doc, fieldNames, modifier) {
+ if (!_.contains(fieldNames, 'customFields'))
+ return;
+
+ // Say hello to the new customField value
+ if (modifier.$set) {
+ _.each(modifier.$set, (value, key) => {
+ if (key.startsWith('customFields')) {
+ const dotNotation = key.split('.');
+
+ // only individual changes are registered
+ if (dotNotation.length > 1) {
+ const customFieldId = doc.customFields[dot_notation[1]]._id;
+ const act = {
+ userId,
+ customFieldId,
+ value,
+ activityType: 'setCustomField',
+ boardId: doc.boardId,
+ cardId: doc._id,
+ };
+ Activities.insert(act);
+ }
+ }
+ });
+ }
+
+ // Say goodbye to the former customField value
+ if (modifier.$unset) {
+ _.each(modifier.$unset, (value, key) => {
+ if (key.startsWith('customFields')) {
+ const dotNotation = key.split('.');
+
+ // only individual changes are registered
+ if (dotNotation.length > 1) {
+ const customFieldId = doc.customFields[dot_notation[1]]._id;
+ const act = {
+ userId,
+ customFieldId,
+ activityType: 'unsetCustomField',
+ boardId: doc.boardId,
+ cardId: doc._id,
+ };
+ Activities.insert(act);
+ }
+ }
+ });
+ }
+}
+
function cardCreation(userId, doc) {
Activities.insert({
userId,
@@ -1471,6 +1521,11 @@ if (Meteor.isServer) {
cardLabels(userId, doc, fieldNames, modifier);
});
+ // Add a new activity if we edit a custom field
+ Cards.before.update((userId, doc, fieldNames, modifier) => {
+ cardCustomFields(userId, doc, fieldNames, modifier);
+ });
+
// Remove all activities associated with a card if we remove the card
// Remove also card_comments / checklists / attachments
Cards.after.remove((userId, doc) => {