Skip to content
Permalink
Browse files

Merge pull request #180 from halo-dev/dev

Dev
  • Loading branch information...
ruibaby committed Jun 5, 2019
2 parents 3fe34ea + 5ecce25 commit f62f54d4ced16277bd0c9c4782a2d1558108518c
Showing with 169 additions and 137 deletions.
  1. +5 −1 build.gradle
  2. +1 −1 scripts/docker-build-release.sh
  3. +6 −6 src/main/java/run/halo/app/config/SwaggerConfiguration.java
  4. +4 −0 src/main/java/run/halo/app/model/dto/MenuDTO.java
  5. +1 −1 src/main/java/run/halo/app/model/entity/BasePost.java
  6. +1 −0 src/main/java/run/halo/app/model/entity/PostCategory.java
  7. +1 −0 src/main/java/run/halo/app/model/entity/PostTag.java
  8. +1 −1 src/main/java/run/halo/app/model/entity/Tag.java
  9. +1 −1 src/main/java/run/halo/app/model/entity/ThemeSetting.java
  10. +1 −1 src/main/java/run/halo/app/model/properties/OtherProperties.java
  11. +4 −0 src/main/java/run/halo/app/model/vo/MenuVO.java
  12. +21 −21 src/main/java/run/halo/app/security/filter/ApiAuthenticationFilter.java
  13. +5 −0 src/main/java/run/halo/app/service/impl/BaseCommentServiceImpl.java
  14. +16 −3 src/main/java/run/halo/app/utils/ServiceUtils.java
  15. +1 −1 src/main/resources/admin/css/{app.8abf48c5.css → app.d748d7bc.css}
  16. +1 −0 src/main/resources/admin/css/chunk-009936c1.f3153164.css
  17. +0 −1 src/main/resources/admin/css/chunk-0337f7a6.4c6b622f.css
  18. +1 −1 src/main/resources/admin/css/{chunk-4e835ab8.5f75da19.css → chunk-0aa79c38.26a33a1b.css}
  19. +0 −1 src/main/resources/admin/css/chunk-14e0b302.32f796a8.css
  20. +0 −1 src/main/resources/admin/css/chunk-2a007c18.45475c5a.css
  21. +1 −0 src/main/resources/admin/css/chunk-2ca3170e.61a5a976.css
  22. +0 −1 src/main/resources/admin/css/chunk-31c8ea42.4a090118.css
  23. +0 −1 src/main/resources/admin/css/chunk-35e63e70.6a83ae7d.css
  24. +1 −1 src/main/resources/admin/css/{chunk-5b9151a2.5ac5144c.css → chunk-37d95348.909d3d1b.css}
  25. +1 −0 src/main/resources/admin/css/chunk-436563a2.cb1e7f15.css
  26. +1 −0 src/main/resources/admin/css/chunk-46d7532c.94c6eb30.css
  27. 0 src/main/resources/admin/css/{chunk-4851a43a.09186be6.css → chunk-4851a43a.210847fe.css}
  28. +0 −1 src/main/resources/admin/css/chunk-6d8b31f6.ad8d17b2.css
  29. +1 −1 src/main/resources/admin/css/{chunk-55d28d8a.5710ea86.css → chunk-6e38bcf5.2ee2b33a.css}
  30. +1 −0 src/main/resources/admin/css/chunk-70b33d4d.701a4459.css
  31. +1 −0 src/main/resources/admin/css/chunk-75c7eed4.7cf84e9e.css
  32. 0 src/main/resources/admin/css/{chunk-9449c032.6f053d75.css → chunk-9449c032.dafef2de.css}
  33. +1 −0 src/main/resources/admin/css/chunk-9cb97d52.046bf41d.css
  34. +0 −1 src/main/resources/admin/css/chunk-f1eac230.8481e8b4.css
  35. 0 src/main/resources/admin/css/{chunk-vendors.da56ac75.css → chunk-vendors.278be955.css}
  36. +0 −1 src/main/resources/admin/css/fail.809a6bc5.css
  37. +1 −0 src/main/resources/admin/css/fail.e9c3e2d8.css
  38. +1 −1 src/main/resources/admin/index.html
  39. +1 −0 src/main/resources/admin/js/app.1842d5e6.js
  40. +0 −1 src/main/resources/admin/js/app.e0ba5034.js
  41. +1 −0 src/main/resources/admin/js/chunk-009936c1.cde57fa8.js
  42. +1 −0 src/main/resources/admin/js/chunk-0aa79c38.2659df6e.js
  43. +1 −1 src/main/resources/admin/js/{chunk-4b5e9e93.8033dcf8.js → chunk-0ba750a2.02c8e842.js}
  44. +1 −1 src/main/resources/admin/js/{chunk-142c8832.919c15cb.js → chunk-142c8832.8aceee71.js}
  45. +0 −1 src/main/resources/admin/js/chunk-14e0b302.8cbbed1c.js
  46. +1 −1 src/main/resources/admin/js/{chunk-1be69b35.3b96d59c.js → chunk-1be69b35.4a496da5.js}
  47. +0 −1 src/main/resources/admin/js/chunk-2a007c18.d7c59ddb.js
  48. +1 −0 src/main/resources/admin/js/chunk-2ca3170e.258d6e52.js
  49. +1 −1 src/main/resources/admin/js/{chunk-2d0b64bf.2af37a5a.js → chunk-2d0b64bf.25665dba.js}
  50. +1 −1 src/main/resources/admin/js/{chunk-2d0d65a2.cea2ab69.js → chunk-2d0d65a2.1c8f2476.js}
  51. +1 −1 src/main/resources/admin/js/{chunk-2d21a35c.8a7b3003.js → chunk-2d21a35c.2fc10284.js}
  52. +1 −1 src/main/resources/admin/js/{chunk-2d228d13.f8dd7bb5.js → chunk-2d228d13.dd7018e7.js}
  53. +0 −1 src/main/resources/admin/js/chunk-35e63e70.25724764.js
  54. +1 −0 src/main/resources/admin/js/chunk-37d95348.9ac04f40.js
  55. +1 −1 src/main/resources/admin/js/{chunk-0337f7a6.53ede862.js → chunk-436563a2.89c8f183.js}
  56. +1 −1 src/main/resources/admin/js/{chunk-31c8ea42.fcec41a2.js → chunk-46d7532c.7500e276.js}
  57. +1 −1 src/main/resources/admin/js/{chunk-4851a43a.eadb6121.js → chunk-4851a43a.e3ce92c4.js}
  58. +0 −1 src/main/resources/admin/js/chunk-4e835ab8.734baaf4.js
  59. +0 −1 src/main/resources/admin/js/chunk-5b9151a2.9189da9d.js
  60. +1 −1 src/main/resources/admin/js/{chunk-5bf599cc.c2681092.js → chunk-5bf599cc.fc6c7d8c.js}
  61. +1 −1 src/main/resources/admin/js/{chunk-55d28d8a.e28b3150.js → chunk-6e38bcf5.7b552106.js}
  62. +1 −0 src/main/resources/admin/js/chunk-70b33d4d.f5bbad6f.js
  63. +1 −0 src/main/resources/admin/js/chunk-75c7eed4.cee58ce6.js
  64. +1 −1 src/main/resources/admin/js/{chunk-87e2df70.b954f846.js → chunk-87e2df70.f4b6bdc6.js}
  65. +1 −1 src/main/resources/admin/js/{chunk-9449c032.8f6a0d1a.js → chunk-9449c032.0036f54b.js}
  66. +1 −1 src/main/resources/admin/js/{chunk-6d8b31f6.cb49297f.js → chunk-9cb97d52.abfd8c14.js}
  67. +1 −1 src/main/resources/admin/js/{chunk-bb4f0d4a.c336573f.js → chunk-bb4f0d4a.3b7dfaaa.js}
  68. +0 −1 src/main/resources/admin/js/chunk-f1eac230.05982c8b.js
  69. +64 −0 src/main/resources/admin/js/chunk-vendors.811663b9.js
  70. +0 −64 src/main/resources/admin/js/chunk-vendors.fe7dde0e.js
  71. +1 −1 src/main/resources/admin/js/{fail.13f5cbab.js → fail.8a6d08f5.js}
