Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
fixes Assign to me and Create by me on issue view.
Browse files Browse the repository at this point in the history
* Issue

When one user is not a project member and manager and is a group member or manager, `Assign to me` and `Create by me` do not work. Because current user is not listed on assignee's and author's combo box.

* Solution

Current user will be listed on assignee's and author's combo box.

Private-issue: 1849
  • Loading branch information
ChangsungKim committed Jan 12, 2015
1 parent cd0c092 commit 7f465fd
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 45 deletions.
31 changes: 5 additions & 26 deletions app/models/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.avaje.ebean.Ebean;
import com.avaje.ebean.ExpressionList;
import com.avaje.ebean.Page;
import controllers.UserApp;
import models.enumeration.ProjectScope;
import models.enumeration.RequestState;
import models.enumeration.ResourceType;
Expand Down Expand Up @@ -468,31 +467,7 @@ public List<ProjectUser> members() {
* If the project has a group and is protected or public, it returns all project and group members.
*/
public List<User> getAssignableUsers() {
Set<User> users = new HashSet<>();

// member of this project.
List<ProjectUser> pus = members();
for(ProjectUser pu : pus) {
users.add(pu.user);
}

// member of the group
if(hasGroup()) {
List<OrganizationUser> ous = (isPublic() || isProtected()) ? this.organization.users : this.organization.getAdmins();
for(OrganizationUser ou : ous) {
users.add(ou.user);
}
}

// sorting
List<User> result = new ArrayList<>(users);
Collections.sort(result, User.USER_NAME_COMPARATOR);

if (UserApp.currentUser().isSiteManager()) {
result.add(UserApp.currentUser());
}

return result;
return User.findUsersByProjectAndOrganization(this);
}

public List<User> getAssignableUsersAndAssignee(Issue issue) {
Expand All @@ -505,6 +480,10 @@ public List<User> getAssignableUsersAndAssignee(Issue issue) {
return users;
}

public boolean isProjectOrOrganizationUser(User user) {
return User.findUsersByProjectAndOrganization(this).contains(user);
}

public boolean isAssignableUser(User user) {
return getAssignableUsers().contains(user);
}
Expand Down
54 changes: 44 additions & 10 deletions app/models/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
import java.util.*;

import javax.persistence.*;
import javax.persistence.OrderBy;
import javax.persistence.criteria.Expression;

import com.avaje.ebean.*;
import controllers.UserApp;
import models.enumeration.*;
import models.resource.GlobalResource;
Expand All @@ -39,14 +42,11 @@
import play.data.validation.Constraints.*;
import play.db.ebean.Model;
import play.db.ebean.Transactional;
import scala.reflect.internal.Trees;
import utils.JodaDateUtil;
import utils.ReservedWordsValidator;

import com.avaje.ebean.Ebean;
import com.avaje.ebean.ExpressionList;
import com.avaje.ebean.Page;
import com.avaje.ebean.RawSql;
import com.avaje.ebean.RawSqlBuilder;
import static com.avaje.ebean.Expr.eq;

@Table(name = "n4user")
@Entity
Expand Down Expand Up @@ -327,6 +327,34 @@ public static List<User> findUsersByProject(Long projectId) {
.findList();
}

public static List<User> findUsersByProjectAndOrganization(Project project) {
Set<User> users = new HashSet<>();

// member of this project.
List<ProjectUser> pus = project.members();
for(ProjectUser pu : pus) {
users.add(pu.user);
}

// member of the group
if(project.hasGroup()) {
List<OrganizationUser> ous = (project.isPublic() || project.isProtected()) ? project.organization.users : project.organization.getAdmins();
for(OrganizationUser ou : ous) {
users.add(ou.user);
}
}

// sorting
List<User> result = new ArrayList<>(users);
Collections.sort(result, USER_NAME_COMPARATOR);

if (UserApp.currentUser().isSiteManager()) {
result.add(UserApp.currentUser());
}

return result;
}

@Transient
public Long avatarId() {
List<Attachment> attachments = Attachment.findByContainer(avatarAsResource());
Expand Down Expand Up @@ -567,13 +595,16 @@ public String avatarUrl() {
}

/**
* All user post a issue at a project whose id is {@code projectId}
* Find issue authors and {@code currentUser}
*
* Issue authors are found in a project whose id is {@code projectId}.
*
* @param currentUser
* @param projectId
* @return
*/
public static List<User> findIssueAuthorsByProjectId(long projectId) {
String sql = "select distinct user.id, user.name, user.login_id from issue issue, n4user user where issue.author_id = user.id";
public static List<User> findIssueAuthorsByProjectIdAndMe(User currentUser, long projectId) {
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;
return createUserSearchQueryWithRawSql(sql).where()
.eq("issue.project_id", projectId)
.orderBy("user.name ASC")
Expand All @@ -586,8 +617,11 @@ public static List<User> findIssueAuthorsByProjectId(long projectId) {
* @param projectId
* @return
*/
public static List<Assignee> findIssueAssigneeByProjectId(long projectId) {
return Assignee.finder.where().eq("project.id", projectId).orderBy("user.name ASC").findList();
public static List<User> findIssueAssigneeByProjectIdAndMe(User currentUser, long projectId) {
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 + "))";
return User.find.setRawSql(RawSqlBuilder.parse(sql).create())
.orderBy("name ASC")
.findList();
}

/**
Expand Down
18 changes: 9 additions & 9 deletions app/views/issue/partial_searchform.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
<select id="authorId" name="authorId" data-search="authorId"
data-toggle="select2" data-format="user" data-container-css-class="fullsize">
<option value="">@Messages("common.order.all")</option>
@if(ProjectUser.isMember(UserApp.currentUser().id, project.id)){
@if(project.isProjectOrOrganizationUser(UserApp.currentUser())) {
<option value="@UserApp.currentUser().id">@Messages("issue.list.authoredByMe")</option>
}
@for(author <- User.findIssueAuthorsByProjectId(project.id)) {
@for(author <- User.findIssueAuthorsByProjectIdAndMe(UserApp.currentUser(), project.id)) {
<option value="@author.id"
@if(param.authorId != null && param.authorId == author.id){
@if(param.authorId != null && param.authorId == author.id) {
selected
}
data-avatar-url="@author.avatarUrl"
Expand All @@ -68,15 +68,15 @@
@if(ProjectUser.isMember(UserApp.currentUser().id, project.id)){
<option value="@UserApp.currentUser().id">@Messages("issue.list.assignedToMe")</a></option>
}
@for(assignee <- User.findIssueAssigneeByProjectId(project.id)) {
<option value="@assignee.user.id"
@for(user <- User.findIssueAssigneeByProjectIdAndMe(UserApp.currentUser(), project.id)) {
<option value="@user.id"
@if(param.assigneeId != null
&& param.assigneeId == assignee.user.id){
&& param.assigneeId == user.id){
selected
}
data-avatar-url="@assignee.user.avatarUrl"
data-login-id="@assignee.user.loginId">
@assignee.user.name
data-avatar-url="@user.avatarUrl"
data-login-id="@user.loginId">
@user.name
</option>
}
</select>
Expand Down

0 comments on commit 7f465fd

Please sign in to comment.