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
... | ... | @@ -1,23 +1,9 @@ |
1 | 1 |
/** |
2 |
- * Yobi, Project Hosting SW |
|
3 |
- * |
|
4 |
- * Copyright 2013 NAVER Corp. |
|
5 |
- * http://yobi.io |
|
6 |
- * |
|
7 |
- * @author Keesun Baik |
|
8 |
- * |
|
9 |
- * Licensed under the Apache License, Version 2.0 (the "License"); |
|
10 |
- * you may not use this file except in compliance with the License. |
|
11 |
- * You may obtain a copy of the License at |
|
12 |
- * |
|
13 |
- * http://www.apache.org/licenses/LICENSE-2.0 |
|
14 |
- * |
|
15 |
- * Unless required by applicable law or agreed to in writing, software |
|
16 |
- * distributed under the License is distributed on an "AS IS" BASIS, |
|
17 |
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
18 |
- * See the License for the specific language governing permissions and |
|
19 |
- * limitations under the License. |
|
20 |
- */ |
|
2 |
+ * Yona, 21st Century Project Hosting SW |
|
3 |
+ * <p> |
|
4 |
+ * Copyright Yona & Yobi Authors & NAVER Corp. |
|
5 |
+ * https://yona.io |
|
6 |
+ **/ |
|
21 | 7 |
package controllers; |
22 | 8 |
|
23 | 9 |
import controllers.annotation.AnonymousCheck; |
... | ... | @@ -28,6 +14,7 @@ |
28 | 14 |
import models.Watch; |
29 | 15 |
import models.enumeration.EventType; |
30 | 16 |
import models.enumeration.Operation; |
17 |
+import play.db.ebean.Transactional; |
|
31 | 18 |
import play.i18n.Messages; |
32 | 19 |
import play.mvc.Controller; |
33 | 20 |
import play.mvc.Result; |
... | ... | @@ -38,6 +25,7 @@ |
38 | 25 |
public class WatchProjectApp extends Controller { |
39 | 26 |
|
40 | 27 |
@IsAllowed(Operation.READ) |
28 |
+ @Transactional |
|
41 | 29 |
public static Result watch(String userName, String projectName) { |
42 | 30 |
Project project = Project.findByOwnerAndProjectName(userName, projectName); |
43 | 31 |
Watch.watch(project.asResource()); |
... | ... | @@ -45,6 +33,7 @@ |
45 | 33 |
} |
46 | 34 |
|
47 | 35 |
@IsAllowed(Operation.READ) |
36 |
+ @Transactional |
|
48 | 37 |
public static Result unwatch(String userName, String projectName) { |
49 | 38 |
Project project = Project.findByOwnerAndProjectName(userName, projectName); |
50 | 39 |
Watch.unwatch(project.asResource()); |
--- app/models/UserAction.java
+++ app/models/UserAction.java
... | ... | @@ -1,23 +1,9 @@ |
1 | 1 |
/** |
2 |
- * Yobi, Project Hosting SW |
|
3 |
- * |
|
4 |
- * Copyright 2013 NAVER Corp. |
|
5 |
- * http://yobi.io |
|
6 |
- * |
|
7 |
- * @author Yi EungJun |
|
8 |
- * |
|
9 |
- * Licensed under the Apache License, Version 2.0 (the "License"); |
|
10 |
- * you may not use this file except in compliance with the License. |
|
11 |
- * You may obtain a copy of the License at |
|
12 |
- * |
|
13 |
- * http://www.apache.org/licenses/LICENSE-2.0 |
|
14 |
- * |
|
15 |
- * Unless required by applicable law or agreed to in writing, software |
|
16 |
- * distributed under the License is distributed on an "AS IS" BASIS, |
|
17 |
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
18 |
- * See the License for the specific language governing permissions and |
|
19 |
- * limitations under the License. |
|
20 |
- */ |
|
2 |
+ * Yona, 21st Century Project Hosting SW |
|
3 |
+ * <p> |
|
4 |
+ * Copyright Yona & Yobi Authors & NAVER Corp. |
|
5 |
+ * https://yona.io |
|
6 |
+ **/ |
|
21 | 7 |
package models; |
22 | 8 |
|
23 | 9 |
import models.enumeration.ResourceType; |
... | ... | @@ -49,10 +35,15 @@ |
49 | 35 |
|
50 | 36 |
public static <T extends UserAction> T findBy(Finder<Long, T> finder, User subject, |
51 | 37 |
ResourceType resourceType, String resourceId) { |
52 |
- return finder.where() |
|
38 |
+ List<T> list = finder.where() |
|
53 | 39 |
.eq("user.id", subject.id) |
54 | 40 |
.eq("resourceType", resourceType) |
55 |
- .eq("resourceId", resourceId).findUnique(); |
|
41 |
+ .eq("resourceId", resourceId).findList(); |
|
42 |
+ if(list.isEmpty()){ |
|
43 |
+ return null; |
|
44 |
+ } else { |
|
45 |
+ return list.get(0); |
|
46 |
+ } |
|
56 | 47 |
} |
57 | 48 |
|
58 | 49 |
public static <T extends UserAction> List<T> findBy(Finder<Long, T> finder, User subject, |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?