Commit e64ec009 authored by Liang Ding's avatar Liang Ding

🎨 调整草稿访问判断

parent 6afd79f5
...@@ -60,7 +60,7 @@ import java.util.*; ...@@ -60,7 +60,7 @@ import java.util.*;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://zephyr.b3log.org">Zephyr</a> * @author <a href="http://zephyr.b3log.org">Zephyr</a>
* @version 1.4.5.6, Apr 18, 2019 * @version 1.4.5.7, May 18, 2019
* @since 0.3.1 * @since 0.3.1
*/ */
@RequestProcessor @RequestProcessor
...@@ -713,14 +713,6 @@ public class ArticleProcessor { ...@@ -713,14 +713,6 @@ public class ArticleProcessor {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "article.ftl"); final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "article.ftl");
try { try {
final JSONObject preference = optionQueryService.getPreference();
final boolean allowVisitDraftViaPermalink = preference.getBoolean(Option.ID_C_ALLOW_VISIT_DRAFT_VIA_PERMALINK);
if (Article.ARTICLE_STATUS_C_PUBLISHED != article.optInt(Article.ARTICLE_STATUS) && !allowVisitDraftViaPermalink) {
context.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
LOGGER.log(Level.TRACE, "Article [title={0}]", article.getString(Article.ARTICLE_TITLE)); LOGGER.log(Level.TRACE, "Article [title={0}]", article.getString(Article.ARTICLE_TITLE));
articleQueryService.markdown(article); articleQueryService.markdown(article);
...@@ -729,6 +721,7 @@ public class ArticleProcessor { ...@@ -729,6 +721,7 @@ public class ArticleProcessor {
// For <meta name="description" content="${article.articleAbstract}"/> // For <meta name="description" content="${article.articleAbstract}"/>
final String metaDescription = Jsoup.parse(article.optString(Article.ARTICLE_ABSTRACT)).text(); final String metaDescription = Jsoup.parse(article.optString(Article.ARTICLE_ABSTRACT)).text();
article.put(Article.ARTICLE_ABSTRACT, metaDescription); article.put(Article.ARTICLE_ABSTRACT, metaDescription);
final JSONObject preference = optionQueryService.getPreference();
if (preference.getBoolean(Option.ID_C_ENABLE_ARTICLE_UPDATE_HINT)) { if (preference.getBoolean(Option.ID_C_ENABLE_ARTICLE_UPDATE_HINT)) {
article.put(Common.HAS_UPDATED, articleQueryService.hasUpdated(article)); article.put(Common.HAS_UPDATED, articleQueryService.hasUpdated(article));
} else { } else {
......
...@@ -29,8 +29,10 @@ import org.b3log.latke.servlet.HttpMethod; ...@@ -29,8 +29,10 @@ import org.b3log.latke.servlet.HttpMethod;
import org.b3log.latke.servlet.RequestContext; import org.b3log.latke.servlet.RequestContext;
import org.b3log.latke.servlet.handler.Handler; import org.b3log.latke.servlet.handler.Handler;
import org.b3log.solo.model.Article; import org.b3log.solo.model.Article;
import org.b3log.solo.model.Option;
import org.b3log.solo.repository.ArticleRepository; import org.b3log.solo.repository.ArticleRepository;
import org.b3log.solo.service.InitService; import org.b3log.solo.service.InitService;
import org.b3log.solo.service.OptionQueryService;
import org.b3log.solo.service.PermalinkQueryService; import org.b3log.solo.service.PermalinkQueryService;
import org.b3log.solo.util.Solos; import org.b3log.solo.util.Solos;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -41,7 +43,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -41,7 +43,7 @@ import javax.servlet.http.HttpServletResponse;
* Article permalink handler. * Article permalink handler.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.1, Apr 18, 2019 * @version 1.0.0.2, May 18, 2019
* @since 3.2.0 * @since 3.2.0
*/ */
public class PermalinkHandler implements Handler { public class PermalinkHandler implements Handler {
...@@ -58,9 +60,10 @@ public class PermalinkHandler implements Handler { ...@@ -58,9 +60,10 @@ public class PermalinkHandler implements Handler {
@Override @Override
public void handle(final RequestContext context) { public void handle(final RequestContext context) {
final BeanManager beanManager = BeanManager.getInstance();
JSONObject article; JSONObject article;
try { try {
final BeanManager beanManager = BeanManager.getInstance();
final InitService initService = beanManager.getReference(InitService.class); final InitService initService = beanManager.getReference(InitService.class);
if (!initService.isInited()) { if (!initService.isInited()) {
context.handle(); context.handle();
...@@ -106,6 +109,15 @@ public class PermalinkHandler implements Handler { ...@@ -106,6 +109,15 @@ public class PermalinkHandler implements Handler {
} }
} }
final OptionQueryService optionQueryService = beanManager.getReference(OptionQueryService.class);
final JSONObject preference = optionQueryService.getPreference();
final boolean allowVisitDraftViaPermalink = preference.getBoolean(Option.ID_C_ALLOW_VISIT_DRAFT_VIA_PERMALINK);
if (Article.ARTICLE_STATUS_C_PUBLISHED != article.optInt(Article.ARTICLE_STATUS) && !allowVisitDraftViaPermalink) {
context.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
dispatchToArticleProcessor(context, article); dispatchToArticleProcessor(context, article);
context.handle(); context.handle();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment