doortts doortts 2017-01-11
milestone: Fix attachment bug and creation with no contents
See: Yona Github issue #123
@fea9fcc078a7e1f4f4496b9cf0f1a5c54cb60af6
app/controllers/AbstractPostingApp.java
--- app/controllers/AbstractPostingApp.java
+++ app/controllers/AbstractPostingApp.java
@@ -249,7 +249,7 @@
         return AttachmentApp.TEMPORARYFILES_KEEPUP_TIME_MILLIS/(60*1000l);
     }
 
-    private static String[] getTemporaryFileListFromHiddenForm() {
+    public static String[] getTemporaryFileListFromHiddenForm() {
         Http.MultipartFormData body = request().body().asMultipartFormData();
         if (body == null) {
             return new String[] {};
app/controllers/MilestoneApp.java
--- app/controllers/MilestoneApp.java
+++ app/controllers/MilestoneApp.java
@@ -23,6 +23,7 @@
 import controllers.annotation.AnonymousCheck;
 import controllers.annotation.IsAllowed;
 import controllers.annotation.IsCreatable;
+import models.AbstractPosting;
 import models.Attachment;
 import models.Milestone;
 import models.Project;
@@ -103,15 +104,10 @@
         } else {
             Milestone newMilestone = milestoneForm.get();
 
-            if (newMilestone.contents == null) {
-                return status(REQUEST_ENTITY_TOO_LARGE,
-                        ErrorViews.RequestTextEntityTooLarge.render());
-            }
-
             newMilestone.project = project;
             newMilestone.dueDate = JodaDateUtil.lastSecondOfDay(newMilestone.dueDate);
             Milestone.create(newMilestone);
-            Attachment.moveAll(UserApp.currentUser().asResource(), newMilestone.asResource());
+            AbstractPostingApp.attachUploadFilesToPost(newMilestone.asResource());
             return redirect(routes.MilestoneApp.milestone(userName, projectName, newMilestone.id));
         }
     }
app/models/Milestone.java
--- app/models/Milestone.java
+++ app/models/Milestone.java
@@ -60,7 +60,7 @@
     @Formats.DateTime(pattern = "yyyy-MM-dd")
     public Date dueDate;
 
-    @Constraints.Required @Lob
+    @Lob
     public String contents;
 
     @Constraints.Required
app/views/milestone/view.scala.html
--- app/views/milestone/view.scala.html
+++ app/views/milestone/view.scala.html
@@ -20,6 +20,7 @@
 **@
 @(title: String, milestone: models.Milestone, project: Project, issueState:State)
 @import scala.collection.immutable._
+@import org.apache.commons.lang.StringUtils
 @import utils.TemplateHelper._
 @import utils.AccessControl._
 @import models.support.SearchCondition
@@ -59,10 +60,15 @@
             <div class="progress progress-success">
                 <div class="bar" style="width: @milestone.getCompletionRate%;"></div>
             </div>
-            <div class="milestone-desc">
-                <div class="markdown-wrap">@Html(Markdown.render(milestone.contents, milestone.project))</div>
-                <div class="attachments" data-attachments="@toJson(AttachmentApp.getFileList(ResourceType.MILESTONE.toString(), milestone.id.toString()))"></div>
-            </div>
+                @if(StringUtils.isEmpty(milestone.contents)){
+                    <div class="content empty-content"></div>
+                } else {
+                    <div class="milestone-desc">
+                        <div class="markdown-wrap">@Html(Markdown.render(milestone.contents, milestone.project))</div>
+                        <div class="attachments" data-attachments="@toJson(AttachmentApp.getFileList(ResourceType.MILESTONE.toString(), milestone.id.toString()))"></div>
+                    </div>
+                }
+
 
             <div class="actrow right-txt row-fluid" style="padding: 15px 0; clear:both;">
                 <a href="@routes.MilestoneApp.milestones(project.owner, project.name)" class="ybtn pull-left">@Messages("button.list")</a>
Add a comment
List