mirror of
https://github.com/HangarMC/Hangar.git
synced 2024-12-15 06:41:46 +08:00
User activity page
This commit is contained in:
parent
736c14e506
commit
8fa6f5542a
@ -29,7 +29,7 @@
|
||||
* [ ] view
|
||||
|
||||
### Users
|
||||
* [ ] admin\activity
|
||||
* [x] admin\activity
|
||||
* [x] admin\flags
|
||||
* [ ] admin\health
|
||||
* [x] admin\log
|
||||
|
@ -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<Activity> 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)
|
||||
|
@ -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<ReviewActivity> 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<FlagActivity> getFlagActivity(String username);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<ReviewActivity> getRewiewActivity(String username) {
|
||||
return userDao.get().getReviewActivity(username);
|
||||
}
|
||||
|
||||
public List<FlagActivity> getFlagActivity(String username) {
|
||||
return userDao.get().getFlagActivity(username);
|
||||
}
|
||||
}
|
||||
|
@ -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" /></#assign>
|
||||
<@base.base title=("${message} ${username}")>
|
||||
|
||||
@ -31,33 +21,33 @@
|
||||
</div>
|
||||
<table class="table table-condensed setting-no-border table-review-log">
|
||||
<tbody>
|
||||
<#if activities.isEmpty>
|
||||
<#if !activities?has_content>
|
||||
<tr><td>No activities founds</td></tr>
|
||||
</#if>
|
||||
@activities.map {
|
||||
case Right(review) => {
|
||||
<#assign OffsetDateTime=@helper["java.time.OffsetDateTime"]>
|
||||
<#list activities as activity>
|
||||
<#if activity.class.simpleName == "ReviewActivity">
|
||||
<tr>
|
||||
<td>Review approved</td>
|
||||
<td>${(review.endedAt!OffsetDateTime.MIN)?string.long}</td>
|
||||
<td>${(activity.endedAt!OffsetDateTime.MIN).format("yyyy-MM-dd HH:mm:ss")}</td>
|
||||
<td>for:
|
||||
<a href="${routes.getRouteUrl("reviews.showReviews", review.project.ownerName, review.project.slug, review.id.toString)}">
|
||||
${review.project.ownerName} / ${review.project.slug}
|
||||
<a href="${routes.getRouteUrl("reviews.showReviews", activity.getProject().getOwner(), activity.getProject().getSlug(), activity.id)}">
|
||||
${activity.getProject().getOwner()} / ${activity.getProject().getSlug()}
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
case Left(flag) => {
|
||||
<#elseif activity.class.simpleName = "FlagActivity">
|
||||
<tr>
|
||||
<td>Flag resolved</td>
|
||||
<td>${(flag.resolvedAt!OffsetDateTime.MIN)?string.long}</td>
|
||||
<td>${(activity.resolvedAt!OffsetDateTime.MIN).format("yyyy-MM-dd HH:mm:ss")}</td>
|
||||
<td>for:
|
||||
<a href="${routes.getRouteUrl("projects.show", flag.project.ownerName, flag.project.slug)}">
|
||||
${flag.project.ownerName} / ${flag.project.slug}
|
||||
<a href="${routes.getRouteUrl("projects.show", activity.getProject().getSlug(), activity.getProject().getSlug())}">
|
||||
${activity.getProject().getOwner()} / ${activity.getProject().getSlug()}
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
</#if>
|
||||
</#list>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user