mirror of
https://github.com/HangarMC/Hangar.git
synced 2024-11-21 01:21:54 +08:00
fix: starring and watching queries
This commit is contained in:
parent
91536786f2
commit
2576321379
@ -40,8 +40,8 @@ public interface UsersApiDAO {
|
||||
JOIN project_stars ps ON u.id = ps.user_id
|
||||
JOIN home_projects hp ON ps.project_id = hp.id
|
||||
WHERE
|
||||
<if(!canSeeHidden)> (p.visibility = 0
|
||||
<if(userId)>OR (<userId> = ANY(hp.project_members) AND p.visibility != 4)<endif>) AND <endif>
|
||||
<if(!canSeeHidden)> (hp.visibility = 0
|
||||
<if(userId)>OR (<userId> = ANY(hp.project_members) AND hp.visibility != 4)<endif>) AND <endif>
|
||||
lower(u.name) = lower(:user)
|
||||
<sorters>
|
||||
<offsetLimit>""")
|
||||
@ -54,8 +54,8 @@ public interface UsersApiDAO {
|
||||
JOIN project_stars ps ON u.id = ps.user_id
|
||||
JOIN home_projects hp ON ps.project_id = hp.id
|
||||
WHERE
|
||||
<if(!canSeeHidden)> (p.visibility = 0
|
||||
<if(userId)>OR (<userId> = ANY(hp.project_members) AND p.visibility != 4)<endif>) AND <endif>
|
||||
<if(!canSeeHidden)> (hp.visibility = 0
|
||||
<if(userId)>OR (<userId> = ANY(hp.project_members) AND hp.visibility != 4)<endif>) AND <endif>
|
||||
lower(u.name) = lower(:user)""")
|
||||
long getUserStarredCount(String user, @Define boolean canSeeHidden, @Define Long userId);
|
||||
|
||||
@ -80,8 +80,8 @@ public interface UsersApiDAO {
|
||||
JOIN project_watchers pw ON u.id = pw.user_id
|
||||
JOIN home_projects hp ON pw.project_id = hp.id
|
||||
WHERE
|
||||
<if(!canSeeHidden)> (p.visibility = 0
|
||||
<if(userId)>OR (<userId> = ANY(hp.project_members) AND p.visibility != 4)<endif>) AND <endif>
|
||||
<if(!canSeeHidden)> (hp.visibility = 0
|
||||
<if(userId)>OR (<userId> = ANY(hp.project_members) AND hp.visibility != 4)<endif>) AND <endif>
|
||||
lower(u.name) = lower(:user)
|
||||
<sorters>
|
||||
<offsetLimit>""")
|
||||
@ -94,8 +94,8 @@ public interface UsersApiDAO {
|
||||
JOIN project_watchers pw ON u.id = pw.user_id
|
||||
JOIN home_projects hp ON pw.project_id = hp.id
|
||||
WHERE
|
||||
<if(!canSeeHidden)> (p.visibility = 0
|
||||
<if(userId)>OR (<userId> = ANY(hp.project_members) AND p.visibility != 4)<endif>) AND <endif>
|
||||
<if(!canSeeHidden)> (hp.visibility = 0
|
||||
<if(userId)>OR (<userId> = ANY(hp.project_members) AND hp.visibility != 4)<endif>) AND <endif>
|
||||
lower(u.name) = lower(:user)""")
|
||||
long getUserWatchingCount(String user, @Define boolean canSeeHidden, @Define Long userId);
|
||||
|
||||
|
@ -48,7 +48,7 @@ class UserControllerTest extends ControllerTest {
|
||||
this.mockMvc.perform(get("/api/v1/users/TestAdmin/starred")
|
||||
.with(this.apiKey(TestData.KEY_ADMIN)))
|
||||
.andExpect(status().is(200))
|
||||
.andExpect(jsonPath("$.pagination.count", is(1)));
|
||||
.andExpect(jsonPath("$.pagination.count", is(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -58,6 +58,10 @@ class UserControllerTest extends ControllerTest {
|
||||
.andExpect(status().is(200))
|
||||
.andExpect(jsonPath("$.pagination.count", is(1)))
|
||||
.andExpect(jsonPath("$.result[*].name", contains("TestProject")));
|
||||
this.mockMvc.perform(get("/api/v1/users/TestAdmin/watching")
|
||||
.with(this.apiKey(TestData.KEY_ADMIN)))
|
||||
.andExpect(status().is(200))
|
||||
.andExpect(jsonPath("$.pagination.count", is(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -68,7 +72,6 @@ class UserControllerTest extends ControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO fix this
|
||||
void testGetAuthors() throws Exception {
|
||||
this.mockMvc.perform(get("/api/v1/authors?query=PaperMC")
|
||||
.with(this.apiKey(TestData.KEY_ADMIN)))
|
||||
|
@ -7,6 +7,7 @@ import io.papermc.hangar.model.api.project.ProjectLicense;
|
||||
import io.papermc.hangar.model.api.project.settings.ProjectSettings;
|
||||
import io.papermc.hangar.model.common.NamedPermission;
|
||||
import io.papermc.hangar.model.common.Permission;
|
||||
import io.papermc.hangar.model.common.Platform;
|
||||
import io.papermc.hangar.model.common.projects.Category;
|
||||
import io.papermc.hangar.model.common.roles.GlobalRole;
|
||||
import io.papermc.hangar.model.common.roles.OrganizationRole;
|
||||
@ -17,6 +18,8 @@ import io.papermc.hangar.model.db.projects.ProjectTable;
|
||||
import io.papermc.hangar.model.db.roles.GlobalRoleTable;
|
||||
import io.papermc.hangar.model.internal.api.requests.CreateAPIKeyForm;
|
||||
import io.papermc.hangar.model.internal.api.requests.projects.NewProjectForm;
|
||||
import io.papermc.hangar.model.internal.versions.PendingVersion;
|
||||
import io.papermc.hangar.model.internal.versions.PendingVersionFile;
|
||||
import io.papermc.hangar.security.authentication.HangarPrincipal;
|
||||
import io.papermc.hangar.service.APIKeyService;
|
||||
import io.papermc.hangar.service.internal.organizations.OrganizationFactory;
|
||||
@ -26,10 +29,14 @@ import io.papermc.hangar.service.internal.projects.ProjectFactory;
|
||||
import io.papermc.hangar.service.internal.projects.ProjectPageService;
|
||||
import io.papermc.hangar.service.internal.projects.ProjectService;
|
||||
import io.papermc.hangar.service.internal.users.UserService;
|
||||
import io.papermc.hangar.service.internal.versions.VersionFactory;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -75,6 +82,8 @@ public class TestData {
|
||||
private ProjectService projectService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private VersionFactory versionFactory;
|
||||
|
||||
@EventListener(ApplicationStartedEvent.class)
|
||||
public void prepare() {
|
||||
@ -99,6 +108,9 @@ public class TestData {
|
||||
PAGE_PARENT = this.projectPageService.createPage(PROJECT.getProjectId(), "TestParentPage", "testparentpage", "# TestParentPage", true, null, false);
|
||||
PAGE_CHILD = this.projectPageService.createPage(PROJECT.getProjectId(), "TestChildPage", "testparentpage/testchild", "# TestChildPage", true, PAGE_PARENT.getId(), false);
|
||||
|
||||
logger.info("Creating some test versions...");
|
||||
this.versionFactory.publishPendingVersion(PROJECT.getProjectId(), new PendingVersion("1.0", Map.of(), new EnumMap<>(Map.of(Platform.PAPER, new TreeSet<>(Set.of("1.8")))), "# 1.0", List.of(new PendingVersionFile(List.of(Platform.PAPER), null, "https://google.com")), "Release", "Release channel", null, Set.of()));
|
||||
|
||||
logger.info("Creating test api keys...");
|
||||
KEY_ADMIN = this.apiKeyService.createApiKey(USER_ADMIN, new CreateAPIKeyForm("Admin", Set.of(NamedPermission.values())), Permission.All);
|
||||
KEY_ALL = this.apiKeyService.createApiKey(USER_NORMAL, new CreateAPIKeyForm("All", new HashSet<>(Permission.fromBinString("0000000000000000000011110000111100001111001100001111011111110111").toNamed())), Permission.All);
|
||||
|
Loading…
Reference in New Issue
Block a user