summaryrefslogtreecommitdiffstats
path: root/models/boards.js
diff options
context:
space:
mode:
authorMaxime Quandalle <maxime@quandalle.com>2015-10-16 17:49:25 +0200
committerMaxime Quandalle <maxime@quandalle.com>2015-10-16 17:49:25 +0200
commit6dedf673d5bde58c8d6ca439825cbf84303a3b4e (patch)
tree727279f4431d54ab6ea330fbc5b4b80540b7f549 /models/boards.js
parent15ebfa63c61694e4aa60e0f9c5047f678d6cf0c4 (diff)
downloadwekan-6dedf673d5bde58c8d6ca439825cbf84303a3b4e.tar.gz
wekan-6dedf673d5bde58c8d6ca439825cbf84303a3b4e.tar.bz2
wekan-6dedf673d5bde58c8d6ca439825cbf84303a3b4e.zip
Prevent duplicate board labels
43de3b8 did prevent empty labels with the same color, but we also want to prevent label with the same non-empty name and same color because the rationale is identical.
Diffstat (limited to 'models/boards.js')
-rw-r--r--models/boards.js33
1 files changed, 15 insertions, 18 deletions
diff --git a/models/boards.js b/models/boards.js
index fd0212c5..d7d40251 100644
--- a/models/boards.js
+++ b/models/boards.js
@@ -135,29 +135,26 @@ Boards.mutations({
},
addLabel(name, color) {
- const _id = Random.id(6);
-
- // If an empty label of a given color already exists we don't want to create
- // an other one because they would be indistinguishable in the UI (they
- // would still have different `_id` but that is not exposed to the user).
- if (name === '' && this.getLabel(name, color)) {
- return {};
+ // If label with the same name and color already exists we don't want to
+ // create another one because they would be indistinguishable in the UI
+ // (they would still have different `_id` but that is not exposed to the
+ // user).
+ if (!this.getLabel(name, color)) {
+ const _id = Random.id(6);
+ return { $push: {labels: { _id, name, color }}};
}
- return { $push: {labels: { _id, name, color }}};
},
editLabel(labelId, name, color) {
- const labelIndex = this.labelIndex(labelId);
-
- if (name === '' && this.getLabel(name, color)) {
- return {};
+ if (!this.getLabel(name, color)) {
+ const labelIndex = this.labelIndex(labelId);
+ return {
+ $set: {
+ [`labels.${labelIndex}.name`]: name,
+ [`labels.${labelIndex}.color`]: color,
+ },
+ };
}
- return {
- $set: {
- [`labels.${labelIndex}.name`]: name,
- [`labels.${labelIndex}.color`]: color,
- },
- };
},
removeLabel(labelId) {