@@ -8,7 +8,7 @@ apply plugin: 'io.spring.dependency-management'

group = 'run.halo.app'
archivesBaseName = 'halo'
version = '1.0.0'
version = '1.0.1'
sourceCompatibility = '1.8'
description = 'Halo, personal blog system developed in Java.'

@@ -26,6 +26,7 @@ configurations {
}

developmentOnly

runtimeClasspath {
extendsFrom developmentOnly
}
@@ -70,6 +71,9 @@ dependencies {
runtimeOnly 'com.h2database:h2'
runtimeOnly 'mysql:mysql-connector-java'

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

testImplementation 'org.springframework.boot:spring-boot-starter-test'

developmentOnly 'org.springframework.boot:spring-boot-devtools'
@@ -5,6 +5,6 @@ VERSION=$(ls build/libs | sed 's/.*halo-//' | sed 's/.jar$//')
echo "Halo version: $VERSION"

echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker build --build-arg JAR_FILE=build/libs/halo-$VERSION.jar -t $DOCKER_USERNAME/halo -t $DOCKER_USERNAME/$VERSION .
docker build --build-arg JAR_FILE=build/libs/halo-$VERSION.jar -t $DOCKER_USERNAME/halo -t $DOCKER_USERNAME/halo:$VERSION .
docker images
docker push $DOCKER_USERNAME/halo
@@ -69,8 +69,8 @@ public Docket haloDefaultApi() {
return buildApiDocket("run.halo.app.content.api",
"run.halo.app.controller.content.api",
"/api/content/**")
.securitySchemes(portalApiKeys())
.securityContexts(portalSecurityContext())
.securitySchemes(contentApiKeys())
.securityContexts(contentSecurityContext())
.enable(!haloProperties.isDocDisabled());
}

@@ -137,14 +137,14 @@ private Docket buildApiDocket(@NonNull String groupName, @NonNull String basePac
);
}

