Skip to content

Commit

Permalink
Merge pull request #180 from halo-dev/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ruibaby authored Jun 5, 2019
2 parents 3fe34ea + 5ecce25 commit f62f54d
Show file tree
Hide file tree
Showing 71 changed files with 169 additions and 137 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.'

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

developmentOnly

runtimeClasspath {
extendsFrom developmentOnly
}
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion scripts/docker-build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions src/main/java/run/halo/app/config/SwaggerConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -137,14 +137,14 @@ private List<SecurityContext> adminSecurityContext() {
);
}

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())
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/run/halo/app/model/dto/MenuDTO.java
Original file line number Diff line number Diff line change
@@ -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;

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

private Integer id;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/run/halo/app/model/entity/BasePost.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/run/halo/app/model/entity/PostCategory.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package run.halo.app.model.entity;

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

import javax.persistence.*;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/run/halo/app/model/entity/PostTag.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package run.halo.app.model.entity;

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

import javax.persistence.*;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/run/halo/app/model/entity/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/run/halo/app/model/entity/ThemeSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public enum OtherProperties implements PropertyEnum {

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, ""),

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/run/halo/app/model/vo/MenuVO.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,6 +12,8 @@
* @date : 2019-04-07
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MenuVO extends MenuDTO {

private List<MenuVO> children;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ public Page<CommentWithHasChildrenVO> pageTopCommentsBy(Integer targetId, Commen
// 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);

Expand Down
19 changes: 16 additions & 3 deletions src/main/java/run/halo/app/utils/ServiceUtils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/main/resources/admin/css/chunk-009936c1.f3153164.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/main/resources/admin/css/chunk-0337f7a6.4c6b622f.css

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/main/resources/admin/css/chunk-14e0b302.32f796a8.css

This file was deleted.

1 change: 0 additions & 1 deletion src/main/resources/admin/css/chunk-2a007c18.45475c5a.css

This file was deleted.

1 change: 1 addition & 0 deletions src/main/resources/admin/css/chunk-2ca3170e.61a5a976.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/main/resources/admin/css/chunk-31c8ea42.4a090118.css

This file was deleted.

1 change: 0 additions & 1 deletion src/main/resources/admin/css/chunk-35e63e70.6a83ae7d.css

This file was deleted.

Loading

0 comments on commit f62f54d

Please sign in to comment.