Sang Jun Lee 2017-02-21
Fix Label bugs.
@b687eb5c13828a939428b5803d11f50cdfbadea1
app/controllers/IssueLabelApp.java
--- app/controllers/IssueLabelApp.java
+++ app/controllers/IssueLabelApp.java
@@ -261,7 +261,14 @@
         }
 
         IssueLabel label = IssueLabel.finder.byId(id);
+        IssueLabelCategory category = label.category;
         label.delete();
+
+        long labelCategoryRemainCount = IssueLabel.findByProject(label.project).stream().filter(lb -> lb.category.equals(category)).count();
+        if (labelCategoryRemainCount == 0) {
+            category.delete();
+        }
+
         return ok();
     }
 
@@ -390,6 +397,12 @@
         }
 
         IssueLabelCategory category = form.get();
+
+        if (IssueLabelCategory.findByProject(category.project).stream()
+            .filter(lc -> lc.name.equals(category.name) && !lc.id.equals(category.id)).count() > 0) {
+            return badRequest(form.errorsAsJson());
+        }
+
         category.id = id;
         category.project =
             Project.findByOwnerAndProjectName(ownerName, projectName);
Add a comment
List