Skip to content

Commit

Permalink
Merge branch 'main' into feat/multi-roles-for-user
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby authored Nov 22, 2024
2 parents efe49a6 + 201afca commit 3288c3b
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,17 @@ public Result reconcile(Request request) {
String newPattern = tagPermalinkPolicy.pattern();
annotations.put(Constant.PERMALINK_PATTERN_ANNO, newPattern);

String permalink = tagPermalinkPolicy.permalink(tag);
var status = tag.getStatusOrDefault();
String permalink = tagPermalinkPolicy.permalink(tag);
status.setPermalink(permalink);

if (status.getPostCount() == null) {
status.setPostCount(0);
}
if (status.getVisiblePostCount() == null) {
status.setVisiblePostCount(0);
}

// Update the observed version.
status.setObservedVersion(tag.getMetadata().getVersion() + 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,14 @@ record DeviceInfo(String browser, String os) {
Pattern.CASE_INSENSITIVE);

static final Pattern OS_REGEX =
Pattern.compile("(Windows NT|Mac OS X|Android|Linux|iPhone|iPad|Windows Phone)");
Pattern.compile(
"(Windows NT|Mac OS X|Android|Linux|iPhone|iPad|Windows Phone|OpenHarmony)");
static final Pattern[] osRegexes = {
Pattern.compile("Windows NT (\\d+\\.\\d+)"),
Pattern.compile("Mac OS X (\\d+[\\._]\\d+([\\._]\\d+)?)"),
Pattern.compile("iPhone OS (\\d+_\\d+(_\\d+)?)"),
Pattern.compile("Android (\\d+\\.\\d+(\\.\\d+)?)")
Pattern.compile("Android (\\d+\\.\\d+(\\.\\d+)?)"),
Pattern.compile("OpenHarmony (\\d+\\.\\d+(\\.\\d+)?)")
};

public static DeviceInfo parse(String userAgent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties;
import org.springframework.stereotype.Component;
import org.springframework.util.ConcurrentLruCache;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.dialect.IDialect;
import org.thymeleaf.spring6.ISpringWebFluxTemplateEngine;
import org.thymeleaf.spring6.dialect.SpringStandardDialect;
Expand Down Expand Up @@ -72,12 +71,7 @@ public ISpringWebFluxTemplateEngine getTemplateEngine(ThemeContext theme) {

public Mono<Void> clearCache(String themeName) {
return themeResolver.getThemeContext(themeName)
.doOnNext(themeContext -> {
CacheKey cacheKey = buildCacheKey(themeContext);
TemplateEngine templateEngine =
(TemplateEngine) engineCache.get(cacheKey);
templateEngine.clearTemplateCache();
})
.doOnNext(themeContext -> engineCache.remove(buildCacheKey(themeContext)))
.then();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package run.halo.app.theme.finders.vo;

import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;

import lombok.Builder;
import lombok.Value;
import run.halo.app.core.extension.content.Tag;
Expand Down Expand Up @@ -33,7 +35,7 @@ public static TagVo from(Tag tag) {
.metadata(tag.getMetadata())
.spec(spec)
.status(status)
.postCount(tag.getStatusOrDefault().getVisiblePostCount())
.postCount(defaultIfNull(status.getVisiblePostCount(), 0))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

/**
* Tests for {@link DeviceServiceImpl}.
Expand All @@ -12,13 +15,29 @@
*/
class DeviceServiceImplTest {

@Test
void deviceInfoParseTest() {
var info = DeviceServiceImpl.DeviceInfo.parse(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like "
+ "Gecko) Chrome/126.0.0.0 Safari/537.36");
assertThat(info.os()).isEqualTo("Mac OS X 10.15.7");
assertThat(info.browser()).isEqualTo("Chrome 126.0");
static Stream<Arguments> deviceInfoParseTest() {
return Stream.of(
Arguments.of(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like "
+ "Gecko) Chrome/126.0.0.0 Safari/537.36",
"Mac OS X 10.15.7",
"Chrome 126.0"
),
Arguments.of(
"Mozilla/5.0 (Phone; OpenHarmony 5.0) AppleWebKit/537.36 (KHTML, like Gecko) "
+ "Chrome/114.0.0.0 Safari/537.36 ArkWeb/4.1.6.1 Mobile HuaweiBrowser/5.0.4"
+ ".300",
"OpenHarmony 5.0",
"Chrome 114.0"
)
);
}

@ParameterizedTest
@MethodSource
void deviceInfoParseTest(String userAgent, String expectedOs, String expectedBrowser) {
var info = DeviceServiceImpl.DeviceInfo.parse(userAgent);
assertThat(info.os()).isEqualTo(expectedOs);
assertThat(info.browser()).isEqualTo(expectedBrowser);
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'org.springframework.boot' version '3.4.0-RC1' apply false
id 'org.springframework.boot' version '3.4.0' apply false
id 'io.spring.dependency-management' version '1.1.6' apply false
id "com.gorylenko.gradle-git-properties" version "2.4.1" apply false
id "de.undercouch.download" version "5.6.0" apply false
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 4 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down

0 comments on commit 3288c3b

Please sign in to comment.