private List<ApiKey> portalApiKeys() {
private List<ApiKey> contentApiKeys() {
return Arrays.asList(
new ApiKey("Token from header", ApiAuthenticationFilter.API_TOKEN_HEADER_NAME, In.HEADER.name()),
new ApiKey("Token from query", ApiAuthenticationFilter.API_TOKEN_QUERY_NAME, In.QUERY.name())
new ApiKey("Access key from header", ApiAuthenticationFilter.API_ACCESS_KEY_HEADER_NAME, In.HEADER.name()),
new ApiKey("Access key from query", ApiAuthenticationFilter.API_ACCESS_KEY_QUERY_NAME, In.QUERY.name())
);
}

private List<SecurityContext> portalSecurityContext() {
private List<SecurityContext> contentSecurityContext() {
return Collections.singletonList(
SecurityContext.builder()
.securityReferences(defaultAuth())
@@ -1,6 +1,8 @@
package run.halo.app.model.dto;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import run.halo.app.model.dto.base.OutputConverter;
import run.halo.app.model.entity.Menu;

@@ -11,6 +13,8 @@
* @date 4/3/19
*/
@Data
@EqualsAndHashCode
@ToString
public class MenuDTO implements OutputConverter<MenuDTO, Menu> {

private Integer id;
@@ -17,7 +17,7 @@
*/
@Data
@Entity(name = "BasePost")
@Table(name = "posts", indexes = @Index(columnList = "url"))
@Table(name = "posts")
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.INTEGER, columnDefinition = "int default 0")
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@@ -1,6 +1,7 @@
package run.halo.app.model.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import javax.persistence.*;
@@ -1,6 +1,7 @@
package run.halo.app.model.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import javax.persistence.*;
@@ -14,7 +14,7 @@
*/
@Data
@Entity
@Table(name = "tags", indexes = @Index(columnList = "slug_name"))
@Table(name = "tags")
@ToString
@EqualsAndHashCode(callSuper = true)
public class Tag extends BaseEntity {
@@ -14,7 +14,7 @@
*/
@Data
@Entity
@Table(name = "theme_settings", indexes = {@Index(columnList = "setting_key")})
@Table(name = "theme_settings")
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class ThemeSetting extends BaseEntity {
@@ -10,7 +10,7 @@

API_ENABLED("api_enabled", Boolean.class, "false"),

API_TOKEN("api_token", String.class, ""),
API_ACCESS_KEY("api_access_key", String.class, ""),

STATISTICS_CODE("statistics_code", String.class, ""),

@@ -1,6 +1,8 @@
package run.halo.app.model.vo;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import run.halo.app.model.dto.MenuDTO;

import java.util.List;
@@ -10,6 +12,8 @@
* @date : 2019-04-07
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MenuVO extends MenuDTO {

private List<MenuVO> children;
@@ -27,9 +27,9 @@
@Slf4j
public class ApiAuthenticationFilter extends AbstractAuthenticationFilter {

public final static String API_TOKEN_HEADER_NAME = "API-" + HttpHeaders.AUTHORIZATION;
public final static String API_ACCESS_KEY_HEADER_NAME = "API-" + HttpHeaders.AUTHORIZATION;

public final static String API_TOKEN_QUERY_NAME = "api_token";
public final static String API_ACCESS_KEY_QUERY_NAME = "api_access_key";

private final OptionService optionService;

@@ -55,27 +55,27 @@ protected void doAuthenticate(HttpServletRequest request, HttpServletResponse re
return;
}

// Get token
String token = getTokenFromRequest(request);
// Get access key
String accessKey = getTokenFromRequest(request);

if (StringUtils.isBlank(token)) {
// If the token is missing
getFailureHandler().onFailure(request, response, new AuthenticationException("Missing API token"));
if (StringUtils.isBlank(accessKey)) {
// If the access key is missing
getFailureHandler().onFailure(request, response, new AuthenticationException("Missing API access key"));
return;
}

// Get token from option
Optional<String> optionalToken = optionService.getByProperty(OtherProperties.API_TOKEN, String.class);
// Get access key from option
Optional<String> optionalAccessKey = optionService.getByProperty(OtherProperties.API_ACCESS_KEY, String.class);

if (!optionalToken.isPresent()) {
// If the token is not set
getFailureHandler().onFailure(request, response, new AuthenticationException("API Token hasn't been set by blogger"));
if (!optionalAccessKey.isPresent()) {
// If the access key is not set
getFailureHandler().onFailure(request, response, new AuthenticationException("API access key hasn't been set by blogger"));
return;
}

if (!StringUtils.equals(token, optionalToken.get())) {
// If the token is mismatch
getFailureHandler().onFailure(request, response, new AuthenticationException("Token is mismatch"));
if (!StringUtils.equals(accessKey, optionalAccessKey.get())) {
// If the access key is mismatch
getFailureHandler().onFailure(request, response, new AuthenticationException("API access key is mismatch"));
return;
}

@@ -103,17 +103,17 @@ protected String getTokenFromRequest(@NonNull HttpServletRequest request) {
Assert.notNull(request, "Http servlet request must not be null");

// Get from header
String token = request.getHeader(API_TOKEN_HEADER_NAME);
String accessKey = request.getHeader(API_ACCESS_KEY_HEADER_NAME);

// Get from param
if (StringUtils.isBlank(token)) {
token = request.getParameter(API_TOKEN_QUERY_NAME);
if (StringUtils.isBlank(accessKey)) {
accessKey = request.getParameter(API_ACCESS_KEY_QUERY_NAME);

log.debug("Got token from parameter: [{}: {}]", API_TOKEN_QUERY_NAME, token);
log.debug("Got access key from parameter: [{}: {}]", API_ACCESS_KEY_QUERY_NAME, accessKey);
} else {
log.debug("Got token from header: [{}: {}]", API_TOKEN_HEADER_NAME, token);
log.debug("Got access key from header: [{}: {}]", API_ACCESS_KEY_HEADER_NAME, accessKey);
}

return token;
return accessKey;
}
}
@@ -429,6 +429,11 @@ public BaseCommentDTO convertTo(COMMENT comment) {
// Get all comments
Page<COMMENT> topCommentPage = baseCommentRepository.findAllByPostIdAndStatusAndParentId(targetId, status, 0L, pageable);

if (topCommentPage.isEmpty()) {
// If the comments is empty
return ServiceUtils.buildEmptyPageImpl(topCommentPage);
}

// Get top comment ids
Set<Long> topCommentIds = ServiceUtils.fetchProperty(topCommentPage.getContent(), BaseComment::getId);

@@ -1,8 +1,6 @@
package run.halo.app.utils;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.*;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -136,6 +134,21 @@ public static Pageable buildLatestPageable(int top) {
return buildLatestPageable(top, "createTime");
}

/**
* Build empty page result.
*
* @param page page info must not be null
* @param <T> target page result type
* @param <S> source page result type
* @return empty page result
*/
@NonNull
public static <T, S> Page<T> buildEmptyPageImpl(@NonNull Page<S> page) {
Assert.notNull(page, "Page result must not be null");

return new PageImpl<>(Collections.emptyList(), page.getPageable(), page.getTotalElements());
}

/**
* Builds latest page request.
*

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more.

This file was deleted.

Some generated files are not rendered by default. Learn more.

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more.

This file was deleted.

This file was deleted.

0 comments on commit f62f54d

Please sign in to comment.
You can’t perform that action at this time.