From 0042d373f61b8701aee77c044636fe0c3ccf4e6c Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Mon, 5 Sep 2022 05:13:30 +0200 Subject: [PATCH] Don't perform repo trigger if submission is closed --- repositories.go | 18 ++++++++++++++++++ ui/src/components/WorkRepository.svelte | 20 ++++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/repositories.go b/repositories.go index 44e5a74..66ac19a 100644 --- a/repositories.go +++ b/repositories.go @@ -129,6 +129,19 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) { }) repositoriesRoutes.DELETE("", func(c *gin.Context) { repository := c.MustGet("repository").(*Repository) + work, err := getWork(int(repository.IdWork)) + if err != nil { + c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to find related work."}) + return + + } + + now := time.Now() + + if !work.Shown || work.Corrected || work.StartAvailability.After(now) || work.EndAvailability.Before(now) { + c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"errmsg": "The submission is closed."}) + return + } if _, err := repository.Delete(); err != nil { log.Println("Unable to Delete repository:", err) @@ -156,6 +169,11 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) { now := time.Now() + if !work.Shown || work.Corrected || work.StartAvailability.After(now) || work.EndAvailability.Add(time.Hour).Before(now) { + c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"errmsg": "The submission is closed."}) + return + } + if repo.LastCheck != nil && !repo.LastCheck.Before(now.Add(-5*time.Minute)) { c.AbortWithStatusJSON(http.StatusPaymentRequired, gin.H{"errmsg": "Please wait between two pulls."}) return diff --git a/ui/src/components/WorkRepository.svelte b/ui/src/components/WorkRepository.svelte index 35fa7a1..59bce09 100644 --- a/ui/src/components/WorkRepository.svelte +++ b/ui/src/components/WorkRepository.svelte @@ -17,9 +17,10 @@ function updatePullState(repo) { repo_pull_state = repo.getBuildState(); + show_logs = null; repo_pull_state.then((state) => { if (state.status == "pending" || state.status == "running") { - setTimeout(() => updatePullState(repo), state.status == "pending" ? 1000 : 2500); + setTimeout(() => updatePullState(repo), state.status == "pending" ? 1000 : 3000); } }) } @@ -53,6 +54,17 @@ }); }); } + + function goRetrieveWork(repo) { + submitInProgress = true; + repo.retrieveWork().then(() => { + submitInProgress = false; + refresh_repo_work(); + }, (error) => { + submitInProgress = false; + ToastsStore.addErrorToast({msg: "Une erreur s'est produite : " + error}); + }) + } {#await repo_work} @@ -75,8 +87,8 @@ {#if state.status == "pending" || state.status == "running"}
@@ -96,7 +108,7 @@ type="button" class="btn btn-outline-info float-end mb-1" disable={submitInProgress || readonly} - on:click={() => repo.retrieveWork().then(() => { refresh_repo_work() }, (error) => ToastsStore.addErrorToast({msg: "Une erreur s'est produite : " + error}))} + on:click={() => goRetrieveWork(repo)} > Récupérer mon travail