Skip to content

Commit

Permalink
Merge branch '1.8.0-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Dec 24, 2016
2 parents 8b04f67 + 9e54d9c commit b2b0959
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://zephyr.b3log.org">Zephyr</a>
* @version 1.24.23.35, Dec 22, 2016
* @version 1.24.24.35, Dec 24, 2016
* @since 0.2.0
*/
@RequestProcessor
Expand Down Expand Up @@ -910,7 +910,7 @@ public void showUpdateArticle(final HTTPRequestContext context, final HttpServle
return;
}

final JSONObject currentUser = Sessions.currentUser(request);
final JSONObject currentUser = (JSONObject) request.getAttribute(User.USER);
if (null == currentUser
|| !currentUser.optString(Keys.OBJECT_ID).equals(article.optString(Article.ARTICLE_AUTHOR_ID))) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
Expand Down
32 changes: 17 additions & 15 deletions src/main/java/org/b3log/symphony/service/ArticleMgmtService.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://zephyr.b3log.org">Zephyr</a>
* @version 2.14.27.31, Dec 17, 2016
* @version 2.14.27.32, Dec 24, 2016
* @since 0.2.0
*/
@Service
Expand Down Expand Up @@ -347,8 +347,12 @@ public synchronized String addArticle(final JSONObject requestJSONObject) throws
final boolean syncWithSymphonyClient = requestJSONObject.optBoolean(Article.ARTICLE_SYNC_TO_CLIENT);

String articleTitle = requestJSONObject.optString(Article.ARTICLE_TITLE);
articleTitle = Emotions.toAliases(articleTitle);
articleTitle = Pangu.spacingText(articleTitle);
articleTitle = StringUtils.trim(articleTitle);

final int articleType = requestJSONObject.optInt(Article.ARTICLE_TYPE, Article.ARTICLE_TYPE_C_NORMAL);

try {
// check if admin allow to add article
final JSONObject option = optionRepository.get(Option.ID_C_MISC_ALLOW_ADD_ARTICLE);
Expand Down Expand Up @@ -389,17 +393,19 @@ public synchronized String addArticle(final JSONObject requestJSONObject) throws
}
}

final JSONObject maybeExist = articleRepository.getByTitle(articleTitle);
if (null != maybeExist) {
final String existArticleAuthorId = maybeExist.optString(Article.ARTICLE_AUTHOR_ID);
final JSONObject existArticleAuthor = userRepository.get(existArticleAuthorId);
final String userName = existArticleAuthor.optString(User.USER_NAME);
String msg = langPropsService.get("duplicatedArticleTitleLabel");
msg = msg.replace("{user}", "<a target='_blank' href='/member/" + userName + "'>" + userName + "</a>");
msg = msg.replace("{article}", "<a target='_blank' href='/article/" + maybeExist.optString(Keys.OBJECT_ID)
+ "'>" + articleTitle + "</a>");
if (Article.ARTICLE_TYPE_C_DISCUSSION != articleType) {
final JSONObject maybeExist = articleRepository.getByTitle(articleTitle);
if (null != maybeExist) {
final String existArticleAuthorId = maybeExist.optString(Article.ARTICLE_AUTHOR_ID);
final JSONObject existArticleAuthor = userRepository.get(existArticleAuthorId);
final String userName = existArticleAuthor.optString(User.USER_NAME);
String msg = langPropsService.get("duplicatedArticleTitleLabel");
msg = msg.replace("{user}", "<a target='_blank' href='/member/" + userName + "'>" + userName + "</a>");
msg = msg.replace("{article}", "<a target='_blank' href='/article/" + maybeExist.optString(Keys.OBJECT_ID)
+ "'>" + articleTitle + "</a>");

throw new ServiceException(msg);
throw new ServiceException(msg);
}
}
} catch (final RepositoryException e) {
throw new ServiceException(e);
Expand All @@ -416,9 +422,6 @@ public synchronized String addArticle(final JSONObject requestJSONObject) throws
final String clientArticlePermalink = requestJSONObject.optString(Article.ARTICLE_CLIENT_ARTICLE_PERMALINK);
final boolean isBroadcast = requestJSONObject.optBoolean(Article.ARTICLE_T_IS_BROADCAST);

articleTitle = Emotions.toAliases(articleTitle);
articleTitle = Pangu.spacingText(articleTitle);

article.put(Article.ARTICLE_TITLE, articleTitle);
article.put(Article.ARTICLE_TAGS, requestJSONObject.optString(Article.ARTICLE_TAGS));

Expand Down Expand Up @@ -455,7 +458,6 @@ public synchronized String addArticle(final JSONObject requestJSONObject) throws
article.put(Article.ARTICLE_RANDOM_DOUBLE, Math.random());
article.put(Article.REDDIT_SCORE, 0);
article.put(Article.ARTICLE_STATUS, Article.ARTICLE_STATUS_C_VALID);
final int articleType = requestJSONObject.optInt(Article.ARTICLE_TYPE, Article.ARTICLE_TYPE_C_NORMAL);
article.put(Article.ARTICLE_TYPE, articleType);
article.put(Article.ARTICLE_REWARD_POINT, rewardPoint);
String city = "";
Expand Down
7 changes: 6 additions & 1 deletion src/main/webapp/js/add-article.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://zephyr.b3log.org">Zephyr</a>
* @version 2.19.15.13, Dec 21, 2016
* @version 2.19.15.14, Dec 24, 2016
*/

/**
Expand Down Expand Up @@ -310,6 +310,11 @@ var AddArticle = {
if ($.trim($(this).val()) === '') {
return false;
}

if (1 === Label.articleType) { // 小黑屋不检查标题重复
return;
}

$.ajax({
url: Label.servePath + "/article/check-title",
type: "POST",
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/js/add-article.min.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/main/webapp/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author Zephyr
* @version 1.41.27.39, Dec 24, 2016
* @version 1.41.28.39, Dec 24, 2016
*/

/**
Expand Down Expand Up @@ -503,6 +503,9 @@ var Util = {
},
focus: function () {
this.$it.focus();
},
setCursor: function () {
this.$it[0].setSelectionRange(0, 0)
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/js/common.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/main/webapp/skins/classic/home/post.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
Label.commonAtUser = '${permissions["commonAtUser"].permissionGrant?c}';
Label.requisite = ${requisite?c};
<#if article??>Label.articleOId = '${article.oId}' ;</#if>
Label.articleType = ${articleType};
</script>
<script type="text/javascript" src="${staticServePath}/js/add-article${miniPostfix}.js?${staticResourceVersion}"></script>
<script>
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/skins/classic/index.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
</a>
</#if>
</span>
<span class="post"><a href="${servePath}/post?type=0">${postArticleLabel}</a></span>
<span class="post"><a href="${servePath}/pre-post">${postArticleLabel}</a></span>
</div>
<div class="perfect-panel list">
<ul>
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/skins/mobile/home/post.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
Label.qiniuUploadToken = '${qiniuUploadToken}';
Label.commonAtUser = '${permissions["commonAtUser"].permissionGrant?c}';
<#if article??>Label.articleOId = '${article.oId}' ;</#if>
Label.articleType = ${articleType};
</script>
<script type="text/javascript" src="${staticServePath}/js/add-article${miniPostfix}.js?${staticResourceVersion}"></script>
<script>
Expand Down

0 comments on commit b2b0959

Please sign in to comment.