User activity page

This commit is contained in:
KennyTV 2020-08-05 17:12:08 +02:00
parent 736c14e506
commit 8fa6f5542a
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
9 changed files with 162 additions and 25 deletions

View File

@ -29,7 +29,7 @@
* [ ] view * [ ] view
### Users ### Users
* [ ] admin\activity * [x] admin\activity
* [x] admin\flags * [x] admin\flags
* [ ] admin\health * [ ] admin\health
* [x] admin\log * [x] admin\log

View File

@ -5,8 +5,14 @@ import me.minidigger.hangar.db.customtypes.LoggedActionType.ProjectContext;
import me.minidigger.hangar.model.NamedPermission; import me.minidigger.hangar.model.NamedPermission;
import me.minidigger.hangar.model.Permission; import me.minidigger.hangar.model.Permission;
import me.minidigger.hangar.model.Visibility; 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.LoggedActionViewModel;
import me.minidigger.hangar.model.viewhelpers.ProjectFlag; 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.ReviewQueueEntry;
import me.minidigger.hangar.model.viewhelpers.UnhealthyProject; import me.minidigger.hangar.model.viewhelpers.UnhealthyProject;
import me.minidigger.hangar.model.viewhelpers.UserData; import me.minidigger.hangar.model.viewhelpers.UserData;
@ -34,6 +40,7 @@ import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.time.OffsetDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -75,7 +82,19 @@ public class ApplicationController extends HangarController {
@Secured("ROLE_USER") @Secured("ROLE_USER")
@GetMapping("/admin/activities/{user}") @GetMapping("/admin/activities/{user}")
public ModelAndView showActivities(@PathVariable String 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) @GlobalPermission(NamedPermission.REVIEWER)

View File

@ -1,5 +1,7 @@
package me.minidigger.hangar.db.dao; 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.config.RegisterBeanMapper;
import org.jdbi.v3.sqlobject.customizer.BindBean; import org.jdbi.v3.sqlobject.customizer.BindBean;
import org.jdbi.v3.sqlobject.customizer.Define; 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") @SqlUpdate("DELETE FROM project_stars WHERE project_id = :projectId AND user_id = :userId")
void removeStargazing(long projectId, long 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);
} }

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -1,5 +1,7 @@
package me.minidigger.hangar.service; 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.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; 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);
}
} }

View File

@ -2,16 +2,6 @@
<#import "*/utils/hangar.ftlh" as hangar /> <#import "*/utils/hangar.ftlh" as hangar />
<#import "*/layout/base.ftlh" as base /> <#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> <#assign message><@spring.message "activity.title" /></#assign>
<@base.base title=("${message} ${username}")> <@base.base title=("${message} ${username}")>
@ -31,33 +21,33 @@
</div> </div>
<table class="table table-condensed setting-no-border table-review-log"> <table class="table table-condensed setting-no-border table-review-log">
<tbody> <tbody>
<#if activities.isEmpty> <#if !activities?has_content>
<tr><td>No activities founds</td></tr> <tr><td>No activities founds</td></tr>
</#if> </#if>
@activities.map { <#assign OffsetDateTime=@helper["java.time.OffsetDateTime"]>
case Right(review) => { <#list activities as activity>
<#if activity.class.simpleName == "ReviewActivity">
<tr> <tr>
<td>Review approved</td> <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: <td>for:
<a href="${routes.getRouteUrl("reviews.showReviews", review.project.ownerName, review.project.slug, review.id.toString)}"> <a href="${routes.getRouteUrl("reviews.showReviews", activity.getProject().getOwner(), activity.getProject().getSlug(), activity.id)}">
${review.project.ownerName} / ${review.project.slug} ${activity.getProject().getOwner()} / ${activity.getProject().getSlug()}
</a> </a>
</td> </td>
</tr> </tr>
} <#elseif activity.class.simpleName = "FlagActivity">
case Left(flag) => {
<tr> <tr>
<td>Flag resolved</td> <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: <td>for:
<a href="${routes.getRouteUrl("projects.show", flag.project.ownerName, flag.project.slug)}"> <a href="${routes.getRouteUrl("projects.show", activity.getProject().getSlug(), activity.getProject().getSlug())}">
${flag.project.ownerName} / ${flag.project.slug} ${activity.getProject().getOwner()} / ${activity.getProject().getSlug()}
</a> </a>
</td> </td>
</tr> </tr>
} </#if>
} </#list>
</tbody> </tbody>
</table> </table>
</div> </div>