From 5f643760bdf65d0145aa5ec6d7b14585e66bf39b Mon Sep 17 00:00:00 2001 From: Suwon Chae Date: Sat, 18 Apr 2015 17:02:14 +0900 Subject: [PATCH] notification: Add noti mail send option User can choose to send modification mail or not --- app/assets/stylesheets/less/_page.less | 13 +++++++++++++ app/controllers/AbstractPostingApp.java | 16 ++++++++++++++++ app/controllers/BoardApp.java | 7 ++++++- app/controllers/CommentApp.java | 4 ++++ app/controllers/IssueApp.java | 12 ++++++++---- app/models/AbstractPosting.java | 6 ++++++ app/models/Comment.java | 6 ++++++ app/views/board/edit.scala.html | 8 ++++++++ app/views/board/partial_comments.scala.html | 2 +- app/views/common/commentUpdateForm.scala.html | 16 ++++++++++++---- app/views/issue/edit.scala.html | 8 ++++++++ app/views/issue/partial_comments.scala.html | 2 +- conf/messages | 2 ++ conf/messages.ko-KR | 2 ++ public/javascripts/common/yobi.Comment.js | 1 + 15 files changed, 94 insertions(+), 11 deletions(-) diff --git a/app/assets/stylesheets/less/_page.less b/app/assets/stylesheets/less/_page.less index 223897af5..9a4e6e5c4 100644 --- a/app/assets/stylesheets/less/_page.less +++ b/app/assets/stylesheets/less/_page.less @@ -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; + } +} + diff --git a/app/controllers/AbstractPostingApp.java b/app/controllers/AbstractPostingApp.java index 4b2b58891..98ff95666 100644 --- a/app/controllers/AbstractPostingApp.java +++ b/app/controllers/AbstractPostingApp.java @@ -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; @@ -156,4 +158,18 @@ private static boolean isTemporaryFilesExist(String[] files) { } return StringUtils.isNotBlank(files[0]); } + + protected static boolean isSelectedToSendNotificationMail() { + Map 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; + } } diff --git a/app/controllers/BoardApp.java b/app/controllers/BoardApp.java index d45b752b9..ecc7673c1 100644 --- a/app/controllers/BoardApp.java +++ b/app/controllers/BoardApp.java @@ -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); + } } }; @@ -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); diff --git a/app/controllers/CommentApp.java b/app/controllers/CommentApp.java index f667b3772..40d56bd07 100644 --- a/app/controllers/CommentApp.java +++ b/app/controllers/CommentApp.java @@ -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; @@ -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); + } } diff --git a/app/controllers/IssueApp.java b/app/controllers/IssueApp.java index ea57f614a..afb9da032 100644 --- a/app/controllers/IssueApp.java +++ b/app/controllers/IssueApp.java @@ -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); + } } }; @@ -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); diff --git a/app/models/AbstractPosting.java b/app/models/AbstractPosting.java index 837dc49c2..2729facf5 100644 --- a/app/models/AbstractPosting.java +++ b/app/models/AbstractPosting.java @@ -23,6 +23,7 @@ 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; @@ -30,6 +31,7 @@ import play.db.ebean.Transactional; import utils.JodaDateUtil; +import javax.annotation.Nonnull; import javax.persistence.*; import javax.validation.constraints.Size; import java.util.Date; @@ -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); + } } diff --git a/app/models/Comment.java b/app/models/Comment.java index 499813a53..4e145bc38 100644 --- a/app/models/Comment.java +++ b/app/models/Comment.java @@ -23,6 +23,7 @@ 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; @@ -30,6 +31,7 @@ import play.db.ebean.Model; import utils.JodaDateUtil; +import javax.annotation.Nonnull; import javax.persistence.Id; import javax.persistence.Lob; import javax.persistence.MappedSuperclass; @@ -153,4 +155,8 @@ public int hashCode() { .append(authorName) .toHashCode(); } + + public boolean isAuthoredBy(@Nonnull User user){ + return StringUtils.equalsIgnoreCase(this.authorLoginId, user.loginId); + } } diff --git a/app/views/board/edit.scala.html b/app/views/board/edit.scala.html index 7ffac8fff..efe867def 100644 --- a/app/views/board/edit.scala.html +++ b/app/views/board/edit.scala.html @@ -78,6 +78,14 @@
+ @if(posting.getAuthor.equals(UserApp.currentUser()) && !posting.readme){ + + + + } @Messages("button.cancel")
diff --git a/app/views/board/partial_comments.scala.html b/app/views/board/partial_comments.scala.html index 7880844bc..5926be91b 100644 --- a/app/views/board/partial_comments.scala.html +++ b/app/views/board/partial_comments.scala.html @@ -63,7 +63,7 @@ - @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)
@Html(Markdown.render(comment.contents, project))
diff --git a/app/views/common/commentUpdateForm.scala.html b/app/views/common/commentUpdateForm.scala.html index 436f43b82..5dc2f3458 100644 --- a/app/views/common/commentUpdateForm.scala.html +++ b/app/views/common/commentUpdateForm.scala.html @@ -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) -
+
- +
@common.editor("contents", contents,"", "update-comment-body")
- + @if(comment.isAuthoredBy(UserApp.currentUser())){ + + + + } +
diff --git a/app/views/issue/edit.scala.html b/app/views/issue/edit.scala.html index 942f880e1..135bc8b26 100644 --- a/app/views/issue/edit.scala.html +++ b/app/views/issue/edit.scala.html @@ -71,6 +71,14 @@ @** end of fileUploader **@
+ @if(issue.isAuthoredBy(UserApp.currentUser())){ + + + + } @Messages("button.cancel")
diff --git a/app/views/issue/partial_comments.scala.html b/app/views/issue/partial_comments.scala.html index 979b7e268..1836b8253 100644 --- a/app/views/issue/partial_comments.scala.html +++ b/app/views/issue/partial_comments.scala.html @@ -144,7 +144,7 @@
- @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)
@Html(Markdown.render(comment.contents, project))
diff --git a/conf/messages b/conf/messages index ed611b2c3..ff4a700f0 100644 --- a/conf/messages +++ b/conf/messages @@ -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 diff --git a/conf/messages.ko-KR b/conf/messages.ko-KR index e75c80ce8..7522739f1 100644 --- a/conf/messages.ko-KR +++ b/conf/messages.ko-KR @@ -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 = 커밋에서의 이슈 언급 diff --git a/public/javascripts/common/yobi.Comment.js b/public/javascripts/common/yobi.Comment.js index 2d6dde4ff..44ae630db 100644 --- a/public/javascripts/common/yobi.Comment.js +++ b/public/javascripts/common/yobi.Comment.js @@ -53,6 +53,7 @@ yobi.Comment = (function(){ $('#comment-editform-' + commentId).toggle(); $('#comment-body-' + commentId).toggle(); + $("[data-toggle='popover']").popover(); } /**