diff --git a/TO-PORT.md b/TO-PORT.md index 20e9e9a7b..5185fc9ef 100644 --- a/TO-PORT.md +++ b/TO-PORT.md @@ -29,7 +29,7 @@ * [ ] view ### Users -* [ ] admin\activity +* [x] admin\activity * [x] admin\flags * [ ] admin\health * [x] admin\log diff --git a/src/main/java/me/minidigger/hangar/controller/ApplicationController.java b/src/main/java/me/minidigger/hangar/controller/ApplicationController.java index 73ffcb484..1a4cb4e59 100644 --- a/src/main/java/me/minidigger/hangar/controller/ApplicationController.java +++ b/src/main/java/me/minidigger/hangar/controller/ApplicationController.java @@ -5,8 +5,14 @@ import me.minidigger.hangar.db.customtypes.LoggedActionType.ProjectContext; import me.minidigger.hangar.model.NamedPermission; import me.minidigger.hangar.model.Permission; import me.minidigger.hangar.model.Visibility; +import me.minidigger.hangar.model.generated.ProjectNamespace; +import me.minidigger.hangar.model.generated.Version; +import me.minidigger.hangar.model.viewhelpers.Activity; +import me.minidigger.hangar.model.viewhelpers.FlagActivity; import me.minidigger.hangar.model.viewhelpers.LoggedActionViewModel; import me.minidigger.hangar.model.viewhelpers.ProjectFlag; +import me.minidigger.hangar.model.viewhelpers.Review; +import me.minidigger.hangar.model.viewhelpers.ReviewActivity; import me.minidigger.hangar.model.viewhelpers.ReviewQueueEntry; import me.minidigger.hangar.model.viewhelpers.UnhealthyProject; import me.minidigger.hangar.model.viewhelpers.UserData; @@ -34,6 +40,7 @@ import org.springframework.web.server.ResponseStatusException; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; +import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -75,7 +82,19 @@ public class ApplicationController extends HangarController { @Secured("ROLE_USER") @GetMapping("/admin/activities/{user}") public ModelAndView showActivities(@PathVariable String user) { - return null; // TODO implement + ModelAndView mv = new ModelAndView("users/admin/activity"); + mv.addObject("username", user); + + List activities = new ArrayList<>(); + activities.addAll(userService.getFlagActivity(user)); + activities.addAll(userService.getRewiewActivity(user)); + + activities.add(new ReviewActivity(OffsetDateTime.now(), + new Review(new Version(), 1L, OffsetDateTime.now(), "suks"), new ProjectNamespace().owner("Kneny").slug("Swags"))); + activities.add(new FlagActivity(OffsetDateTime.now(), new ProjectNamespace().owner("Kneny").slug("Swags"))); + + mv.addObject("activities", activities); + return mv; } @GlobalPermission(NamedPermission.REVIEWER) diff --git a/src/main/java/me/minidigger/hangar/db/dao/UserDao.java b/src/main/java/me/minidigger/hangar/db/dao/UserDao.java index 70a5d2170..a8f3f6a9d 100644 --- a/src/main/java/me/minidigger/hangar/db/dao/UserDao.java +++ b/src/main/java/me/minidigger/hangar/db/dao/UserDao.java @@ -1,5 +1,7 @@ package me.minidigger.hangar.db.dao; +import me.minidigger.hangar.model.viewhelpers.FlagActivity; +import me.minidigger.hangar.model.viewhelpers.ReviewActivity; import org.jdbi.v3.sqlobject.config.RegisterBeanMapper; import org.jdbi.v3.sqlobject.customizer.BindBean; import org.jdbi.v3.sqlobject.customizer.Define; @@ -100,4 +102,24 @@ public interface UserDao { @SqlUpdate("DELETE FROM project_stars WHERE project_id = :projectId AND user_id = :userId") void removeStargazing(long projectId, long userId); + + + @SqlQuery("SELECT pvr.ended_at, pvr.id, p.owner_name, p.slug" + + " FROM users u" + + " JOIN project_version_reviews pvr ON u.id = pvr.user_id" + + " JOIN project_versions pv ON pvr.version_id = pv.id" + + " JOIN projects p ON pv.project_id = p.id" + + " WHERE u.name = :username" + + " LIMIT 20") + @RegisterBeanMapper(ReviewActivity.class) + List getReviewActivity(String username); + + @SqlQuery("SELECT pf.resolved_at, p.owner_name, p.slug" + + " FROM users u" + + " JOIN project_flags pf ON u.id = pf.user_id" + + " JOIN projects p ON pf.project_id = p.id" + + " WHERE u.name = :username" + + " LIMIT 20") + @RegisterBeanMapper(FlagActivity.class) + List getFlagActivity(String username); } diff --git a/src/main/java/me/minidigger/hangar/model/viewhelpers/Activity.java b/src/main/java/me/minidigger/hangar/model/viewhelpers/Activity.java new file mode 100644 index 000000000..35d0fe319 --- /dev/null +++ b/src/main/java/me/minidigger/hangar/model/viewhelpers/Activity.java @@ -0,0 +1,16 @@ +package me.minidigger.hangar.model.viewhelpers; + +import me.minidigger.hangar.model.generated.ProjectNamespace; + +public abstract class Activity { + + private ProjectNamespace project; + + protected Activity(ProjectNamespace project) { + this.project = project; + } + + public ProjectNamespace getProject() { + return project; + } +} diff --git a/src/main/java/me/minidigger/hangar/model/viewhelpers/FlagActivity.java b/src/main/java/me/minidigger/hangar/model/viewhelpers/FlagActivity.java new file mode 100644 index 000000000..c86a71f90 --- /dev/null +++ b/src/main/java/me/minidigger/hangar/model/viewhelpers/FlagActivity.java @@ -0,0 +1,19 @@ +package me.minidigger.hangar.model.viewhelpers; + +import me.minidigger.hangar.model.generated.ProjectNamespace; + +import java.time.OffsetDateTime; + +public class FlagActivity extends Activity { + + private OffsetDateTime resolvedAt; + + public FlagActivity(OffsetDateTime resolvedAt, ProjectNamespace project) { + super(project); + this.resolvedAt = resolvedAt; + } + + public OffsetDateTime getResolvedAt() { + return resolvedAt; + } +} diff --git a/src/main/java/me/minidigger/hangar/model/viewhelpers/Review.java b/src/main/java/me/minidigger/hangar/model/viewhelpers/Review.java new file mode 100644 index 000000000..935fb7d6d --- /dev/null +++ b/src/main/java/me/minidigger/hangar/model/viewhelpers/Review.java @@ -0,0 +1,36 @@ +package me.minidigger.hangar.model.viewhelpers; + +import me.minidigger.hangar.model.generated.Version; + +import java.time.OffsetDateTime; + +public class Review { + + private Version version; + private long userId; + private OffsetDateTime endedAt; + private String message; + + public Review(Version version, long userId, OffsetDateTime endedAt, String message) { + this.version = version; + this.userId = userId; + this.endedAt = endedAt; + this.message = message; + } + + public Version getVersion() { + return version; + } + + public long getUserId() { + return userId; + } + + public OffsetDateTime getEndedAt() { + return endedAt; + } + + public String getMessage() { + return message; + } +} diff --git a/src/main/java/me/minidigger/hangar/model/viewhelpers/ReviewActivity.java b/src/main/java/me/minidigger/hangar/model/viewhelpers/ReviewActivity.java new file mode 100644 index 000000000..605114f7d --- /dev/null +++ b/src/main/java/me/minidigger/hangar/model/viewhelpers/ReviewActivity.java @@ -0,0 +1,25 @@ +package me.minidigger.hangar.model.viewhelpers; + +import me.minidigger.hangar.model.generated.ProjectNamespace; + +import java.time.OffsetDateTime; + +public class ReviewActivity extends Activity { + + private OffsetDateTime endedAt; + private Review id; + + public ReviewActivity(OffsetDateTime endedAt, Review id, ProjectNamespace project) { + super(project); + this.endedAt = endedAt; + this.id = id; + } + + public OffsetDateTime getEndedAt() { + return endedAt; + } + + public Review getId() { + return id; + } +} diff --git a/src/main/java/me/minidigger/hangar/service/UserService.java b/src/main/java/me/minidigger/hangar/service/UserService.java index 48d7d4f3f..5058d8a85 100644 --- a/src/main/java/me/minidigger/hangar/service/UserService.java +++ b/src/main/java/me/minidigger/hangar/service/UserService.java @@ -1,5 +1,7 @@ package me.minidigger.hangar.service; +import me.minidigger.hangar.model.viewhelpers.FlagActivity; +import me.minidigger.hangar.model.viewhelpers.ReviewActivity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; @@ -198,4 +200,12 @@ public class UserService { } } } + + public List getRewiewActivity(String username) { + return userDao.get().getReviewActivity(username); + } + + public List getFlagActivity(String username) { + return userDao.get().getFlagActivity(username); + } } diff --git a/src/main/resources/templates/users/admin/activity.ftlh b/src/main/resources/templates/users/admin/activity.ftlh index 6df991cb3..7957d70d1 100644 --- a/src/main/resources/templates/users/admin/activity.ftlh +++ b/src/main/resources/templates/users/admin/activity.ftlh @@ -2,16 +2,6 @@ <#import "*/utils/hangar.ftlh" as hangar /> <#import "*/layout/base.ftlh" as base /> -<#-- -@import java.time.OffsetDateTime - -@import controllers.sugar.Requests.OreRequest -@import models.querymodels.{FlagActivity, ReviewActivity} -@import ore.OreConfig -@import util.StringFormatterUtils._ -@(username: String, activities: Seq[Either[FlagActivity, ReviewActivity]])(implicit messages: Messages, request: OreRequest[_], config: OreConfig, flash: Flash, assetsFinder: AssetsFinder) ---> - <#assign message><@spring.message "activity.title" /> <@base.base title=("${message} ${username}")> @@ -31,33 +21,33 @@ - <#if activities.isEmpty> + <#if !activities?has_content> - @activities.map { - case Right(review) => { + <#assign OffsetDateTime=@helper["java.time.OffsetDateTime"]> + <#list activities as activity> + <#if activity.class.simpleName == "ReviewActivity"> - + - } - case Left(flag) => { + <#elseif activity.class.simpleName = "FlagActivity"> - + - } - } + +
No activities founds
Review approved${(review.endedAt!OffsetDateTime.MIN)?string.long}${(activity.endedAt!OffsetDateTime.MIN).format("yyyy-MM-dd HH:mm:ss")} for: - - ${review.project.ownerName} / ${review.project.slug} + + ${activity.getProject().getOwner()} / ${activity.getProject().getSlug()}
Flag resolved${(flag.resolvedAt!OffsetDateTime.MIN)?string.long}${(activity.resolvedAt!OffsetDateTime.MIN).format("yyyy-MM-dd HH:mm:ss")} for: - - ${flag.project.ownerName} / ${flag.project.slug} + + ${activity.getProject().getOwner()} / ${activity.getProject().getSlug()}