aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Svantesson <davidsvantesson@gmail.com>2019-10-28 00:36:28 +0100
committerLauris BH <lauris@nix.lv>2019-10-28 01:36:28 +0200
commitb2c3a7d79f87fb443ff2b479ce9c280f99262dbe (patch)
tree0747c85174cab680e3d963ab22039ab07cbf1a2e
parent76bbcf13870a46b15d7fb04a311e8584d76c3a15 (diff)
downloadgitea-b2c3a7d79f87fb443ff2b479ce9c280f99262dbe.tar.gz
gitea-b2c3a7d79f87fb443ff2b479ce9c280f99262dbe.zip
Fix deadline on update issue or PR via API (#8699)
-rw-r--r--routers/api/v1/repo/issue.go13
-rw-r--r--routers/api/v1/repo/pull.go13
2 files changed, 12 insertions, 14 deletions
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go
index daaa3d5985..af320a39eb 100644
--- a/routers/api/v1/repo/issue.go
+++ b/routers/api/v1/repo/issue.go
@@ -310,14 +310,13 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
}
// Update the deadline
- var deadlineUnix util.TimeStamp
if form.Deadline != nil && !form.Deadline.IsZero() && ctx.Repo.CanWrite(models.UnitTypeIssues) {
- deadlineUnix = util.TimeStamp(form.Deadline.Unix())
- }
-
- if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil {
- ctx.Error(500, "UpdateIssueDeadline", err)
- return
+ deadlineUnix := util.TimeStamp(form.Deadline.Unix())
+ if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil {
+ ctx.Error(500, "UpdateIssueDeadline", err)
+ return
+ }
+ issue.DeadlineUnix = deadlineUnix
}
// Add/delete assignees
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index d99c9a00c9..4ad3479fd0 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -375,14 +375,13 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
}
// Update Deadline
- var deadlineUnix util.TimeStamp
if form.Deadline != nil && !form.Deadline.IsZero() {
- deadlineUnix = util.TimeStamp(form.Deadline.Unix())
- }
-
- if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil {
- ctx.Error(500, "UpdateIssueDeadline", err)
- return
+ deadlineUnix := util.TimeStamp(form.Deadline.Unix())
+ if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil {
+ ctx.Error(500, "UpdateIssueDeadline", err)
+ return
+ }
+ issue.DeadlineUnix = deadlineUnix
}
// Add/delete assignees
> 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.
 */

/* $Id$ */
package org.apache.fop.pdf;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.junit.Assert;
import org.junit.Test;

import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFParser;
import org.apache.fop.render.intermediate.IFSerializer;
import org.apache.fop.render.intermediate.IFUtil;

public class PDFPageXMPTestCase {
    private static final String XMP = "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\">\n"
            + "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n"
            + "<rdf:Description xmlns:abc=\"http://www.abc.de/abc/\" abc:def=\"val\" rdf:about=\"\"/>\n"
            + "<rdf:Description xmlns:pdfaExtension=\"http://www.aiim.org/pdfa/ns/extension/\" "
            + "xmlns:pdfaProperty=\"http://www.aiim.org/pdfa/ns/property#\" "
            + "xmlns:pdfaSchema=\"http://www.aiim.org/pdfa/ns/schema#\" rdf:about=\"\">\n"
            + "<pdfaExtension:schemas>\n"
            + "<rdf:Bag>\n"
            + "<rdf:li rdf:parseType=\"Resource\">\n"
            + "<pdfaSchema:property>\n"
            + "<rdf:Seq>\n"
            + "<rdf:li rdf:parseType=\"Resource\">\n"
            + "<pdfaProperty:name>split</pdfaProperty:name>\n"
            + "</rdf:li>\n"
            + "</rdf:Seq>\n"
            + "</pdfaSchema:property>\n"
            + "</rdf:li>\n"
            + "</rdf:Bag>\n"
            + "</pdfaExtension:schemas>\n"
            + "</rdf:Description>\n"
            + "</rdf:RDF>\n"
            + "</x:xmpmeta>";

    @Test
    public void textFO() throws Exception {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        foToOutput(out, MimeConstants.MIME_PDF);
        String pdf = trimLines(out.toString());
        Assert.assertTrue(pdf, pdf.contains(XMP));
    }

    @Test
    public void textIF() throws Exception {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        foToOutput(out, MimeConstants.MIME_FOP_IF);
        out = iFToPDF(new ByteArrayInputStream(out.toByteArray()));
        String pdf = trimLines(out.toString());
        Assert.assertTrue(pdf, pdf.contains(XMP));
    }

    private String trimLines(String pdf) {
        pdf = pdf.replace("\r", "");
        StringBuilder sb = new StringBuilder();
        for (String line : pdf.split("\n")) {
            sb.append(line.trim()).append("\n");
        }
        return sb.toString();
    }

    private ByteArrayOutputStream iFToPDF(InputStream is) throws Exception {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        FOUserAgent userAgent = getFopFactory().newFOUserAgent();
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        Source src = new StreamSource(is);
        IFDocumentHandler documentHandler
                = userAgent.getRendererFactory().createDocumentHandler(userAgent, MimeConstants.MIME_PDF);
        documentHandler.setResult(new StreamResult(out));
        IFUtil.setupFonts(documentHandler);
        IFParser parser = new IFParser();
        Result res = new SAXResult(parser.getContentHandler(documentHandler, userAgent));
        transformer.transform(src, res);
        return out;
    }

    private void foToOutput(ByteArrayOutputStream out, String mimeFopIf) throws Exception {
        FopFactory fopFactory = getFopFactory();
        FOUserAgent userAgent = fopFactory.newFOUserAgent();
        if (mimeFopIf.equals(MimeConstants.MIME_FOP_IF)) {
            IFSerializer serializer = new IFSerializer(new IFContext(userAgent));
            IFDocumentHandler targetHandler
                    = userAgent.getRendererFactory().createDocumentHandler(userAgent, MimeConstants.MIME_PDF);
            serializer.mimicDocumentHandler(targetHandler);
            userAgent.setDocumentHandlerOverride(serializer);
        }
        Fop fop = fopFactory.newFop(mimeFopIf, userAgent, out);
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        Source src = new StreamSource(PDFPageXMPTestCase.class.getResource("PDFPageXMP.fo").openStream());
        Result res = new SAXResult(fop.getDefaultHandler());
        transformer.transform(src, res);
    }

    private FopFactory getFopFactory() {
        return FopFactory.newInstance(new File(".").toURI());
    }
}