mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-05-21 09:57:28 +08:00
Log post visibility changes
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.openisle.dto;
|
package com.openisle.dto;
|
||||||
|
|
||||||
import com.openisle.model.PostChangeType;
|
import com.openisle.model.PostChangeType;
|
||||||
|
import com.openisle.model.PostVisibleScopeType;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -29,5 +30,7 @@ public class PostChangeLogDto {
|
|||||||
private LocalDateTime newPinnedAt;
|
private LocalDateTime newPinnedAt;
|
||||||
private Boolean oldFeatured;
|
private Boolean oldFeatured;
|
||||||
private Boolean newFeatured;
|
private Boolean newFeatured;
|
||||||
|
private PostVisibleScopeType oldVisibleScope;
|
||||||
|
private PostVisibleScopeType newVisibleScope;
|
||||||
private Integer amount;
|
private Integer amount;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ public class PostChangeLogMapper {
|
|||||||
} else if (log instanceof PostFeaturedChangeLog f) {
|
} else if (log instanceof PostFeaturedChangeLog f) {
|
||||||
dto.setOldFeatured(f.isOldFeatured());
|
dto.setOldFeatured(f.isOldFeatured());
|
||||||
dto.setNewFeatured(f.isNewFeatured());
|
dto.setNewFeatured(f.isNewFeatured());
|
||||||
|
} else if (log instanceof PostVisibleScopeChangeLog v) {
|
||||||
|
dto.setOldVisibleScope(v.getOldVisibleScope());
|
||||||
|
dto.setNewVisibleScope(v.getNewVisibleScope());
|
||||||
} else if (log instanceof PostDonateChangeLog d) {
|
} else if (log instanceof PostDonateChangeLog d) {
|
||||||
dto.setAmount(d.getAmount());
|
dto.setAmount(d.getAmount());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public enum PostChangeType {
|
|||||||
CLOSED,
|
CLOSED,
|
||||||
PINNED,
|
PINNED,
|
||||||
FEATURED,
|
FEATURED,
|
||||||
|
VISIBLE_SCOPE,
|
||||||
VOTE_RESULT,
|
VOTE_RESULT,
|
||||||
LOTTERY_RESULT,
|
LOTTERY_RESULT,
|
||||||
DONATE,
|
DONATE,
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.openisle.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.EnumType;
|
||||||
|
import jakarta.persistence.Enumerated;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "post_visible_scope_change_logs")
|
||||||
|
public class PostVisibleScopeChangeLog extends PostChangeLog {
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private PostVisibleScopeType oldVisibleScope;
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private PostVisibleScopeType newVisibleScope;
|
||||||
|
}
|
||||||
@@ -99,6 +99,21 @@ public class PostChangeLogService {
|
|||||||
logRepository.save(log);
|
logRepository.save(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void recordVisibleScopeChange(
|
||||||
|
Post post,
|
||||||
|
User user,
|
||||||
|
PostVisibleScopeType oldVisibleScope,
|
||||||
|
PostVisibleScopeType newVisibleScope
|
||||||
|
) {
|
||||||
|
PostVisibleScopeChangeLog log = new PostVisibleScopeChangeLog();
|
||||||
|
log.setPost(post);
|
||||||
|
log.setUser(user);
|
||||||
|
log.setType(PostChangeType.VISIBLE_SCOPE);
|
||||||
|
log.setOldVisibleScope(oldVisibleScope);
|
||||||
|
log.setNewVisibleScope(newVisibleScope);
|
||||||
|
logRepository.save(log);
|
||||||
|
}
|
||||||
|
|
||||||
public void recordVoteResult(Post post) {
|
public void recordVoteResult(Post post) {
|
||||||
PostVoteResultChangeLog log = new PostVoteResultChangeLog();
|
PostVoteResultChangeLog log = new PostVoteResultChangeLog();
|
||||||
log.setPost(post);
|
log.setPost(post);
|
||||||
|
|||||||
@@ -340,10 +340,10 @@ public class PostService {
|
|||||||
post.setStatus(publishMode == PublishMode.REVIEW ? PostStatus.PENDING : PostStatus.PUBLISHED);
|
post.setStatus(publishMode == PublishMode.REVIEW ? PostStatus.PENDING : PostStatus.PUBLISHED);
|
||||||
|
|
||||||
// 什么都没设置的情况下,默认为ALL
|
// 什么都没设置的情况下,默认为ALL
|
||||||
if(Objects.isNull(postVisibleScopeType)){
|
if (Objects.isNull(postVisibleScopeType)) {
|
||||||
post.setVisibleScope(PostVisibleScopeType.ALL);
|
post.setVisibleScope(PostVisibleScopeType.ALL);
|
||||||
}else{
|
} else {
|
||||||
post.setVisibleScope(postVisibleScopeType);
|
post.setVisibleScope(postVisibleScopeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (post instanceof LotteryPost) {
|
if (post instanceof LotteryPost) {
|
||||||
@@ -1190,6 +1190,7 @@ public class PostService {
|
|||||||
post.setContent(content);
|
post.setContent(content);
|
||||||
post.setCategory(category);
|
post.setCategory(category);
|
||||||
post.setTags(new java.util.HashSet<>(tags));
|
post.setTags(new java.util.HashSet<>(tags));
|
||||||
|
PostVisibleScopeType oldVisibleScope = post.getVisibleScope();
|
||||||
post.setVisibleScope(postVisibleScopeType);
|
post.setVisibleScope(postVisibleScopeType);
|
||||||
Post updated = postRepository.save(post);
|
Post updated = postRepository.save(post);
|
||||||
imageUploader.adjustReferences(oldContent, content);
|
imageUploader.adjustReferences(oldContent, content);
|
||||||
@@ -1212,6 +1213,14 @@ public class PostService {
|
|||||||
if (!oldTags.equals(newTags)) {
|
if (!oldTags.equals(newTags)) {
|
||||||
postChangeLogService.recordTagChange(updated, user, oldTags, newTags);
|
postChangeLogService.recordTagChange(updated, user, oldTags, newTags);
|
||||||
}
|
}
|
||||||
|
if (!java.util.Objects.equals(oldVisibleScope, postVisibleScopeType)) {
|
||||||
|
postChangeLogService.recordVisibleScopeChange(
|
||||||
|
updated,
|
||||||
|
user,
|
||||||
|
oldVisibleScope,
|
||||||
|
postVisibleScopeType
|
||||||
|
);
|
||||||
|
}
|
||||||
if (updated.getStatus() == PostStatus.PUBLISHED) {
|
if (updated.getStatus() == PostStatus.PUBLISHED) {
|
||||||
searchIndexEventPublisher.publishPostSaved(updated);
|
searchIndexEventPublisher.publishPostSaved(updated);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,10 @@
|
|||||||
<template v-if="log.newFeatured">将文章设为精选</template>
|
<template v-if="log.newFeatured">将文章设为精选</template>
|
||||||
<template v-else>取消精选文章</template>
|
<template v-else>取消精选文章</template>
|
||||||
</span>
|
</span>
|
||||||
|
<span v-else-if="log.type === 'VISIBLE_SCOPE'" class="change-log-content">
|
||||||
|
变更了文章可见范围, 从 {{ formatVisibleScope(log.oldVisibleScope) }} 修改为
|
||||||
|
{{ formatVisibleScope(log.newVisibleScope) }}
|
||||||
|
</span>
|
||||||
<span v-else-if="log.type === 'VOTE_RESULT'" class="change-log-content"
|
<span v-else-if="log.type === 'VOTE_RESULT'" class="change-log-content"
|
||||||
>系统已计算投票结果</span
|
>系统已计算投票结果</span
|
||||||
>
|
>
|
||||||
@@ -69,6 +73,17 @@ const props = defineProps({
|
|||||||
title: String,
|
title: String,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const VISIBLE_SCOPE_LABELS = {
|
||||||
|
ALL: '全部可见',
|
||||||
|
ONLY_ME: '仅自己可见',
|
||||||
|
ONLY_REGISTER: '仅注册用户可见',
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatVisibleScope = (scope) => {
|
||||||
|
if (!scope) return VISIBLE_SCOPE_LABELS.ALL
|
||||||
|
return VISIBLE_SCOPE_LABELS[scope] ?? scope
|
||||||
|
}
|
||||||
|
|
||||||
const diffHtml = computed(() => {
|
const diffHtml = computed(() => {
|
||||||
// Track theme changes
|
// Track theme changes
|
||||||
const isDark = import.meta.client && document.documentElement.dataset.theme === 'dark'
|
const isDark = import.meta.client && document.documentElement.dataset.theme === 'dark'
|
||||||
|
|||||||
@@ -416,6 +416,14 @@ const changeLogIcon = (l) => {
|
|||||||
} else {
|
} else {
|
||||||
return 'dislike'
|
return 'dislike'
|
||||||
}
|
}
|
||||||
|
} else if (l.type === 'VISIBLE_SCOPE') {
|
||||||
|
if (l.newVisibleScope === 'ONLY_ME') {
|
||||||
|
return 'lock-one'
|
||||||
|
} else if (l.newVisibleScope === 'ONLY_REGISTER') {
|
||||||
|
return 'peoples-two'
|
||||||
|
} else {
|
||||||
|
return 'communication'
|
||||||
|
}
|
||||||
} else if (l.type === 'VOTE_RESULT') {
|
} else if (l.type === 'VOTE_RESULT') {
|
||||||
return 'check-one'
|
return 'check-one'
|
||||||
} else if (l.type === 'LOTTERY_RESULT') {
|
} else if (l.type === 'LOTTERY_RESULT') {
|
||||||
@@ -446,6 +454,8 @@ const mapChangeLog = (l) => ({
|
|||||||
newCategory: l.newCategory,
|
newCategory: l.newCategory,
|
||||||
oldTags: l.oldTags,
|
oldTags: l.oldTags,
|
||||||
newTags: l.newTags,
|
newTags: l.newTags,
|
||||||
|
oldVisibleScope: l.oldVisibleScope,
|
||||||
|
newVisibleScope: l.newVisibleScope,
|
||||||
amount: l.amount,
|
amount: l.amount,
|
||||||
icon: changeLogIcon(l),
|
icon: changeLogIcon(l),
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user