Skip to content

Commit 5fd53ab

Browse files
committed
unsubmit command
1 parent eb59704 commit 5fd53ab

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed

botfest/src/main/kotlin/net/modfest/botfest/Platform.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ class PlatformAuthenticated(var client: HttpClient, var discordUser: Snowflake)
193193
}.unwrapErrors()
194194
}
195195

196+
suspend fun deleteSubmission(eventId: String, subId: String) {
197+
client.delete("/event/$eventId/submission/$subId") {
198+
addAuth()
199+
}.unwrapErrors()
200+
}
201+
196202
suspend fun editSubmissionImage(eventId: String, subId: String, type: String, url: String) {
197203
client.patch("/event/$eventId/submission/$subId/image/$type") {
198204
addAuth()

botfest/src/main/kotlin/net/modfest/botfest/extensions/SubmissionCommands.kt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,50 @@ class SubmissionCommands : Extension(), KordExKoinComponent {
294294
}
295295
}
296296

297+
// Delete submission data
298+
unsafeSubCommand(::SubmissionArg) {
299+
name = Translations.Commands.Submission.Delete.name
300+
description = Translations.Commands.Submission.Delete.description
301+
302+
initialResponse = InitialSlashCommandResponse.None
303+
304+
action {
305+
val subId = this.arguments.submission
306+
val curEvent = platform.getCurrentEvent().event
307+
if (curEvent == null) {
308+
ackEphemeral {
309+
content = Translations.Commands.Event.Submit.Response.unavailable
310+
.withContext(this@action)
311+
.translateNamed()
312+
}
313+
return@action
314+
}
315+
316+
val submission = platform.getUserSubmissions(this.user.id).find { it.id == subId }
317+
318+
if (submission == null) {
319+
ackEphemeral {
320+
content = Translations.Commands.Submission.Edit.Response.notfound
321+
.withContext(this@action)
322+
.translateNamed(
323+
"subId" to subId
324+
)
325+
}
326+
return@action
327+
}
328+
329+
platform.withAuth(this.user).deleteSubmission(curEvent, subId)
330+
331+
ackEphemeral {
332+
content = Translations.Commands.Submission.Edit.Response.success
333+
.withContext(this@action)
334+
.translateNamed(
335+
"subId" to subId
336+
)
337+
}
338+
}
339+
}
340+
297341
// Edit submissions images
298342
group(Translations.Commands.Submission.EditImage.label) {
299343
description = Translations.Commands.Submission.EditImage.description

botfest/src/main/resources/translations/botfest/strings.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ commands.submission.edit.name=edit
7777
commands.submission.edit.description=Edit your submission's data
7878
commands.submission.edit.response.notfound=Unknown submission {subId}
7979
commands.submission.edit.response.success=Successfully edited the data for {subId}
80+
commands.submission.delete.name=unsubmit
81+
commands.submission.delete.description=Withdraw your submission
82+
commands.submission.delete.response.notfound=Unknown submission {subId}
83+
commands.submission.delete.response.success=Successfully withdrew {subId}
8084
commands.submission.edit_image.label=images
8185
commands.submission.edit_image.description=Change your submission's images
8286
commands.submission.edit_image.icon.label=icon

platform_api/src/main/java/net/modfest/platform/controller/EventController.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,22 @@ public void editSubmissionImage(@PathVariable String eventId, @PathVariable Stri
183183
imageService.downloadSubmissionImage(url, new SubmissionRepository.SubmissionId(eventId, subId), typeEnum);
184184
}
185185

186+
@DeleteMapping("/event/{eventId}/submission/{subId}")
187+
public void deleteSubmission(@PathVariable String eventId, @PathVariable String subId) {
188+
getEvent(eventId);
189+
var submission = service.getSubmission(eventId, subId);
190+
if (submission == null) {
191+
throw new IllegalArgumentException();// TODO
192+
}
193+
194+
if (!canEdit(submission)) {
195+
throw new ResponseStatusException(HttpStatus.FORBIDDEN,
196+
"You do not have permissions to edit this data");
197+
}
198+
199+
service.deleteSubmission(eventId, subId);
200+
}
201+
186202
private boolean canEdit(SubmissionData submission) {
187203
var subject = SecurityUtils.getSubject();
188204
var can_others = subject.isPermitted(Permissions.Event.EDIT_OTHER_SUBMISSION);

platform_api/src/main/java/net/modfest/platform/service/SubmissionService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public void editSubmission(SubmissionData data, SubmissionPatchData edit) {
5656
submissionRepository.save(data);
5757
}
5858

59+
public void deleteSubmission(String eventId, String subId) {
60+
submissionRepository.delete(new SubmissionRepository.SubmissionId(eventId, subId));
61+
}
62+
5963
/**
6064
* Retrieve all submissions made by a user
6165
* @param filter If non-null, only submissions associated with that event will be returned

0 commit comments

Comments
 (0)