恢复点(restore point)。别人改崩后可 git reset --hard 回到此提交。 == 此快照内容 == - 后端 oa-backend: 734 控制器 / 711 实体 (Spring Boot 3.2.5 + SQLite, 端口8091) - 前端 modern-ui/app: Vue3+Vite, 约700页 (构建产物已在 oa-backend/src/main/resources/static) - 数据库 oa-backend/data/oa.db: 含全部演示数据 (强制入库, 6.6MB) - 交接文档 go.md + go-code-reference/endpoints/entities/database.md - 多代理建设脚本 .claude/wf-*.js == 状态 == - 对 凯迪科技ERP_20260507.xlsx 合规 MET ~73.3% (PARTIAL 75: 34可建+6种子/bug+35外部硬天花板) - 安全: 5轮红队+5轮复检, default-deny分级鉴权, 连续零可利用 - W3~W7 累计补完436缺口; W8末轮(40缺口)为半成品(源码树可编译但未集成) - 运行: cd oa-backend; java -jar build/libs/oa-backend-0.1.0.jar --server.port=8091; admin/123456 == 排除(gitignore, 可再生) == node_modules / oa-backend/build / .jdks / *.log / Backup-ERP-* / 弃用的OFBiz核心(只保留modern-ui) 完整文件夹备份见同目录 Backup-ERP-20260615-191517/ (含上述全部, 仅缺 node_modules) 时间戳: 20260615-191517 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
106 lines
4.8 KiB
Java
106 lines
4.8 KiB
Java
package com.kaidi.oa.web;
|
|
|
|
import com.kaidi.oa.common.ApiException;
|
|
import com.kaidi.oa.common.ApiResp;
|
|
import com.kaidi.oa.common.NotFoundException;
|
|
import com.kaidi.oa.domain.Message;
|
|
import com.kaidi.oa.domain.SysUser;
|
|
import com.kaidi.oa.repository.MessageRepository;
|
|
import com.kaidi.oa.service.AuthorizationService;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 统一消息中心 API. Identity comes from the auth token (server-authoritative): a user
|
|
* only ever sees / clears their own messages. Drives the 顶栏铃铛 unread badge + the
|
|
* message list page.
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/api/oa/messages")
|
|
public class MessageController {
|
|
|
|
private final MessageRepository messageRepo;
|
|
private final CurrentUserResolver currentUser;
|
|
private final AuthorizationService authz;
|
|
|
|
public MessageController(MessageRepository messageRepo, CurrentUserResolver currentUser,
|
|
AuthorizationService authz) {
|
|
this.messageRepo = messageRepo;
|
|
this.currentUser = currentUser;
|
|
this.authz = authz;
|
|
}
|
|
|
|
/**
|
|
* GET /messages — my latest messages (newest first). 按名投递查询后再按稳定 recipientId 过滤:
|
|
* recipientId 命中本人才返回;recipientId 为空(旧行/未解析)时回退按名(查询已按名命中,自然保留)。
|
|
* 这样可堵住"改名后新用户占用旧名、把旧用户站内信连同正文读走"的改名重用泄漏。
|
|
*/
|
|
@GetMapping
|
|
public ApiResp<List<Message>> list(HttpServletRequest request) {
|
|
SysUser su = currentUser.resolve(request);
|
|
String me = currentUser.resolveLabel(request);
|
|
return ApiResp.ok(messageRepo.findTop200ByRecipientOrderByIdDesc(me).stream()
|
|
.filter(m -> authz.isOwner(su, m.getRecipientId(), m.getRecipient()))
|
|
.toList());
|
|
}
|
|
|
|
/** GET /messages/unread-count — my unread count (for the bell badge). 同 list:按 recipientId 过滤后计数。 */
|
|
@GetMapping("/unread-count")
|
|
public ApiResp<Map<String, Object>> unreadCount(HttpServletRequest request) {
|
|
SysUser su = currentUser.resolve(request);
|
|
String me = currentUser.resolveLabel(request);
|
|
long count = messageRepo.findByRecipientAndReadFalse(me).stream()
|
|
.filter(m -> authz.isOwner(su, m.getRecipientId(), m.getRecipient()))
|
|
.count();
|
|
Map<String, Object> m = new LinkedHashMap<>();
|
|
m.put("count", count);
|
|
return ApiResp.ok(m);
|
|
}
|
|
|
|
/** POST /messages/{id}/read — mark one of my messages read. */
|
|
@PostMapping("/{id}/read")
|
|
public ApiResp<Message> read(@PathVariable Long id, HttpServletRequest request) {
|
|
Message msg = messageRepo.findById(id)
|
|
.orElseThrow(() -> new NotFoundException("message not found: " + id));
|
|
// 对象级读授权:仅收件人本人或 ADMIN 可标记已读并取回正文,杜绝任意登录用户按 id
|
|
// 枚举把他人站内信(含审批正文/退回理由等)正文回吐(读 IDOR)。
|
|
// 身份按稳定 recipientId 比对(空时回退 recipient 名),根治改名重用冒充。
|
|
SysUser su = currentUser.resolve(request);
|
|
boolean isRecipient = authz.isOwner(su, msg.getRecipientId(), msg.getRecipient());
|
|
if (!authz.isAdmin(su) && !isRecipient) {
|
|
throw new ApiException(403, "无权访问:仅收件人本人或管理员可读取/标记该消息");
|
|
}
|
|
if (isRecipient && !msg.isRead()) {
|
|
msg.setRead(true);
|
|
messageRepo.save(msg);
|
|
}
|
|
return ApiResp.ok(msg);
|
|
}
|
|
|
|
/** POST /messages/read-all — mark all my messages read. */
|
|
@PostMapping("/read-all")
|
|
public ApiResp<Map<String, Object>> readAll(HttpServletRequest request) {
|
|
SysUser su = currentUser.resolve(request);
|
|
String me = currentUser.resolveLabel(request);
|
|
// 仅标记本人(按 recipientId 命中,空回退名)的未读,杜绝改名重用场景下误标他人未读为已读。
|
|
List<Message> unread = messageRepo.findByRecipientAndReadFalse(me).stream()
|
|
.filter(m -> authz.isOwner(su, m.getRecipientId(), m.getRecipient()))
|
|
.toList();
|
|
for (Message msg : unread) {
|
|
msg.setRead(true);
|
|
}
|
|
messageRepo.saveAll(unread);
|
|
Map<String, Object> m = new LinkedHashMap<>();
|
|
m.put("cleared", unread.size());
|
|
return ApiResp.ok(m);
|
|
}
|
|
}
|