doortts doortts 2017-01-19
watch: Fix duplicated watched project list by accidently
This bug was reported by Hyeonseok Jeong.
Thanks! :)

I added defensive and self restoration codes.
@b5a0bcd7e05558b17189abc8e98629f0c8e18ffd
app/controllers/WatchProjectApp.java
--- app/controllers/WatchProjectApp.java
+++ app/controllers/WatchProjectApp.java
@@ -1,23 +1,9 @@
 /**
- * Yobi, Project Hosting SW
- *
- * Copyright 2013 NAVER Corp.
- * http://yobi.io
- *
- * @author Keesun Baik
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+ * Yona, 21st Century Project Hosting SW
+ * <p>
+ * Copyright Yona & Yobi Authors & NAVER Corp.
+ * https://yona.io
+ **/
 package controllers;
 
 import controllers.annotation.AnonymousCheck;
@@ -28,6 +14,7 @@
 import models.Watch;
 import models.enumeration.EventType;
 import models.enumeration.Operation;
+import play.db.ebean.Transactional;
 import play.i18n.Messages;
 import play.mvc.Controller;
 import play.mvc.Result;
@@ -38,6 +25,7 @@
 public class WatchProjectApp extends Controller {
 
     @IsAllowed(Operation.READ)
+    @Transactional
     public static Result watch(String userName, String projectName) {
         Project project = Project.findByOwnerAndProjectName(userName, projectName);
         Watch.watch(project.asResource());
@@ -45,6 +33,7 @@
     }
 
     @IsAllowed(Operation.READ)
+    @Transactional
     public static Result unwatch(String userName, String projectName) {
         Project project = Project.findByOwnerAndProjectName(userName, projectName);
         Watch.unwatch(project.asResource());
app/models/UserAction.java
--- app/models/UserAction.java
+++ app/models/UserAction.java
@@ -1,23 +1,9 @@
 /**
- * Yobi, Project Hosting SW
- *
- * Copyright 2013 NAVER Corp.
- * http://yobi.io
- *
- * @author Yi EungJun
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+ * Yona, 21st Century Project Hosting SW
+ * <p>
+ * Copyright Yona & Yobi Authors & NAVER Corp.
+ * https://yona.io
+ **/
 package models;
 
 import models.enumeration.ResourceType;
@@ -49,10 +35,15 @@
 
     public static <T extends UserAction> T findBy(Finder<Long, T> finder, User subject,
                                       ResourceType resourceType, String resourceId) {
-        return finder.where()
+        List<T> list = finder.where()
                 .eq("user.id", subject.id)
                 .eq("resourceType", resourceType)
-                .eq("resourceId", resourceId).findUnique();
+                .eq("resourceId", resourceId).findList();
+        if(list.isEmpty()){
+            return null;
+        } else {
+            return list.get(0);
+        }
     }
 
     public static <T extends UserAction> List<T> findBy(Finder<Long, T> finder, User subject,
Add a comment
List