Admin/health (#109)

* Implemented missingFiles without logic
So it will currently display all projects.
Also fixed the other health parts which didnt show up because namespace wasnt retrieved from the database correctly.

* Implemented missing files into admin/health

* Oops, used slug instead of name, it works better now

* change method calls to freemark format
This commit is contained in:
Dragonium 2020-09-02 21:08:39 +02:00 committed by GitHub
parent 2fd52c2241
commit 218a8a1460
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 13 deletions

View File

@ -149,8 +149,7 @@ public class ApplicationController extends HangarController {
mav.addObject("noTopicProjects", unhealthyProjects.stream().filter(p -> p.getTopicId() == null || p.getPostId() == null).collect(Collectors.toList()));
mav.addObject("staleProjects", unhealthyProjects);
mav.addObject("notPublicProjects", unhealthyProjects.stream().filter(p -> p.getVisibility() != Visibility.PUBLIC).collect(Collectors.toList()));
// TODO missingFiles
mav.addObject("missingFileProjects");
mav.addObject("missingFileProjects", projectService.getPluginsWithMissingFiles());
mav.addObject("erroredJobs", jobService.getErroredJobs());
return fillModel(mav);
}

View File

@ -7,6 +7,7 @@ import io.papermc.hangar.db.model.UsersTable;
import io.papermc.hangar.model.Permission;
import io.papermc.hangar.model.generated.ProjectStatsAll;
import io.papermc.hangar.model.viewhelpers.ProjectApprovalData;
import io.papermc.hangar.model.viewhelpers.ProjectMissingFile;
import io.papermc.hangar.model.viewhelpers.ScopedProjectData;
import io.papermc.hangar.model.viewhelpers.UnhealthyProject;
import io.papermc.hangar.service.project.ProjectFactory.InvalidProjectReason;
@ -156,7 +157,7 @@ public interface ProjectDao {
@RegisterBeanMapper(UnhealthyProject.class)
@UseStringTemplateEngine
@SqlQuery("SELECT p.owner_name, p.slug, p.topic_id, p.post_id, coalesce(hp.last_updated, p.created_at), p.visibility" +
@SqlQuery("SELECT p.owner_name pn_owner, p.slug pn_slug, p.topic_id, p.post_id, coalesce(hp.last_updated, p.created_at), p.visibility" +
" FROM projects p JOIN home_projects hp ON p.id = hp.id" +
" WHERE p.topic_id IS NULL" +
" OR p.post_id IS NULL" +
@ -168,4 +169,9 @@ public interface ProjectDao {
@SqlQuery("SELECT upr.id pr_id, upr.created_at pr_created_at, upr.user_id pr_user_id, upr.role_type pr_role_type, upr.project_id pr_project_id, upr.is_accepted pr_is_accepted, " +
"p.* FROM user_project_roles upr JOIN projects p ON p.id = upr.project_id WHERE upr.user_id = :userId")
Map<UserProjectRolesTable, ProjectsTable> getProjectRoles(long userId);
@SqlQuery("SELECT v.version_string version_versionString, v.file_name version_fileName, p.owner_name AS owner, p.name AS name " +
"FROM project_versions v JOIN projects p on v.project_id = p.id ")
@RegisterBeanMapper(value = ProjectMissingFile.class)
List<ProjectMissingFile> allProjectsForMissingFiles();
}

View File

@ -0,0 +1,48 @@
package io.papermc.hangar.model.viewhelpers;
import io.papermc.hangar.db.model.ProjectVersionsTable;
import org.jdbi.v3.core.mapper.Nested;
public class ProjectMissingFile {
private String owner;
private String name;
private ProjectVersionsTable version;
public ProjectVersionsTable getVersion() {
return version;
}
@Nested("version")
public void setVersion(ProjectVersionsTable version) {
this.version = version;
}
public String getDisplayText(){
return owner + "/" + name + "/" + version.getVersionString();
}
public void setOwner(String owner) {
this.owner = owner;
}
public String getOwner(){
return owner;
}
public void setName(String name) {
this.name = name;
}
public String getName(){
return name;
}
public String getVersionString(){
return getVersion().getVersionString();
}
public String getFileName(){
return getVersion().getFileName();
}
}

View File

@ -12,12 +12,12 @@ import io.papermc.hangar.db.model.ProjectVisibilityChangesTable;
import io.papermc.hangar.db.model.ProjectsTable;
import io.papermc.hangar.db.model.UserProjectRolesTable;
import io.papermc.hangar.db.model.UsersTable;
import io.papermc.hangar.model.Role;
import io.papermc.hangar.model.Visibility;
import io.papermc.hangar.model.generated.*;
import io.papermc.hangar.model.viewhelpers.ProjectData;
import io.papermc.hangar.model.viewhelpers.ProjectFlag;
import io.papermc.hangar.service.UserService;
import io.papermc.hangar.service.pluginupload.ProjectFiles;
import io.papermc.hangar.util.StringUtils;
import io.papermc.hangar.db.dao.VisibilityDao;
import io.papermc.hangar.model.Category;
@ -26,6 +26,7 @@ import io.papermc.hangar.model.viewhelpers.ProjectViewSettings;
import io.papermc.hangar.model.viewhelpers.ScopedProjectData;
import io.papermc.hangar.model.viewhelpers.UnhealthyProject;
import io.papermc.hangar.model.viewhelpers.UserRole;
import io.papermc.hangar.model.viewhelpers.ProjectMissingFile;
import org.postgresql.shaded.com.ongres.scram.common.util.Preconditions;
import org.springframework.beans.factory.annotation.Autowired;
@ -34,6 +35,7 @@ import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;
import java.nio.file.Path;
import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.List;
@ -52,9 +54,10 @@ public class ProjectService {
private final HangarDao<GeneralDao> generalDao;
private final UserService userService;
private final FlagService flagService;
private final ProjectFiles projectFiles;
@Autowired
public ProjectService(HangarConfig hangarConfig, HangarDao<ProjectDao> projectDao, HangarDao<UserDao> userDao, HangarDao<VisibilityDao> visibilityDao, HangarDao<ProjectApiDao> projectApiDao, HangarDao<ProjectViewDao> projectViewDao, HangarDao<GeneralDao> generalDao, UserService userService, FlagService flagService) {
public ProjectService(HangarConfig hangarConfig, HangarDao<ProjectDao> projectDao, HangarDao<UserDao> userDao, HangarDao<VisibilityDao> visibilityDao, HangarDao<ProjectApiDao> projectApiDao, HangarDao<ProjectViewDao> projectViewDao, HangarDao<GeneralDao> generalDao, ProjectFiles projectFiles, UserService userService, FlagService flagService) {
this.hangarConfig = hangarConfig;
this.projectDao = projectDao;
this.userDao = userDao;
@ -62,6 +65,7 @@ public class ProjectService {
this.projectApiDao = projectApiDao;
this.projectViewDao = projectViewDao;
this.generalDao = generalDao;
this.projectFiles = projectFiles;
this.userService = userService;
this.flagService = flagService;
}
@ -274,4 +278,13 @@ public class ProjectService {
private List<String> getTagsNamesAndVersion(List<Tag> tags){
return tags == null ? null : tags.stream().filter(tag -> tag.getData() != null).map(tag -> " (" + tag.getName() + "," + tag.getData() + ") ").collect(Collectors.toList());
}
public List<ProjectMissingFile> getPluginsWithMissingFiles() {
List<ProjectMissingFile> projectMissingFiles = projectDao.get().allProjectsForMissingFiles();
return projectMissingFiles.stream()
.filter(project -> {
Path path = projectFiles.getVersionDir(project.getOwner(), project.getName(), project.getVersionString());
return !path.resolve(project.getFileName()).toFile().exists();
}).collect(Collectors.toList());
}
}

View File

@ -83,7 +83,7 @@
<#list notPublicProjects as project>
<div class="list-group-item">
<a href="${routes.getRouteUrl("projects.show", project.getNamespace().getOwner(), project.getNamespace().getSlug())}">
<strong>${project.namespace}</strong> <small><@spring.message "visibility.name." + project.visibility.name /></small>
<strong>${project.namespace}</strong> <small><@spring.message "visibility.name." + project.getVisibility().getName() /></small>
</a>
</div>
</#list>
@ -108,13 +108,13 @@
<h4 class="panel-title"><@spring.message "admin.health.missingFile" /></h4>
</div>
<div class="panel-body list-group list-group-health">
<#--@missingFileProjects.map { case (version, project) =>
<div class="list-group-item">
<a href="${routes.getRouteUrl("versions.show", project.ownerName, project.slug, version.name)}">
<strong>${project.namespace}/${version.name}</strong>
</a>
</div>
}--> <#--TODO missinFileProjects -->
<#list missingFileProjects as missingFileProject>
<div class="list-group-item">
<a href="${routes.getRouteUrl("versions.show", missingFileProject.owner, missingFileProject.name, missingFileProject.getVersion().getVersionString())}">
<strong>${missingFileProject.displayText}</strong>
</a>
</div>
</#list>
</div>
</div>
</div>