Skip to content

Commit

Permalink
Merge branch 'next' before release v1.9.1
Browse files Browse the repository at this point in the history
Reviewed-by: Suwon Chae
Reviewed-by: Mijeong Park
  • Loading branch information
mjpark03 committed Mar 22, 2018
2 parents 9e9f128 + 67d6c17 commit 6f7f75f
Show file tree
Hide file tree
Showing 19 changed files with 290 additions and 115 deletions.
31 changes: 28 additions & 3 deletions app/assets/stylesheets/less/_page.less
Original file line number Diff line number Diff line change
Expand Up @@ -2087,7 +2087,12 @@ label.inline-list {
}
.filters {
color:#666;
float: right; margin-top:5px;
float: right;
margin-top:5px;
border: 1px solid #ddd;
border-radius: 3px;
padding: 5px 10px;

.filter {
margin-right:10px;
&.active { font-weight:bold; color:@primary; }
Expand Down Expand Up @@ -7138,8 +7143,28 @@ div.diff-body[data-outdated="true"] tr:hover .icon-comment {
}

.sharer-list {
margin-top: 40px;
padding: 10px;
margin-top: -5px;
padding: 15px;

&.sharer-list-border {
border: 1px solid #ddd;
border-radius: 3px;
position: relative;

&:before {
position:absolute;
top: -9px;
left: 133px;
content: ' ';
width: 16px;
height: 16px;
border-width: 0 0 1px 1px;
border-style: solid;
border-color: #BDC3C7;
background-color: #fff;
.rotate(135deg);
}
}

.issue-share-title {
font-size: 16px;
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/ProjectApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ public static Result newWebhook(String ownerId, String projectName) {

Webhook webhook = addWebhookForm.get();

Webhook.create(project.id, webhook.payloadUrl, webhook.secret,
Webhook.create(project.id, webhook.payloadUrl.trim(), webhook.secret,
BooleanUtils.toBooleanDefaultIfNull(webhook.gitPushOnly, false));

return redirect(routes.ProjectApp.webhooks(project.owner, project.name));
Expand Down
16 changes: 8 additions & 8 deletions app/controllers/VoteApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import utils.RouteUtil;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -119,16 +120,15 @@ public static Result unvoteComment(String user, String project, Long number, Lon
}

public static List<User> getVotersForAvatar(Set<User> voters, int size){
return getSubList(voters, 0, size);
}
List<User> userList = new ArrayList<>();
Iterator<User> iterator = voters.iterator();
int index = 0;

public static List<User> getVotersForName(Set<User> voters, int fromIndex, int size){
return getSubList(voters, fromIndex, fromIndex + size);
}
while( index++ < size && iterator.hasNext() ) {
userList.add(iterator.next());
}

public static Set<User> getVotersExceptCurrentUser(Set<User> voters){
voters.remove(UserApp.currentUser());
return voters;
return userList;
}

/**
Expand Down
111 changes: 88 additions & 23 deletions app/controllers/api/IssueApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
import controllers.annotation.IsCreatable;
import controllers.routes;
import models.*;
import models.enumeration.Operation;
import models.enumeration.ResourceType;
import models.enumeration.State;
import models.enumeration.UserState;
import models.enumeration.*;
import org.apache.commons.lang3.StringUtils;
import play.db.ebean.Transactional;
import play.i18n.Messages;
Expand Down Expand Up @@ -367,6 +364,17 @@ private static ExpressionList<User> getUserExpressionList(String query, String s
return el;
}

private static ExpressionList<Project> getProjectExpressionList(String query, String searchType) {

ExpressionList<Project> el = Project.find.select("id, name").where()
.eq("projectScope", ProjectScope.PUBLIC).disjunction();

el.icontains("name", query);
el.endJunction();

return el;
}

private static void addAuthorIfNotMe(Issue issue, List<ObjectNode> users, User issueAuthor) {
if (!issue.getAuthor().loginId.equals(UserApp.currentUser().loginId)) {
addUserToUsersWithCustomName(issueAuthor, users, Messages.get("issue.assignToAuthor"));
Expand All @@ -391,12 +399,25 @@ static void addUserToUsers(User user, List<ObjectNode> users) {
userNode.put("loginId", user.loginId);
userNode.put("name", user.getDisplayName());
userNode.put("avatarUrl", user.avatarUrl());
userNode.put("type", "user");

if(!users.contains(userNode)) {
users.add(userNode);
}
}

static void addProjectToProjects(Project project, List<ObjectNode> projects) {
ObjectNode projectNode = Json.newObject();
projectNode.put("loginId", project.id);
projectNode.put("name", project.owner + "/" + project.name);
projectNode.put("avatarUrl", "");
projectNode.put("type", "project");

if(!projects.contains(projectNode)) {
projects.add(projectNode);
}
}

private static void addUserToUsersWithCustomName(User user, List<ObjectNode> users, String name) {
ObjectNode userNode = Json.newObject();
userNode.put("loginId", user.loginId);
Expand Down Expand Up @@ -580,21 +601,27 @@ public static Result findSharableUsers(String ownerName, String projectName, Lon
return status(Http.Status.NOT_ACCEPTABLE);
}

List<ObjectNode> users = new ArrayList<>();
List<ObjectNode> results = new ArrayList<>();

ExpressionList<User> el = getUserExpressionList(query, request().getQueryString("type"));
ExpressionList<User> userExpressionList = getUserExpressionList(query, request().getQueryString("type"));
ExpressionList<Project> projectExpressionList = getProjectExpressionList(query, request().getQueryString("type"));

int total = el.findRowCount();
int total = userExpressionList.findRowCount() + projectExpressionList.findRowCount();
if (total > MAX_FETCH_USERS) {
el.setMaxRows(MAX_FETCH_USERS);
userExpressionList.setMaxRows(MAX_FETCH_USERS / 2);
projectExpressionList.setMaxRows(MAX_FETCH_USERS / 2);
response().setHeader("Content-Range", "items " + MAX_FETCH_USERS + "/" + total);
}

for (User user :el.findList()) {
addUserToUsers(user, users);
for (User user :userExpressionList.findList()) {
addUserToUsers(user, results);
}

return ok(toJson(users));
for (Project project: projectExpressionList.findList()) {
addProjectToProjects(project, results);
}

return ok(toJson(results));
}

public static Result updateSharer(String owner, String projectName, Long number){
Expand All @@ -618,35 +645,73 @@ public static Result updateSharer(String owner, String projectName, Long number)
final String action = json.findValue("action").asText();

ObjectNode result = changeSharer(sharer, issue, action);
sendNotification(sharer, issue, action);

return ok(result);
}

private static ObjectNode changeSharer(JsonNode sharer, Issue issue, String action) {
ObjectNode result = Json.newObject();
for (JsonNode sharerLoginId : sharer) {
List<String> users = new ArrayList<>();

if(sharer.findValue("type").asText().equals("project")) {
changeSharerByProject(sharer.findValue("loginId").asLong(), issue, action, result, users);
} else {
changeSharerByUser(sharer.findValue("loginId").asText(), issue, action, result, users);
}

sendNotification(users, issue, action);
return result;
}

private static void changeSharerByUser(String loginId, Issue issue, String action, ObjectNode result, List<String> users) {
if ("add".equalsIgnoreCase(action)) {
addSharer(issue, loginId);
} else if ("delete".equalsIgnoreCase(action)) {
removeSharer(issue, loginId);
} else {
play.Logger.error("Unknown issue sharing action: " + issue + ":" + action + " by " + currentUser());
}

users.add(loginId);
setShareActionToResponse(action, result);
result.put("sharer", User.findByLoginId(loginId).getDisplayName());
}

private static void changeSharerByProject(Long projectId, Issue issue, String action, ObjectNode result, List<String> users) {
List<ProjectUser> projectUsers = ProjectUser.findMemberListByProject(projectId);

for (ProjectUser projectUser: projectUsers) {
if ("add".equalsIgnoreCase(action)) {
addSharer(issue, sharerLoginId.asText());
result.put("action", "added");
addSharer(issue, projectUser.user.loginId);
} else if ("delete".equalsIgnoreCase(action)) {
result.put("action", "deleted");
removeSharer(issue, sharerLoginId.asText());
removeSharer(issue, projectUser.user.loginId);
} else {
play.Logger.error("Unknown issue sharing action: " + issue + ":" + action + " by " + currentUser());
result.put("action", "Do nothing. Unsupported action: " + action);
}
result.put("sharer", User.findByLoginId(sharerLoginId.asText()).getDisplayName());
users.add(projectUser.user.loginId);
}

setShareActionToResponse(action, result);

result.put("sharer", Project.find.byId(projectId).name);
}

private static void setShareActionToResponse(String action, ObjectNode result) {
if ("add".equalsIgnoreCase(action)) {
result.put("action", "added");
} else if ("delete".equalsIgnoreCase(action)) {
result.put("action", "deleted");
} else {
result.put("action", "Do nothing. Unsupported action: " + action);
}
return result;
}

private static void sendNotification(JsonNode sharer, Issue issue, String action) {
private static void sendNotification(List<String> users, Issue issue, String action) {
Runnable preUpdateHook = new Runnable() {
@Override
public void run() {
for(JsonNode sharerLoginId: sharer){
addSharerChangedNotification(issue, sharerLoginId.asText(), action);
for(String sharerLoginId: users){
addSharerChangedNotification(issue, sharerLoginId, action);
}
}
};
Expand Down
31 changes: 24 additions & 7 deletions app/models/NotificationEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -978,11 +978,28 @@ private static Set<User> getMandatoryReceivers(Issue issue, EventType eventType)

receivers.removeAll(findUnwatchers(issue.asResource()));
receivers.removeAll(findEventUnwatchersByEventType(issue.project.id, eventType));
receivers.remove(UserApp.currentUser());
receivers.remove(findCurrentUserToBeExcluded(issue.authorId));

return receivers;
}

private static User findCurrentUserToBeExcluded(Long authorId) {
User currentUser;
try {
currentUser = UserApp.currentUser();
} catch (RuntimeException re) {
// expectation: "There is no HTTP Context available from here" runtime exception
currentUser = User.anonymous;
}

if (currentUser.isAnonymous()) {
// It is assumed that it is called by author and processed by system.
return User.find.byId(authorId);
} else {
return currentUser;
}
}

private static Set<User> getMandatoryReceivers(Posting posting, EventType eventType) {
Set<User> receivers = findWatchers(posting.asResource());
receivers.add(posting.getAuthor());
Expand All @@ -991,7 +1008,7 @@ private static Set<User> getMandatoryReceivers(Posting posting, EventType eventT

receivers.removeAll(findUnwatchers(posting.asResource()));
receivers.removeAll(findEventUnwatchersByEventType(posting.project.id, eventType));
receivers.remove(UserApp.currentUser());
receivers.remove(findCurrentUserToBeExcluded(posting.authorId));

return receivers;
}
Expand All @@ -1006,16 +1023,16 @@ private static Set<User> getMandatoryReceivers(Comment comment, EventType eventT

receivers.removeAll(findUnwatchers(parent.asResource()));
receivers.removeAll(findEventUnwatchersByEventType(comment.projectId, eventType));
receivers.remove(UserApp.currentUser());
receivers.remove(findCurrentUserToBeExcluded(comment.authorId));

return receivers;
}

private static Set<User> getProjectCommitReceivers(Project project, EventType eventType) {
private static Set<User> getProjectCommitReceivers(Project project, EventType eventType, User sender) {
Set<User> receivers = findMembersOnlyFromWatchers(project);
receivers.removeAll(findUnwatchers(project.asResource()));
receivers.removeAll(findEventUnwatchersByEventType(project.id, eventType));
receivers.remove(UserApp.currentUser());
receivers.remove(sender);

return receivers;
}
Expand All @@ -1042,7 +1059,7 @@ private static Set<User> extractMembers(Project project) {
private static Set<User> getReceiversForIssueBodyChanged(String oldBody, Issue issue) {
Set<User> receivers = getMandatoryReceivers(issue, ISSUE_BODY_CHANGED);
receivers.addAll(getNewMentionedUsers(oldBody, issue.body));
receivers.remove(UserApp.currentUser());
receivers.remove(findCurrentUserToBeExcluded(issue.authorId));
return receivers;
}

Expand Down Expand Up @@ -1183,7 +1200,7 @@ public static void afterOrganizationMemberRequest(Organization organization, Use
public static void afterNewCommits(List<RevCommit> commits, List<String> refNames, Project project, User sender, String title) {
NotificationEvent notiEvent = createFrom(sender, project);
notiEvent.title = title;
notiEvent.receivers = getProjectCommitReceivers(project, NEW_COMMIT);
notiEvent.receivers = getProjectCommitReceivers(project, NEW_COMMIT, sender);
notiEvent.eventType = NEW_COMMIT;
notiEvent.oldValue = null;
notiEvent.newValue = newCommitsMessage(commits, refNames, project);
Expand Down
2 changes: 1 addition & 1 deletion app/models/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public Set<User> findAuthorsAndWatchers() {
}

private Set<User> getIssueUsers() {
String issueSql = "SELECT distinct author_id id FROM ISSUE where project_id=" + this.id;
String issueSql = "select distinct author_id id from issue where project_id=" + this.id;
return User.find.setRawSql(RawSqlBuilder.parse(issueSql).create()).findSet();
}

Expand Down
13 changes: 10 additions & 3 deletions app/models/ProjectUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public static void create(Long userId, Long projectId, Long roleId) {
}

public static void delete(Long userId, Long projectId) {
ProjectUser.findByIds(userId, projectId).delete();
ProjectUser projectUser = ProjectUser.findByIds(userId, projectId);
if (projectUser != null) {
projectUser.delete();
}
}

public static void assignRole(Long userId, Long projectId, Long roleId) {
Expand All @@ -87,8 +90,12 @@ public static void assignRole(Long userId, Long projectId, RoleType roleType) {
}

public static ProjectUser findByIds(Long userId, Long projectId) {
return find.where().eq("user.id", userId).eq("project.id", projectId)
.ne("role.id", RoleType.SITEMANAGER.roleType()).findUnique();
List<ProjectUser> projectUsers = find.where().eq("user.id", userId).eq("project.id", projectId)
.ne("role.id", RoleType.SITEMANAGER.roleType()).findList();
if(projectUsers.size() > 0) {
return projectUsers.get(0);
}
return null;
}

public static List<ProjectUser> findMemberListByProject(Long projectId) {
Expand Down
4 changes: 4 additions & 0 deletions app/models/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,10 @@ public String extractDepartmentPart(){
}

public String getDisplayName(){
if (UserApp.currentUser().isAnonymous()) {
return name;
}

if (StringUtils.isNotBlank(englishName) && lang != null && UserApp.currentUser().lang.startsWith("en")) {
return englishName + " " + extractDepartmentPart();
} else {
Expand Down
Loading

0 comments on commit 6f7f75f

Please sign in to comment.