Skip to content

Commit

Permalink
notification: Add noti mail send option
Browse files Browse the repository at this point in the history
User can choose to send modification mail or not
  • Loading branch information
doortts committed Jun 23, 2015
1 parent 1aedcfb commit 5f64376
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 11 deletions.
13 changes: 13 additions & 0 deletions app/assets/stylesheets/less/_page.less
Original file line number Diff line number Diff line change
Expand Up @@ -6239,3 +6239,16 @@ div.diff-body[data-outdated="true"] tr:hover .icon-comment {
border-radius: 2px;
color: #3592B5;
}

.send-notification-check {
vertical-align: middle;
padding: 9px;
border-radius: 3px;
strong {
margin-right: 5px;
}
.checkbox.inline {
padding-top: 0px;
}
}

16 changes: 16 additions & 0 deletions app/controllers/AbstractPostingApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import play.mvc.*;
import utils.*;

import java.util.Map;

@AnonymousCheck
public class AbstractPostingApp extends Controller {
public static final int ITEMS_PER_PAGE = 15;
Expand Down Expand Up @@ -156,4 +158,18 @@ private static boolean isTemporaryFilesExist(String[] files) {
}
return StringUtils.isNotBlank(files[0]);
}

protected static boolean isSelectedToSendNotificationMail() {
Map<String,String[]> data;
if (isMultiPartFormData()) {
data = request().body().asMultipartFormData().asFormUrlEncoded();
} else {
data = request().body().asFormUrlEncoded();
}
return "yes".equalsIgnoreCase(HttpUtil.getFirstValueFromQuery(data, "notificationMail"));
}

private static boolean isMultiPartFormData() {
return request().body().asMultipartFormData() != null;
}
}
7 changes: 6 additions & 1 deletion app/controllers/BoardApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ public static Result editPost(String userName, String projectName, Long number)
@Override
public void run() {
post.comments = original.comments;
if(isSelectedToSendNotificationMail() || !original.isAuthoredBy(UserApp.currentUser())){
NotificationEvent.afterNewPost(post);
}
}
};

Expand Down Expand Up @@ -294,7 +297,9 @@ public static Result newComment(String owner, String projectName, Long number) t
if (existingComment != null) {
existingComment.contents = comment.contents;
savedComment = saveComment(existingComment, getContainerUpdater(posting, comment));
NotificationEvent.afterCommentUpdated(savedComment);
if(isSelectedToSendNotificationMail() || !existingComment.isAuthoredBy(UserApp.currentUser())){
NotificationEvent.afterCommentUpdated(savedComment);
}
} else {
savedComment = saveComment(comment, getContainerUpdater(posting, comment));
NotificationEvent.afterNewComment(savedComment);
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/CommentApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package controllers;

import controllers.annotation.AnonymousCheck;
import models.Comment;
import models.enumeration.Operation;
import models.resource.Resource;
import play.db.ebean.Transactional;
Expand Down Expand Up @@ -54,5 +55,8 @@ public static Result delete(String type, String id) {
}
}

public static boolean isCurrentUserTheAuthor(Comment comment){
return UserApp.currentUser().loginId.equals(comment.authorLoginId);
}

}
12 changes: 8 additions & 4 deletions app/controllers/IssueApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,11 @@ public void run() {
issue.comments = originalIssue.comments;
addLabels(issue, request());

addAssigneeChangedNotification(issue, originalIssue);
addStateChangedNotification(issue, originalIssue);
addBodyChangedNotification(issue, originalIssue);
if(isSelectedToSendNotificationMail() || !originalIssue.isAuthoredBy(UserApp.currentUser())){
addAssigneeChangedNotification(issue, originalIssue);
addStateChangedNotification(issue, originalIssue);
addBodyChangedNotification(issue, originalIssue);
}
}
};

Expand Down Expand Up @@ -602,7 +604,9 @@ public static Result newComment(String ownerName, String projectName, Long numbe
if (existingComment != null) {
existingComment.contents = comment.contents;
savedComment = saveComment(existingComment, getContainerUpdater(issue, comment));
NotificationEvent.afterCommentUpdated(savedComment);
if(isSelectedToSendNotificationMail() || !existingComment.isAuthoredBy(UserApp.currentUser())){
NotificationEvent.afterCommentUpdated(savedComment);
}
} else {
savedComment = saveComment(comment, getContainerUpdater(issue, comment));
NotificationEvent.afterNewComment(savedComment);
Expand Down
6 changes: 6 additions & 0 deletions app/models/AbstractPosting.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
import models.enumeration.ResourceType;
import models.resource.Resource;
import models.resource.ResourceConvertible;
import org.apache.commons.lang.StringUtils;
import org.joda.time.Duration;
import play.data.format.Formats;
import play.data.validation.Constraints;
import play.db.ebean.Model;
import play.db.ebean.Transactional;
import utils.JodaDateUtil;

import javax.annotation.Nonnull;
import javax.persistence.*;
import javax.validation.constraints.Size;
import java.util.Date;
Expand Down Expand Up @@ -257,4 +259,8 @@ protected void updateMention() {
}

public abstract void checkLabels() throws IssueLabel.IssueLabelException;

public boolean isAuthoredBy(@Nonnull User user){
return StringUtils.equalsIgnoreCase(this.authorLoginId, user.loginId);
}
}
6 changes: 6 additions & 0 deletions app/models/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
import com.avaje.ebean.annotation.Transactional;
import models.resource.Resource;
import models.resource.ResourceConvertible;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.joda.time.Duration;
import play.data.validation.Constraints;
import play.db.ebean.Model;
import utils.JodaDateUtil;

import javax.annotation.Nonnull;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.MappedSuperclass;
Expand Down Expand Up @@ -153,4 +155,8 @@ public int hashCode() {
.append(authorName)
.toHashCode();
}

public boolean isAuthoredBy(@Nonnull User user){
return StringUtils.equalsIgnoreCase(this.authorLoginId, user.loginId);
}
}
8 changes: 8 additions & 0 deletions app/views/board/edit.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@
</div>

