Don't perform repo trigger if submission is closed
This commit is contained in:
parent
0b16676929
commit
0042d373f6
2 changed files with 34 additions and 4 deletions
|
@ -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
|
||||
|
|
Reference in a new issue