|
|
@@ -172,7 +172,12 @@ public class AdminArticleController {
|
|
|
}
|
|
|
|
|
|
@PostMapping("/update")
|
|
|
- public Result<String> update(@RequestBody Map<String, Object> body) {
|
|
|
+ public Result<String> update(@RequestBody Map<String, Object> body,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ // S-cfc-315 / B-142-1:admin 角色守卫,非 admin(如登录的 parent/child)拒绝更新文章
|
|
|
+ if (!"admin".equals(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
String title = (String) body.get("title");
|
|
|
String content = (String) body.get("content");
|
|
|
|
|
|
@@ -267,21 +272,36 @@ public class AdminArticleController {
|
|
|
}
|
|
|
|
|
|
@PostMapping("/delete")
|
|
|
- public Result<String> delete(@RequestBody Map<String, Object> body) {
|
|
|
+ public Result<String> delete(@RequestBody Map<String, Object> body,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ // S-cfc-315 / B-142-1:admin 角色守卫,非 admin 拒绝删除文章
|
|
|
+ if (!"admin".equals(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
Long id = ParamUtils.getLong(body.get("id"));
|
|
|
articleService.delete(id);
|
|
|
return Result.success("删除成功");
|
|
|
}
|
|
|
|
|
|
@PostMapping("/{id}/publish")
|
|
|
- public Result<String> publishById(@PathVariable Long id, @RequestBody Map<String, Object> body) {
|
|
|
+ public Result<String> publishById(@PathVariable Long id, @RequestBody Map<String, Object> body,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ // S-cfc-315 / B-142-1:admin 角色守卫,非 admin 拒绝直接发布/上下架
|
|
|
+ if (!"admin".equals(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
String status = (String) body.get("status");
|
|
|
articleService.toggleStatus(id, status);
|
|
|
return Result.success("操作成功");
|
|
|
}
|
|
|
|
|
|
@PostMapping("/publish")
|
|
|
- public Result<String> publish(@RequestBody Map<String, Object> body) {
|
|
|
+ public Result<String> publish(@RequestBody Map<String, Object> body,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ // S-cfc-315 / B-142-1:admin 角色守卫,非 admin(如登录的 parent/child)拒绝直接发布/上下架文章
|
|
|
+ if (!"admin".equals(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
if (body.get("id") == null) {
|
|
|
return Result.error("缺少文章ID");
|
|
|
}
|
|
|
@@ -291,6 +311,11 @@ public class AdminArticleController {
|
|
|
return Result.success("操作成功");
|
|
|
}
|
|
|
|
|
|
+ /** 单测契约兼容:1 参数 publish(非 HTTP 端点),委托完整守卫版本。 */
|
|
|
+ public Result<String> publish(Map<String, Object> body) {
|
|
|
+ return publish(body, "admin");
|
|
|
+ }
|
|
|
+
|
|
|
@PostMapping("/backfill-tags")
|
|
|
public Result<Integer> backfillTags() {
|
|
|
int n = articleService.backfillEmptyPublishedTags();
|
|
|
@@ -298,13 +323,23 @@ public class AdminArticleController {
|
|
|
}
|
|
|
|
|
|
@PostMapping("/toggle-featured")
|
|
|
- public Result<String> toggleFeatured(@RequestBody Map<String, Object> body) {
|
|
|
+ public Result<String> toggleFeatured(@RequestBody Map<String, Object> body,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ // S-cfc-315 / B-142-1:admin 角色守卫,非 admin 拒绝置精选
|
|
|
+ if (!"admin".equals(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
Long id = ParamUtils.getLong(body.get("id"));
|
|
|
int isFeatured = Integer.parseInt(body.get("isFeatured").toString());
|
|
|
articleService.toggleFeatured(id, isFeatured);
|
|
|
return Result.success("操作成功");
|
|
|
}
|
|
|
|
|
|
+ /** 单测契约兼容:1 参数 toggleFeatured(非 HTTP 端点),委托完整守卫版本。 */
|
|
|
+ public Result<String> toggleFeatured(Map<String, Object> body) {
|
|
|
+ return toggleFeatured(body, "admin");
|
|
|
+ }
|
|
|
+
|
|
|
@PostMapping("/move")
|
|
|
public Result<String> move(@RequestBody Map<String, Object> body,
|
|
|
@RequestAttribute("role") String role) {
|
|
|
@@ -353,7 +388,12 @@ public class AdminArticleController {
|
|
|
}
|
|
|
|
|
|
@PostMapping("/submit-review")
|
|
|
- public Result<String> submitReview(@RequestBody Map<String, Object> body) {
|
|
|
+ public Result<String> submitReview(@RequestBody Map<String, Object> body,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ // S-cfc-315 / B-142-1:admin 角色守卫,非 admin 拒绝提交审核
|
|
|
+ if (!"admin".equals(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
Long id = ParamUtils.getLong(body.get("id"));
|
|
|
if (id == null) return Result.error("缺少文章ID");
|
|
|
try {
|
|
|
@@ -364,8 +404,18 @@ public class AdminArticleController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /** 单测契约兼容:1 参数 submitReview(非 HTTP 端点),委托完整守卫版本。 */
|
|
|
+ public Result<String> submitReview(Map<String, Object> body) {
|
|
|
+ return submitReview(body, "admin");
|
|
|
+ }
|
|
|
+
|
|
|
@PostMapping("/withdraw")
|
|
|
- public Result<String> withdraw(@RequestBody Map<String, Object> body) {
|
|
|
+ public Result<String> withdraw(@RequestBody Map<String, Object> body,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ // S-cfc-315 / B-142-1:admin 角色守卫,非 admin 拒绝撤回
|
|
|
+ if (!"admin".equals(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
Long id = ParamUtils.getLong(body.get("id"));
|
|
|
if (id == null) return Result.error("缺少文章ID");
|
|
|
try {
|
|
|
@@ -376,8 +426,18 @@ public class AdminArticleController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /** 单测契约兼容:1 参数 withdraw(非 HTTP 端点),委托完整守卫版本。 */
|
|
|
+ public Result<String> withdraw(Map<String, Object> body) {
|
|
|
+ return withdraw(body, "admin");
|
|
|
+ }
|
|
|
+
|
|
|
@PostMapping("/re-draft")
|
|
|
- public Result<String> reDraft(@RequestBody Map<String, Object> body) {
|
|
|
+ public Result<String> reDraft(@RequestBody Map<String, Object> body,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ // S-cfc-315 / B-142-1:admin 角色守卫,非 admin 拒绝转草稿
|
|
|
+ if (!"admin".equals(role)) {
|
|
|
+ return Result.error("无权限");
|
|
|
+ }
|
|
|
Long id = ParamUtils.getLong(body.get("id"));
|
|
|
if (id == null) return Result.error("缺少文章ID");
|
|
|
try {
|
|
|
@@ -388,6 +448,11 @@ public class AdminArticleController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /** 单测契约兼容:1 参数 reDraft(非 HTTP 端点),委托完整守卫版本。 */
|
|
|
+ public Result<String> reDraft(Map<String, Object> body) {
|
|
|
+ return reDraft(body, "admin");
|
|
|
+ }
|
|
|
+
|
|
|
@PostMapping("/upload/image")
|
|
|
public Result<String> uploadImage(@RequestParam("file") MultipartFile file) {
|
|
|
if (file.isEmpty()) {
|