github.com/quickfeed/quickfeed@v0.0.0-20240507093252-ed8ca812a09c/web/interceptor/util.go (about)

     1  package interceptor
     2  
     3  import (
     4  	"github.com/quickfeed/quickfeed/database"
     5  	"github.com/quickfeed/quickfeed/qf"
     6  )
     7  
     8  // isValidSubmission returns true if the student or group submitting the original push event
     9  // has an active course enrollment in the given course.
    10  func isValidSubmission(db database.Database, req requestID) bool {
    11  	courseID := req.IDFor("course")
    12  	submissionID := req.IDFor("submission")
    13  	sbm, err := db.GetSubmission(&qf.Submission{ID: submissionID})
    14  	if err != nil {
    15  		return false
    16  	}
    17  
    18  	if sbm.GroupID > 0 {
    19  		grp, err := db.GetGroup(sbm.GroupID)
    20  		if err != nil || grp.GetCourseID() != courseID {
    21  			return false
    22  		}
    23  		return true
    24  	}
    25  
    26  	enrol, err := db.GetEnrollmentByCourseAndUser(courseID, sbm.UserID)
    27  	if err != nil || enrol.IsNone() || enrol.IsPending() {
    28  		return false
    29  	}
    30  	return true
    31  }