fix project apiv2 NPEing for anon access

This commit is contained in:
MiniDigger 2020-08-05 16:22:36 +02:00
parent 0f88e0492c
commit 0ae98abe7f
2 changed files with 6 additions and 5 deletions

View File

@ -71,7 +71,8 @@ public class ProjectsApiController implements ProjectsApi {
UsersTable currentUser = userService.getCurrentUser();
// TODO this is really meh, we want to save global permissions somewhere
boolean seeHidden = permissionService.getGlobalPermissions(currentUser.getId()).has(Permission.SeeHidden);
boolean seeHidden = currentUser != null && permissionService.getGlobalPermissions(currentUser.getId()).has(Permission.SeeHidden);
Long requesterId = currentUser == null ? null : currentUser.getId();
List<Project> projects = projectService.getProjects(
null,
@ -80,7 +81,7 @@ public class ProjectsApiController implements ProjectsApi {
q,
owner,
seeHidden,
currentUser.getId(),
requesterId,
sort,
relevance,
limit,
@ -94,7 +95,7 @@ public class ProjectsApiController implements ProjectsApi {
q,
owner,
seeHidden,
currentUser.getId()
requesterId
);
PaginatedProjectResult result = new PaginatedProjectResult();

View File

@ -193,11 +193,11 @@ public class ProjectService {
return projectDao.get().getUnhealthyProjects(hangarConfig.projects.getStaleAge().toMillis());
}
public List<Project> getProjects(String pluginId, List<Category> categories, List<Tag> parsedTags, String query, String owner, boolean seeHidden, long requesterId, ProjectSortingStrategy sort, boolean relevance, long limit, long offset) {
public List<Project> getProjects(String pluginId, List<Category> categories, List<Tag> parsedTags, String query, String owner, boolean seeHidden, Long requesterId, ProjectSortingStrategy sort, boolean relevance, long limit, long offset) {
return List.of(getProjectApi("test")); // TODO getProjects query
}
public long countProjects(String pluginId, List<Category> categories, List<Tag> parsedTags, String query, String owner, boolean seeHidden, long requesterId) {
public long countProjects(String pluginId, List<Category> categories, List<Tag> parsedTags, String query, String owner, boolean seeHidden, Long requesterId) {
return 1; // TODO count projects query
}
}