把可拼装的排到前面,再根据发布时间排序
This commit is contained in:
+6
-4
@@ -36,7 +36,8 @@ public class AdminProjectController {
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam(required = false) String publishStatus,
|
||||
@RequestParam(required = false) String repoStatus,
|
||||
@RequestParam(required = false) String moderationStatus) {
|
||||
@RequestParam(required = false) String moderationStatus,
|
||||
@RequestParam(defaultValue = "CREATED_AT_DESC") String sort) {
|
||||
return ApiResponse.success(
|
||||
management.projects(
|
||||
page,
|
||||
@@ -46,7 +47,8 @@ public class AdminProjectController {
|
||||
keyword,
|
||||
publishStatus,
|
||||
repoStatus,
|
||||
moderationStatus));
|
||||
moderationStatus,
|
||||
sort));
|
||||
}
|
||||
|
||||
@GetMapping("/types")
|
||||
@@ -66,8 +68,8 @@ public class AdminProjectController {
|
||||
|
||||
@PatchMapping("/{projectCode}")
|
||||
public ApiResponse<ProjectView> update(
|
||||
@PathVariable String projectCode, @Valid @RequestBody ProjectInput input) {
|
||||
return ApiResponse.success(projects.update(0, projectCode, input));
|
||||
@PathVariable String projectCode, @Valid @RequestBody UpdateProjectInput input) {
|
||||
return ApiResponse.success(projects.updateByAdmin(projectCode, input));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{projectCode}")
|
||||
|
||||
+1
-1
@@ -53,6 +53,6 @@ public class AdminUserController {
|
||||
@RequestParam(defaultValue = "1") long page,
|
||||
@RequestParam(defaultValue = "20") long size) {
|
||||
return ApiResponse.success(
|
||||
service.projects(page, size, userCode, null, null, null, null, null));
|
||||
service.projects(page, size, userCode, null, null, null, null, null, null));
|
||||
}
|
||||
}
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.linkerbot.vibemake.adminapi;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import com.linkerbot.vibemake.adminapi.controller.AdminStepController;
|
||||
import com.linkerbot.vibemake.common.ApiResponse;
|
||||
import com.linkerbot.vibemake.common.RequestTooLargeException;
|
||||
import com.linkerbot.vibemake.service.admin.AdminStepService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.mock.http.MockHttpInputMessage;
|
||||
|
||||
class AdminStepControllerTest {
|
||||
@Test
|
||||
void jsonParsingErrorsKeepRequestBodyLimitSeparateFromInvalidFileParameters() {
|
||||
AdminStepController controller = new AdminStepController(mock(AdminStepService.class));
|
||||
HttpMessageNotReadableException oversized = new HttpMessageNotReadableException("读取失败",
|
||||
new RuntimeException(new RequestTooLargeException()), new MockHttpInputMessage(new byte[0]));
|
||||
ResponseEntity<ApiResponse<Object>> response = controller.invalidJson(oversized);
|
||||
assertThat(response.getStatusCode().value()).isEqualTo(413);
|
||||
assertThat(response.getBody().code()).isEqualTo("REQUEST_TOO_LARGE");
|
||||
assertThat(response.getHeaders().getCacheControl()).isEqualTo("no-store");
|
||||
HttpMessageNotReadableException invalid = new HttpMessageNotReadableException(
|
||||
"大小不是整数", new MockHttpInputMessage(new byte[0]));
|
||||
ResponseEntity<ApiResponse<Object>> invalidResponse = controller.invalidJson(invalid);
|
||||
assertThat(invalidResponse.getStatusCode().value()).isEqualTo(400);
|
||||
assertThat(invalidResponse.getBody().code()).isEqualTo("STEP_INVALID_FILE");
|
||||
}
|
||||
}
|
||||
+85
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.*;
|
||||
import com.linkerbot.vibemake.adminapi.security.AdminAuthService;
|
||||
import com.linkerbot.vibemake.bean.entity.*;
|
||||
import com.linkerbot.vibemake.common.BusinessException;
|
||||
import com.linkerbot.vibemake.common.ProjectListingFixtures;
|
||||
import com.linkerbot.vibemake.security.TokenService;
|
||||
import com.linkerbot.vibemake.service.*;
|
||||
import com.linkerbot.vibemake.service.admin.AdminImportService;
|
||||
@@ -177,6 +178,90 @@ class AdminWorkflowTest {
|
||||
.asText();
|
||||
}
|
||||
|
||||
@Test
|
||||
void publicationTimeCanBeSetOmittedClearedAndIsProtectedFromOrdinaryUsers() throws Exception {
|
||||
String code = createProject();
|
||||
String endpoint = "/admin-api/projects/" + code;
|
||||
String sha = request(signed(get(endpoint + "/tree")), 200).path("data").path("commitSha").asText();
|
||||
JsonNode published = request(signed(body(put(endpoint + "/publication"),
|
||||
Map.of("commitSha", sha))), 200).path("data");
|
||||
assertThat(published.path("publishedAt").isTextual()).isTrue();
|
||||
String manualTime = "2020-01-02T03:04:05.123";
|
||||
Map<String, Object> input = new HashMap<>(metadata());
|
||||
input.put("publishedAt", manualTime);
|
||||
// 请求不能伪造字段存在标记来绕过实际 publishedAt 的提交语义。
|
||||
input.put("publishedAtProvided", false);
|
||||
JsonNode edited = request(signed(body(patch(endpoint), input)), 200).path("data");
|
||||
assertThat(edited.path("publishedAt").asText()).isEqualTo(manualTime);
|
||||
for (String field : List.of("publishStatus", "publishedCommitSha"))
|
||||
assertThat(edited.path(field)).isEqualTo(published.path(field));
|
||||
Map<String, Object> omitted = new HashMap<>(metadata());
|
||||
omitted.put("publishedAtProvided", true);
|
||||
assertThat(request(signed(body(patch(endpoint), omitted)), 200)
|
||||
.path("data").path("publishedAt").asText()).isEqualTo(manualTime);
|
||||
assertThat(request(signed(body(put(endpoint + "/publication"), Map.of("commitSha", sha))), 200)
|
||||
.path("data").path("publishedAt").asText()).isEqualTo(manualTime);
|
||||
|
||||
for (Object invalid : List.of("not-a-time", "", "2026-11-02T10:30:00Z", 123,
|
||||
List.of(2026, 11, 2, 10, 30))) {
|
||||
input.put("publishedAt", invalid);
|
||||
request(signed(body(patch(endpoint), input)), 400);
|
||||
}
|
||||
request(signed(body(patch(endpoint), Map.of("publishedAt", manualTime))), 400);
|
||||
assertThat(request(signed(get(endpoint)), 200).path("data").path("project")
|
||||
.path("publishedAt").asText()).isEqualTo(manualTime);
|
||||
input.put("publishedAt", null);
|
||||
JsonNode cleared = request(signed(body(patch(endpoint), input)), 200).path("data");
|
||||
assertThat(cleared.path("publishedAt").isNull()).isTrue();
|
||||
for (String field : List.of("publishStatus", "publishedCommitSha"))
|
||||
assertThat(cleared.path(field)).isEqualTo(published.path(field));
|
||||
assertThat(jdbc.queryForObject("SELECT published_at FROM project WHERE project_code=?",
|
||||
java.time.LocalDateTime.class, code)).isNull();
|
||||
assertThat(request(signed(body(put(endpoint + "/publication"), Map.of("commitSha", sha))), 200)
|
||||
.path("data").path("publishedAt").isTextual()).isTrue();
|
||||
String ordinaryToken = tokens.issue(ordinary.getId(), ordinary.getSessionVersion());
|
||||
request(body(patch(endpoint), input).header("Authorization", "Bearer " + ordinaryToken), 403);
|
||||
assertThatThrownBy(() -> projectService.updateByAdmin(code,
|
||||
json.convertValue(input, com.linkerbot.vibemake.bean.AdminContracts.UpdateProjectInput.class)))
|
||||
.isInstanceOf(BusinessException.class).hasMessageContaining("仅限后台管理员");
|
||||
}
|
||||
|
||||
@Test
|
||||
void projectListSupportsAllSortModesWithStablePaginationAndFilters() throws Exception {
|
||||
String template = createProject();
|
||||
ProjectListingFixtures.Fixture fixture = ProjectListingFixtures.create(dataSource, template);
|
||||
jdbc.update("UPDATE project SET deleted=1 WHERE project_code=?", template);
|
||||
Map<String, List<String>> orders = Map.of(
|
||||
"CREATED_AT_DESC", fixture.createdOrder(),
|
||||
"PUBLISHED_AT_DESC", fixture.publishedOrder(),
|
||||
"RESOURCES_FIRST", fixture.resourcesOrder());
|
||||
for (Map.Entry<String, List<String>> entry : orders.entrySet()) {
|
||||
List<String> actual = new ArrayList<>();
|
||||
for (int page = 1; page <= 4; page++) {
|
||||
JsonNode data = request(signed(get("/admin-api/projects")
|
||||
.param("sort", entry.getKey()).param("page", Integer.toString(page)).param("size", "3")
|
||||
.param("type", "WHEELED").param("keyword", "排序测试")
|
||||
.param("publishStatus", "PUBLISHED").param("repoStatus", "READY")
|
||||
.param("moderationStatus", "NORMAL")), 200).path("data");
|
||||
assertThat(data.path("total").asLong()).isEqualTo(10);
|
||||
for (JsonNode item : data.path("items"))
|
||||
actual.add(item.path("project").path("projectCode").asText());
|
||||
}
|
||||
assertThat(actual).as(entry.getKey()).containsExactlyElementsOf(entry.getValue());
|
||||
}
|
||||
JsonNode defaults = request(signed(get("/admin-api/projects")), 200).path("data").path("items");
|
||||
assertThat(defaults).extracting(p -> p.path("project").path("projectCode").asText())
|
||||
.containsExactlyElementsOf(fixture.createdOrder());
|
||||
assertThat(request(signed(get("/admin-api/projects").param("sort", "RESOURCES_FIRST")
|
||||
.param("ownerUserCode", ordinary.getUserCode())), 200)
|
||||
.path("data").path("total").asLong()).isZero();
|
||||
assertThat(request(signed(get("/admin-api/projects").param("sort", "PUBLISHED_AT_DESC")
|
||||
.param("moderationStatus", "BLOCKED")), 200)
|
||||
.path("data").path("total").asLong()).isZero();
|
||||
for (String invalid : List.of("unknown", "published_at DESC", "id; DROP TABLE project"))
|
||||
request(signed(get("/admin-api/projects").param("sort", invalid)), 400);
|
||||
}
|
||||
|
||||
private MockHttpServletRequestBuilder uploadRequest(String code, String sha) {
|
||||
return signed(multipart("/admin-api/projects/" + code + "/uploads/commit")
|
||||
.file(new MockMultipartFile("files", "sample.txt", "text/plain", "hello".getBytes()))
|
||||
|
||||
Reference in New Issue
Block a user