Don't perform repo trigger if submission is closed

This commit is contained in:
nemunaire 2022-09-05 05:13:30 +02:00
parent 0b16676929
commit 0042d373f6
2 changed files with 34 additions and 4 deletions

View File

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

View File

@ -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});
})
}
</script>
{#await repo_work}
@ -75,8 +87,8 @@
{#if state.status == "pending" || state.status == "running"}
<div
class="spinner-grow spinner-grow-sm mx-1"
class:text-secondary={state.status == "pending"}
class:text-warning={state.status == "running"}
class:text-primary={state.status == "pending"}
class:text-warning={state.status == "running"}
title="La récupération est en cours"
role="status"
></div>
@ -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
</button>