<div class="actions">
@if(posting.getAuthor.equals(UserApp.currentUser()) && !posting.readme){
<span class="send-notification-check">
<label class="checkbox inline">
<input type="checkbox" name="notificationMail" id="notificationMail" value="yes" checked>
<strong>@Messages("notification.send.mail")</strong>
</label>
</span>
}
<button class="ybtn ybtn-info" tabindex="3">@Messages("button.save")</button><!--
--><a href="javascript:history.back();" class="ybtn" tabindex="4">@Messages("button.cancel")</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/board/partial_comments.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</span>
</div>

@common.commentUpdateForm(comment.id, routes.BoardApp.newComment(project.owner, project.name, post.getNumber).toString(), comment.contents)
@common.commentUpdateForm(comment, routes.BoardApp.newComment(project.owner, project.name, post.getNumber).toString(), comment.contents)

<div id="[email protected]">
<div class="comment-body markdown-wrap" data-via-email="@OriginalEmail.exists(comment.asResource)">@Html(Markdown.render(comment.contents, project))</div>
Expand Down
16 changes: 12 additions & 4 deletions app/views/common/commentUpdateForm.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**@
@(commentId:Long, action:String, contents:String)
@(comment:Comment, action:String, contents:String)

<div id="comment-editform-@commentId" class="comment-update-form">
<div id="comment-editform-@comment.id" class="comment-update-form">
<form action="@action" method="post">
<input type="hidden" name="id" value="@commentId">
<input type="hidden" name="id" value="@comment.id">

<div class="write-comment-box">
<div class="write-comment-wrap">
@common.editor("contents", contents,"", "update-comment-body")

<div class="right-txt comment-update-button">
<button type="button" class="ybtn ybtn-cancel" data-comment-id="@commentId">@Messages("button.cancel")</button>
@if(comment.isAuthoredBy(UserApp.currentUser())){
<span class="send-notification-check" data-toggle='popover' data-trigger="hover" data-placement="top" data-content="@Messages("notification.send.mail.warning")">
<label class="checkbox inline">
<input type="checkbox" name="notificationMail" id="notificationMail" value="yes" checked>
<strong>@Messages("notification.send.mail")</strong>
</label>
</span>
}
<button type="button" class="ybtn ybtn-cancel" data-comment-id="@comment.id">@Messages("button.cancel")</button>
<button type="submit" class="ybtn ybtn-info">@Messages("button.save")</button>
</div>
</div>
Expand Down
8 changes: 8 additions & 0 deletions app/views/issue/edit.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@
@** end of fileUploader **@

<div class=" actrow right-txt">
@if(issue.isAuthoredBy(UserApp.currentUser())){
<span class="send-notification-check">
<label class="checkbox inline">
<input type="checkbox" name="notificationMail" id="notificationMail" value="yes" checked>
<strong>@Messages("notification.send.mail")</strong>
</label>
</span>
}
<button type="submit" class="ybtn ybtn-info">@Messages("button.save")</button><!--
--><a href="javascript:history.back();" class="ybtn">@Messages("button.cancel")</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/issue/partial_comments.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
</span>
</div>

@common.commentUpdateForm(comment.id, routes.IssueApp.newComment(project.owner, project.name, issue.getNumber).toString(), comment.contents)
@common.commentUpdateForm(comment, routes.IssueApp.newComment(project.owner, project.name, issue.getNumber).toString(), comment.contents)

<div id="[email protected]">
<div class="comment-body markdown-wrap" data-via-email="@OriginalEmail.exists(comment.asResource)">@Html(Markdown.render(comment.contents, project))</div>
Expand Down
2 changes: 2 additions & 0 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ notification.reviewthread.closed = Review thread closed.
notification.reviewthread.reopened = Review thread reopened
notification.reviewthread.inTheFile = In {0}:
notification.type.comment.updated = Comment updated
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.referred.from.commit = Issue mentioned in commit
Expand Down
2 changes: 2 additions & 0 deletions conf/messages.ko-KR
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ notification.reviewthread.closed = 리뷰 스레드 닫힘
notification.reviewthread.reopened = 리뷰 스레드 다시 열림
notification.reviewthread.inTheFile = {0} 에서:
notification.type.comment.updated = 댓글 수정
notification.send.mail = 수정에 대한 알림 메일 발송
notification.send.mail.warning = 만약 해당글의 원 작성자가 아니라면 이 옵션은 무시되고 알림 메일이 발송됩니다.
notification.type.issue.assignee.changed = 이슈 담당자 변경
notification.type.issue.body.changed = 이슈 본문 변경
notification.type.issue.referred.from.commit = 커밋에서의 이슈 언급
Expand Down
1 change: 1 addition & 0 deletions public/javascripts/common/yobi.Comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ yobi.Comment = (function(){

$('#comment-editform-' + commentId).toggle();
$('#comment-body-' + commentId).toggle();
$("[data-toggle='popover']").popover();
}

/**
Expand Down

0 comments on commit 5f64376

Please sign in to comment.