Skip to content

Commit

Permalink
issue: Show event message when issue is moved
Browse files Browse the repository at this point in the history
  • Loading branch information
doortts committed Mar 13, 2017
1 parent 1c251f9 commit f1aecf9
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 80 deletions.
51 changes: 31 additions & 20 deletions app/controllers/IssueApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,13 @@ private static void addBodyChangedNotification(Issue modifiedIssue, Issue origin
}
}

private static void addIssueMovedNotification(Project previous, Issue issue) {
if (isRequestedToOtherProject(previous, issue.project)) {
NotificationEvent notiEvent = NotificationEvent.afterIssueMoved(previous, issue);
IssueEvent.addFromNotificationEvent(notiEvent, issue, UserApp.currentUser().loginId);
}
}

@With(NullProjectCheckAction.class)
public static Result editIssue(String ownerName, String projectName, Long number) {
Form<Issue> issueForm = new Form<>(Issue.class).bindFromRequest();
Expand All @@ -544,22 +551,7 @@ public static Result editIssue(String ownerName, String projectName, Long number
flash(Constants.WARNING, Messages.get("error.notfound.project"));
return badRequest(edit.render("error.validation", issueForm, Issue.findByNumber(project, number), project));
} else if (isRequestedToOtherProject(project, toOtherProject)) {
originalIssue.project = toOtherProject;
originalIssue.setNumber(Project.increaseLastIssueNumber(toOtherProject.id));
originalIssue.createdDate = JodaDateUtil.now();
originalIssue.updatedDate = JodaDateUtil.now();
originalIssue.milestone = null;
for(IssueComment comment: originalIssue.comments){
comment.projectId = originalIssue.project.id;
comment.update();
}
if (UserApp.currentUser().isMemberOf(toOtherProject) && originalIssue.labels.size() > 0) {
play.Logger.warn("--- transfered");
transferLabels(originalIssue, toOtherProject);
} else {
originalIssue.labels = new HashSet<>();
originalIssue.update();
}
moveIssueToOtherProject(originalIssue, toOtherProject);
}
}
updateSubtaskRelation(issue, originalIssue);
Expand All @@ -576,11 +568,12 @@ public void run() {
// Do not replace it to 'issue.comments = originalIssue.comments;'
issue.voters.addAll(originalIssue.voters);
issue.comments = originalIssue.comments;
if(originalIssue.project.id.equals(Project.findByOwnerAndProjectName(ownerName, projectName).id)){
addLabels(issue, request());
} else {
play.Logger.warn("originalIssue.labels: " + originalIssue.labels.size());
final Project previous = Project.findByOwnerAndProjectName(ownerName, projectName);
if(isRequestedToOtherProject(originalIssue.project, previous)){
issue.labels = originalIssue.labels;
addIssueMovedNotification(previous, issue);
} else {
addLabels(issue, request());
}

if(isSelectedToSendNotificationMail() || !originalIssue.isAuthoredBy(UserApp.currentUser())){
Expand All @@ -594,6 +587,24 @@ public void run() {
return editPosting(originalIssue, issue, issueForm, redirectTo, preUpdateHook);
}

private static void moveIssueToOtherProject(Issue originalIssue, Project toOtherProject) {
originalIssue.project = toOtherProject;
originalIssue.setNumber(Project.increaseLastIssueNumber(toOtherProject.id));
originalIssue.createdDate = JodaDateUtil.now();
originalIssue.updatedDate = JodaDateUtil.now();
originalIssue.milestone = null;
for(IssueComment comment: originalIssue.comments){
comment.projectId = originalIssue.project.id;
comment.update();
}
if (UserApp.currentUser().isMemberOf(toOtherProject) && originalIssue.labels.size() > 0) {
transferLabels(originalIssue, toOtherProject);
} else {
originalIssue.labels = new HashSet<>();
originalIssue.update();
}
}

private static void transferLabels(Issue originalIssue, Project toProject) {
Set<IssueLabel> newLabels = new HashSet<>();

Expand Down
43 changes: 22 additions & 21 deletions app/models/NotificationEvent.java
Original file line number Diff line number Diff line change
@@ -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 com.avaje.ebean.RawSqlBuilder;
Expand Down Expand Up @@ -89,10 +75,10 @@ public class NotificationEvent extends Model implements INotificationEvent {
@Enumerated(EnumType.STRING)
public EventType eventType;

@Lob
@Lob @Basic(fetch=FetchType.EAGER)
public String oldValue;

@Lob
@Lob @Basic(fetch=FetchType.EAGER)
public String newValue;

@OneToOne(mappedBy="notificationEvent", cascade = CascadeType.ALL)
Expand Down Expand Up @@ -201,6 +187,8 @@ public String getMessage(Lang lang) {
} else {
return Messages.get(lang, "notification.reviewthread.reopened");
}
case ISSUE_MOVED:
return Messages.get(lang, "notification.type.issue.moved", oldValue, newValue);
default:
return null;
}
Expand Down Expand Up @@ -727,6 +715,19 @@ public static NotificationEvent afterIssueBodyChanged(String oldBody, Issue issu
return notiEvent;
}

public static NotificationEvent afterIssueMoved(Project previous, Issue issue) {
NotificationEvent notiEvent = createFromCurrentUser(issue);
notiEvent.title = formatReplyTitle(issue);
notiEvent.receivers = getReceivers(issue);
notiEvent.eventType = ISSUE_MOVED;
notiEvent.oldValue = previous != null ? previous.owner + "/" + previous.name : null;
notiEvent.newValue = issue.project.owner + "/" + issue.project.name;

NotificationEvent.add(notiEvent);

return notiEvent;
}

private static Set<User> getReceiversForIssueBodyChanged(String oldBody, Issue issue) {
Set<User> receivers = issue.getWatchers();
receivers.addAll(getNewMentionedUsers(oldBody, issue.body));
Expand Down
27 changes: 7 additions & 20 deletions app/models/enumeration/EventType.java
Original file line number Diff line number Diff line change
@@ -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.enumeration;

import play.i18n.Messages;
Expand Down Expand Up @@ -47,7 +33,8 @@ public enum EventType {
ISSUE_REFERRED_FROM_PULL_REQUEST("notification.type.issue.referred.from.pullrequest", 16),
REVIEW_THREAD_STATE_CHANGED("notification.type.review.state.changed", 18),
ORGANIZATION_MEMBER_ENROLL_REQUEST("notification.organization.type.member.enroll",19),
COMMENT_UPDATED("notification.type.comment.updated", 20);
COMMENT_UPDATED("notification.type.comment.updated", 20),
ISSUE_MOVED("notification.type.issue.is.moved", 21);

private String descr;

Expand Down
31 changes: 12 additions & 19 deletions app/views/issue/partial_comments.scala.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
@**
/**
* Yobi, Project Hosting SW
*
* Copyright 2013 NAVER Corp.
* http://yobi.io
*
* 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
*
* Copyright Yona & Yobi Authors & NAVER Corp.
* https://yona.io
**@

@(project:Project, issue:Issue)

@import utils.TemplateHelper._
Expand Down Expand Up @@ -61,6 +46,10 @@
<strong>@Messages("pullRequest")[email protected] <a href="@routes.PullRequestApp.pullRequest(pull.toProject.owner, pull.toProject.name, pull.number)" class="link">@pull.title</a></strong>
}

@linkToProject(owner: String, name: String) ={
<strong><a href="@routes.ProjectApp.project(owner, name)" class="link">@owner/@name</a></strong>
}

@linkToCommit(commitId: String) ={
<strong>@Messages("code.commits") <a href="@routes.CodeHistoryApp.show(project.owner, project.name, commitId)" class="link">@{"@"}@commitId</a></strong>
}
Expand Down Expand Up @@ -175,6 +164,10 @@
<span class="state changed">@Messages("issue.event.referred.title")</span>
@Html(Messages("issue.event.referred",linkToUser(user.loginId, user.name),linkToCommit(event.newValue)))
}
case EventType.ISSUE_MOVED => {
<span class="state changed">@Messages("issue.event.moved.title")</span>
@Html(Messages("issue.event.moved", linkToUser(user.loginId, user.name), linkToProject(event.oldValue.split("/")(0), event.oldValue.split("/")(1))))
}
case EventType.ISSUE_REFERRED_FROM_PULL_REQUEST => {
<span class="state changed">@Messages("issue.event.referred.title")</span>
@defining(PullRequest.findById(Long.valueOf(event.newValue))) { pull =>
Expand Down
3 changes: 3 additions & 0 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ issue.error.unwatch.permission = You have no permission to unwatch it.
issue.event.assigned = {0} assigned this issue to {1}
issue.event.assignedToMe = {0} assigned this issue to oneself
issue.event.closed = {0} closed this issue
issue.event.moved = {0} moved this issue from {1}
issue.event.moved.title = moved
issue.event.open = {0} reopened this issue
issue.event.referred = {0} mentioned this issue in {1}
issue.event.referred.title = mentioned
Expand Down Expand Up @@ -418,6 +420,7 @@ notification.send.mail = Send notification mail
notification.send.mail.warning = If you are not original author, this option will be ignored. Noti mail will be sent.
notification.type.issue.assignee.changed = Issue assignee changed.
notification.type.issue.body.changed = Issue body changed
notification.type.issue.moved = Issue has been moved. From {0} To {1}
notification.type.issue.referred.from.commit = Issue mentioned in commit
notification.type.issue.referred.from.pullrequest = Issue mentioned in pull request
notification.type.issue.state.changed = Issue status changed
Expand Down
3 changes: 3 additions & 0 deletions conf/messages.ko-KR
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ issue.error.unwatch.permission = 권한이 없어 그만 지켜보기를 할 수
issue.event.assigned = {0}님이 {1}님을 이 이슈의 담당자로 지정하였습니다.
issue.event.assignedToMe = {0}님이 자신을 이슈의 담당자로 지정하였습니다.
issue.event.closed = {0}님이 이 이슈를 닫았습니다.
issue.event.moved = {0}님이 {1}로부터 이슈를 이동했습니다.
issue.event.moved.title = 이동함
issue.event.open = {0}님이 이 이슈를 다시 열었습니다.
issue.event.referred = {0} 님이 {1} 에서 이 이슈를 언급했습니다.
issue.event.referred.title = 언급됨
Expand Down Expand Up @@ -415,6 +417,7 @@ notification.send.mail = 수정에 대한 알림 메일 발송
notification.send.mail.warning = 만약 해당글의 원 작성자가 아니라면 이 옵션은 무시되고 알림 메일이 발송됩니다.
notification.type.issue.assignee.changed = 이슈 담당자 변경
notification.type.issue.body.changed = 이슈 본문 변경
notification.type.issue.moved = 이슈가 {0}에서 {1}로 이동되었습니다
notification.type.issue.referred.from.commit = 커밋에서의 이슈 언급
notification.type.issue.referred.from.pullrequest = 코드 주고받기에서의 이슈 언급
notification.type.issue.state.changed = 이슈 상태 변경
Expand Down

0 comments on commit f1aecf9

Please sign in to comment.