Revert "Display survey mean to admin"
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This reverts commit d7f679ce8443de51f5f639283d2ff12cb3843374.
This commit is contained in:
parent
c21df9d93f
commit
1532ede587
28
surveys.go
28
surveys.go
@ -72,12 +72,11 @@ func declareAPIAuthSurveysRoutes(router *gin.RouterGroup) {
|
|||||||
surveysRoutes.Use(surveyUserAccessHandler)
|
surveysRoutes.Use(surveyUserAccessHandler)
|
||||||
|
|
||||||
surveysRoutes.GET("/score", func(c *gin.Context) {
|
surveysRoutes.GET("/score", func(c *gin.Context) {
|
||||||
loggedUser := c.MustGet("LoggedUser").(*User)
|
|
||||||
var u *User
|
var u *User
|
||||||
if user, ok := c.Get("user"); ok {
|
if user, ok := c.Get("user"); ok {
|
||||||
u = user.(*User)
|
u = user.(*User)
|
||||||
} else {
|
} else {
|
||||||
u = loggedUser
|
u = c.MustGet("LoggedUser").(*User)
|
||||||
}
|
}
|
||||||
s := c.MustGet("survey").(*Survey)
|
s := c.MustGet("survey").(*Survey)
|
||||||
|
|
||||||
@ -89,29 +88,10 @@ func declareAPIAuthSurveysRoutes(router *gin.RouterGroup) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if score != nil {
|
if score == nil {
|
||||||
c.JSON(http.StatusOK, map[string]float64{"score": *score})
|
|
||||||
} else if _, ok := c.Get("user"); !ok && loggedUser.IsAdmin {
|
|
||||||
// Admin retrieve mean score
|
|
||||||
scores, err := s.GetGrades()
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Unable to GetGrades(sid=%d): %s", s.Id, err.Error())
|
|
||||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs when trying to retrieve grades."})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
*score = 0
|
|
||||||
nbGrades := 0
|
|
||||||
for _, s := range scores {
|
|
||||||
*score += *s
|
|
||||||
nbGrades += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
*score /= float64(nbGrades)
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, map[string]float64{"score": *score})
|
|
||||||
} else {
|
|
||||||
c.JSON(http.StatusOK, map[string]string{"score": "N/A"})
|
c.JSON(http.StatusOK, map[string]string{"score": "N/A"})
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, map[string]float64{"score": *score})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"errmsg": "Not accessible"})
|
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"errmsg": "Not accessible"})
|
||||||
|
Reference in New Issue
Block a user