[Notice] Announcing the End of Demo Server [Read me]

Merge branch 'issue-1849' of dlab/hive
from pull-request 1412 * refs/heads/issue-1849: fixes `Assign to me` and `Create by me` on issue view. Reviewed-by: 채수원
@f5a4d3d6c27dc38e824a48fa67e4e9d6270f0d58
--- app/models/Project.java
+++ app/models/Project.java
... | ... | @@ -23,7 +23,6 @@ |
23 | 23 |
import com.avaje.ebean.Ebean; |
24 | 24 |
import com.avaje.ebean.ExpressionList; |
25 | 25 |
import com.avaje.ebean.Page; |
26 |
-import controllers.UserApp; |
|
27 | 26 |
import models.enumeration.ProjectScope; |
28 | 27 |
import models.enumeration.RequestState; |
29 | 28 |
import models.enumeration.ResourceType; |
... | ... | @@ -468,31 +467,7 @@ |
468 | 467 |
* If the project has a group and is protected or public, it returns all project and group members. |
469 | 468 |
*/ |
470 | 469 |
public List<User> getAssignableUsers() { |
471 |
- Set<User> users = new HashSet<>(); |
|
472 |
- |
|
473 |
- // member of this project. |
|
474 |
- List<ProjectUser> pus = members(); |
|
475 |
- for(ProjectUser pu : pus) { |
|
476 |
- users.add(pu.user); |
|
477 |
- } |
|
478 |
- |
|
479 |
- // member of the group |
|
480 |
- if(hasGroup()) { |
|
481 |
- List<OrganizationUser> ous = (isPublic() || isProtected()) ? this.organization.users : this.organization.getAdmins(); |
|
482 |
- for(OrganizationUser ou : ous) { |
|
483 |
- users.add(ou.user); |
|
484 |
- } |
|
485 |
- } |
|
486 |
- |
|
487 |
- // sorting |
|
488 |
- List<User> result = new ArrayList<>(users); |
|
489 |
- Collections.sort(result, User.USER_NAME_COMPARATOR); |
|
490 |
- |
|
491 |
- if (UserApp.currentUser().isSiteManager()) { |
|
492 |
- result.add(UserApp.currentUser()); |
|
493 |
- } |
|
494 |
- |
|
495 |
- return result; |
|
470 |
+ return User.findUsersByProjectAndOrganization(this); |
|
496 | 471 |
} |
497 | 472 |
|
498 | 473 |
public List<User> getAssignableUsersAndAssignee(Issue issue) { |
... | ... | @@ -505,6 +480,10 @@ |
505 | 480 |
return users; |
506 | 481 |
} |
507 | 482 |
|
483 |
+ public boolean isProjectOrOrganizationUser(User user) { |
|
484 |
+ return User.findUsersByProjectAndOrganization(this).contains(user); |
|
485 |
+ } |
|
486 |
+ |
|
508 | 487 |
public boolean isAssignableUser(User user) { |
509 | 488 |
return getAssignableUsers().contains(user); |
510 | 489 |
} |
--- app/models/User.java
+++ app/models/User.java
... | ... | @@ -24,7 +24,10 @@ |
24 | 24 |
import java.util.*; |
25 | 25 |
|
26 | 26 |
import javax.persistence.*; |
27 |
+import javax.persistence.OrderBy; |
|
28 |
+import javax.persistence.criteria.Expression; |
|
27 | 29 |
|
30 |
+import com.avaje.ebean.*; |
|
28 | 31 |
import controllers.UserApp; |
29 | 32 |
import models.enumeration.*; |
30 | 33 |
import models.resource.GlobalResource; |
... | ... | @@ -39,14 +42,11 @@ |
39 | 42 |
import play.data.validation.Constraints.*; |
40 | 43 |
import play.db.ebean.Model; |
41 | 44 |
import play.db.ebean.Transactional; |
45 |
+import scala.reflect.internal.Trees; |
|
42 | 46 |
import utils.JodaDateUtil; |
43 | 47 |
import utils.ReservedWordsValidator; |
44 | 48 |
|
45 |
-import com.avaje.ebean.Ebean; |
|
46 |
-import com.avaje.ebean.ExpressionList; |
|
47 |
-import com.avaje.ebean.Page; |
|
48 |
-import com.avaje.ebean.RawSql; |
|
49 |
-import com.avaje.ebean.RawSqlBuilder; |
|
49 |
+import static com.avaje.ebean.Expr.eq; |
|
50 | 50 |
|
51 | 51 |
@Table(name = "n4user") |
52 | 52 |
@Entity |
... | ... | @@ -327,6 +327,34 @@ |
327 | 327 |
.findList(); |
328 | 328 |
} |
329 | 329 |
|
330 |
+ public static List<User> findUsersByProjectAndOrganization(Project project) { |
|
331 |
+ Set<User> users = new HashSet<>(); |
|
332 |
+ |
|
333 |
+ // member of this project. |
|
334 |
+ List<ProjectUser> pus = project.members(); |
|
335 |
+ for(ProjectUser pu : pus) { |
|
336 |
+ users.add(pu.user); |
|
337 |
+ } |
|
338 |
+ |
|
339 |
+ // member of the group |
|
340 |
+ if(project.hasGroup()) { |
|
341 |
+ List<OrganizationUser> ous = (project.isPublic() || project.isProtected()) ? project.organization.users : project.organization.getAdmins(); |
|
342 |
+ for(OrganizationUser ou : ous) { |
|
343 |
+ users.add(ou.user); |
|
344 |
+ } |
|
345 |
+ } |
|
346 |
+ |
|
347 |
+ // sorting |
|
348 |
+ List<User> result = new ArrayList<>(users); |
|
349 |
+ Collections.sort(result, USER_NAME_COMPARATOR); |
|
350 |
+ |
|
351 |
+ if (UserApp.currentUser().isSiteManager()) { |
|
352 |
+ result.add(UserApp.currentUser()); |
|
353 |
+ } |
|
354 |
+ |
|
355 |
+ return result; |
|
356 |
+ } |
|
357 |
+ |
|
330 | 358 |
@Transient |
331 | 359 |
public Long avatarId() { |
332 | 360 |
List<Attachment> attachments = Attachment.findByContainer(avatarAsResource()); |
... | ... | @@ -567,13 +595,16 @@ |
567 | 595 |
} |
568 | 596 |
|
569 | 597 |
/** |
570 |
- * All user post a issue at a project whose id is {@code projectId} |
|
598 |
+ * Find issue authors and {@code currentUser} |
|
571 | 599 |
* |
600 |
+ * Issue authors are found in a project whose id is {@code projectId}. |
|
601 |
+ * |
|
602 |
+ * @param currentUser |
|
572 | 603 |
* @param projectId |
573 | 604 |
* @return |
574 | 605 |
*/ |
575 |
- public static List<User> findIssueAuthorsByProjectId(long projectId) { |
|
576 |
- String sql = "select distinct user.id, user.name, user.login_id from issue issue, n4user user where issue.author_id = user.id"; |
|
606 |
+ public static List<User> findIssueAuthorsByProjectIdAndMe(User currentUser, long projectId) { |
|
607 |
+ String sql = "select distinct user.id, user.name, user.login_id from issue issue, n4user user where issue.author_id = user.id or user.id = " + currentUser.id; |
|
577 | 608 |
return createUserSearchQueryWithRawSql(sql).where() |
578 | 609 |
.eq("issue.project_id", projectId) |
579 | 610 |
.orderBy("user.name ASC") |
... | ... | @@ -586,8 +617,11 @@ |
586 | 617 |
* @param projectId |
587 | 618 |
* @return |
588 | 619 |
*/ |
589 |
- public static List<Assignee> findIssueAssigneeByProjectId(long projectId) { |
|
590 |
- return Assignee.finder.where().eq("project.id", projectId).orderBy("user.name ASC").findList(); |
|
620 |
+ public static List<User> findIssueAssigneeByProjectIdAndMe(User currentUser, long projectId) { |
|
621 |
+ String sql = "SELECT id, name FROM n4user WHERE id = " + currentUser.id + " or id IN (SELECT DISTINCT user_id FROM assignee WHERE id IN (SELECT DISTINCT assignee_id FROM issue WHERE project_id = " + projectId + "))"; |
|
622 |
+ return User.find.setRawSql(RawSqlBuilder.parse(sql).create()) |
|
623 |
+ .orderBy("name ASC") |
|
624 |
+ .findList(); |
|
591 | 625 |
} |
592 | 626 |
|
593 | 627 |
/** |
--- app/views/issue/partial_searchform.scala.html
+++ app/views/issue/partial_searchform.scala.html
... | ... | @@ -41,12 +41,12 @@ |
41 | 41 |
<select id="authorId" name="authorId" data-search="authorId" |
42 | 42 |
data-toggle="select2" data-format="user" data-container-css-class="fullsize"> |
43 | 43 |
<option value="">@Messages("common.order.all")</option> |
44 |
- @if(ProjectUser.isMember(UserApp.currentUser().id, project.id)){ |
|
44 |
+ @if(project.isProjectOrOrganizationUser(UserApp.currentUser())) { |
|
45 | 45 |
<option value="@UserApp.currentUser().id">@Messages("issue.list.authoredByMe")</option> |
46 | 46 |
} |
47 |
- @for(author <- User.findIssueAuthorsByProjectId(project.id)) { |
|
47 |
+ @for(author <- User.findIssueAuthorsByProjectIdAndMe(UserApp.currentUser(), project.id)) { |
|
48 | 48 |
<option value="@author.id" |
49 |
- @if(param.authorId != null && param.authorId == author.id){ |
|
49 |
+ @if(param.authorId != null && param.authorId == author.id) { |
|
50 | 50 |
selected |
51 | 51 |
} |
52 | 52 |
data-avatar-url="@author.avatarUrl" |
... | ... | @@ -68,15 +68,15 @@ |
68 | 68 |
@if(ProjectUser.isMember(UserApp.currentUser().id, project.id)){ |
69 | 69 |
<option value="@UserApp.currentUser().id">@Messages("issue.list.assignedToMe")</a></option> |
70 | 70 |
} |
71 |
- @for(assignee <- User.findIssueAssigneeByProjectId(project.id)) { |
|
72 |
- <option value="@assignee.user.id" |
|
71 |
+ @for(user <- User.findIssueAssigneeByProjectIdAndMe(UserApp.currentUser(), project.id)) { |
|
72 |
+ <option value="@user.id" |
|
73 | 73 |
@if(param.assigneeId != null |
74 |
- && param.assigneeId == assignee.user.id){ |
|
74 |
+ && param.assigneeId == user.id){ |
|
75 | 75 |
selected |
76 | 76 |
} |
77 |
- data-avatar-url="@assignee.user.avatarUrl" |
|
78 |
- data-login-id="@assignee.user.loginId"> |
|
79 |
- @assignee.user.name |
|
77 |
+ data-avatar-url="@user.avatarUrl" |
|
78 |
+ data-login-id="@user.loginId"> |
|
79 |
+ @user.name |
|
80 | 80 |
</option> |
81 | 81 |
} |
82 | 82 |
</select> |
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?