mirror of
https://github.com/HangarMC/Hangar.git
synced 2024-11-27 06:01:08 +08:00
fix a few things
This commit is contained in:
parent
fb4990e8ce
commit
b07d78f059
@ -1,8 +1,14 @@
|
|||||||
package io.papermc.hangar.controller.internal;
|
package io.papermc.hangar.controller.internal;
|
||||||
|
|
||||||
|
import io.papermc.hangar.controller.HangarController;
|
||||||
|
import io.papermc.hangar.model.api.requests.FlagForm;
|
||||||
|
import io.papermc.hangar.model.common.NamedPermission;
|
||||||
|
import io.papermc.hangar.model.internal.projects.HangarProjectFlag;
|
||||||
|
import io.papermc.hangar.security.annotations.LoggedIn;
|
||||||
|
import io.papermc.hangar.security.annotations.permission.PermissionRequired;
|
||||||
|
import io.papermc.hangar.service.internal.admin.FlagService;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.security.access.annotation.Secured;
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
@ -14,14 +20,9 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.papermc.hangar.controller.HangarController;
|
@LoggedIn
|
||||||
import io.papermc.hangar.controllerold.forms.FlagForm;
|
|
||||||
import io.papermc.hangar.model.internal.projects.HangarProjectFlag;
|
|
||||||
import io.papermc.hangar.service.internal.admin.FlagService;
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@Secured("ROLE_USER")
|
@RequestMapping("/api/internal/flags")
|
||||||
@RequestMapping(path = "/api/internal/flags", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
public class FlagController extends HangarController {
|
public class FlagController extends HangarController {
|
||||||
|
|
||||||
private final FlagService flagService;
|
private final FlagService flagService;
|
||||||
@ -30,26 +31,29 @@ public class FlagController extends HangarController {
|
|||||||
this.flagService = flagService;
|
this.flagService = flagService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/")
|
|
||||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||||
|
@PostMapping(value = "/", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||||
public void flag(@RequestBody FlagForm form) {
|
public void flag(@RequestBody FlagForm form) {
|
||||||
flagService.createFlag(form.getProjectId(), form.getReason(), form.getComment());
|
flagService.createFlag(form.getProjectId(), form.getReason(), form.getComment());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/resolve/{resolve}")
|
|
||||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||||
public void resolve(@PathVariable("id") long id, @PathVariable("resolve") boolean resolve) {
|
@PostMapping("/{id}/resolve/{resolve}")
|
||||||
|
@PermissionRequired(perms = NamedPermission.MOD_NOTES_AND_FLAGS)
|
||||||
|
public void resolve(@PathVariable long id, @PathVariable boolean resolve) {
|
||||||
flagService.markAsResolved(id, resolve);
|
flagService.markAsResolved(id, resolve);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@GetMapping("/{author}/{slug}")
|
@GetMapping(value = "/{author}/{slug}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
public List<HangarProjectFlag> getFlags(@PathVariable("author") String author, @PathVariable("slug") String slug) {
|
@PermissionRequired(perms = NamedPermission.MOD_NOTES_AND_FLAGS)
|
||||||
|
public List<HangarProjectFlag> getFlags(@PathVariable String author, @PathVariable String slug) {
|
||||||
return flagService.getFlags(author, slug);
|
return flagService.getFlags(author, slug);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@GetMapping("/")
|
@GetMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
@PermissionRequired(perms = NamedPermission.MOD_NOTES_AND_FLAGS)
|
||||||
public List<HangarProjectFlag> getFlags() {
|
public List<HangarProjectFlag> getFlags() {
|
||||||
return flagService.getFlags();
|
return flagService.getFlags();
|
||||||
}
|
}
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
package io.papermc.hangar.controllerold.forms;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.StringJoiner;
|
|
||||||
|
|
||||||
import io.papermc.hangar.model.common.projects.FlagReason;
|
|
||||||
|
|
||||||
public class FlagForm {
|
|
||||||
private final String comment;
|
|
||||||
private final long projectId;
|
|
||||||
private final FlagReason reason;
|
|
||||||
|
|
||||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
|
||||||
public FlagForm(@JsonProperty(value = "comment", required = true) @NotNull String comment,
|
|
||||||
@JsonProperty(value = "project_id", required = true) long projectId,
|
|
||||||
@JsonProperty(value = "reason", required = true) @NotNull FlagReason reason) {
|
|
||||||
this.comment = comment;
|
|
||||||
this.projectId = projectId;
|
|
||||||
this.reason = reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getComment() {
|
|
||||||
return comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getProjectId() {
|
|
||||||
return projectId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FlagReason getReason() {
|
|
||||||
return reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return new StringJoiner(", ", FlagForm.class.getSimpleName() + "[", "]")
|
|
||||||
.add("comment='" + comment + "'")
|
|
||||||
.add("projectId=" + projectId)
|
|
||||||
.add("reason=" + reason)
|
|
||||||
.toString();
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,43 @@
|
|||||||
|
package io.papermc.hangar.model.api.requests;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import io.papermc.hangar.model.common.projects.FlagReason;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
public class FlagForm {
|
||||||
|
@NotBlank
|
||||||
|
private final String comment;
|
||||||
|
private final long projectId;
|
||||||
|
@NotNull
|
||||||
|
private final FlagReason reason;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public FlagForm(String comment, long projectId, FlagReason reason) {
|
||||||
|
this.comment = comment;
|
||||||
|
this.projectId = projectId;
|
||||||
|
this.reason = reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getComment() {
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getProjectId() {
|
||||||
|
return projectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FlagReason getReason() {
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "FlagForm{" +
|
||||||
|
"comment='" + comment + '\'' +
|
||||||
|
", projectId=" + projectId +
|
||||||
|
", reason=" + reason +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
@ -83,7 +83,7 @@ public class ProjectFlagTable extends Table {
|
|||||||
"projectId=" + projectId +
|
"projectId=" + projectId +
|
||||||
", userId=" + userId +
|
", userId=" + userId +
|
||||||
", reason=" + reason +
|
", reason=" + reason +
|
||||||
", isResolved=" + resolved +
|
", resolved=" + resolved +
|
||||||
", comment='" + comment + '\'' +
|
", comment='" + comment + '\'' +
|
||||||
", resolvedAt=" + resolvedAt +
|
", resolvedAt=" + resolvedAt +
|
||||||
", resolvedBy=" + resolvedBy +
|
", resolvedBy=" + resolvedBy +
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
package io.papermc.hangar.service.internal.admin;
|
package io.papermc.hangar.service.internal.admin;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import io.papermc.hangar.db.dao.HangarDao;
|
import io.papermc.hangar.db.dao.HangarDao;
|
||||||
import io.papermc.hangar.db.dao.internal.HangarFlagsDAO;
|
import io.papermc.hangar.db.dao.internal.HangarFlagsDAO;
|
||||||
import io.papermc.hangar.model.common.projects.FlagReason;
|
import io.papermc.hangar.model.common.projects.FlagReason;
|
||||||
import io.papermc.hangar.model.db.projects.ProjectFlagTable;
|
import io.papermc.hangar.model.db.projects.ProjectFlagTable;
|
||||||
import io.papermc.hangar.model.internal.projects.HangarProjectFlag;
|
import io.papermc.hangar.model.internal.projects.HangarProjectFlag;
|
||||||
import io.papermc.hangar.service.HangarService;
|
import io.papermc.hangar.service.HangarService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class FlagService extends HangarService {
|
public class FlagService extends HangarService {
|
||||||
@ -23,12 +22,13 @@ public class FlagService extends HangarService {
|
|||||||
|
|
||||||
public void createFlag(long projectId, FlagReason reason, String comment) {
|
public void createFlag(long projectId, FlagReason reason, String comment) {
|
||||||
// TODO idk, we prolly need more checking here, plus notification? logs?
|
// TODO idk, we prolly need more checking here, plus notification? logs?
|
||||||
flagsDAO.insert(new ProjectFlagTable( projectId, getHangarUserId(), reason, comment));
|
flagsDAO.insert(new ProjectFlagTable( projectId, getHangarPrincipal().getId(), reason, comment));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectFlagTable markAsResolved(long flagId, boolean resolved) {
|
public ProjectFlagTable markAsResolved(long flagId, boolean resolved) {
|
||||||
|
Long resolvedBy = resolved ? getHangarPrincipal().getId() : null;
|
||||||
OffsetDateTime resolvedAt = resolved ? OffsetDateTime.now() : null;
|
OffsetDateTime resolvedAt = resolved ? OffsetDateTime.now() : null;
|
||||||
return flagsDAO.markAsResolved(flagId, resolved, getHangarUserId(), resolvedAt);
|
return flagsDAO.markAsResolved(flagId, resolved, resolvedBy, resolvedAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<HangarProjectFlag> getFlags(String author, String slug) {
|
public List<HangarProjectFlag> getFlags(String author, String slug) {
|
||||||
|
@ -101,7 +101,7 @@ public class ProjectService extends HangarService {
|
|||||||
if (Objects.equals(getHangarUserId(), userId)) {
|
if (Objects.equals(getHangarUserId(), userId)) {
|
||||||
return getHangarPrincipal();
|
return getHangarPrincipal();
|
||||||
}
|
}
|
||||||
return organizationService.getOrganizationTablesWithPermission(getHangarUserId(), Permission.CreateProject).stream().filter(ot -> ot.getUserId() == userId).findFirst().orElse(null);
|
return organizationService.getOrganizationTablesWithPermission(getHangarPrincipal().getId(), Permission.CreateProject).stream().filter(ot -> ot.getUserId() == userId).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectOwner getProjectOwner(String userName) {
|
public ProjectOwner getProjectOwner(String userName) {
|
||||||
|
Loading…
Reference in New Issue
Block a user