chore(deps): update module github.com/coreos/go-oidc to v3 - autoclosed #17
@ -51,6 +51,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-3 text-sm-end">
|
||||
<label for="group" class="col-form-label col-form-label-sm">Restreindre au groupe</label>
|
||||
</div>
|
||||
<div class="col-sm-8 col-md-4 col-lg-2">
|
||||
<input class="form-control form-control-sm" id="group" bind:value={survey.group}>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-3 text-sm-end">
|
||||
<label for="start_availability" class="col-form-label col-form-label-sm">Date de début</label>
|
||||
|
@ -8,10 +8,11 @@ class Survey {
|
||||
}
|
||||
}
|
||||
|
||||
update({ id, title, promo, shown, corrected, start_availability, end_availability }) {
|
||||
update({ id, title, promo, group, shown, corrected, start_availability, end_availability }) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.promo = promo;
|
||||
this.group = group;
|
||||
this.shown = shown;
|
||||
this.corrected = corrected;
|
||||
if (this.start_availability != start_availability) {
|
||||
|
34
surveys.go
34
surveys.go
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
@ -19,7 +20,19 @@ func init() {
|
||||
} else if u.IsAdmin {
|
||||
return formatApiResponse(getSurveys("ORDER BY promo DESC, start_availability ASC"))
|
||||
} else {
|
||||
return formatApiResponse(getSurveys(fmt.Sprintf("WHERE shown = TRUE AND promo = %d ORDER BY start_availability ASC", u.Promo)))
|
||||
surveys, err := getSurveys(fmt.Sprintf("WHERE shown = TRUE AND promo = %d ORDER BY start_availability ASC", u.Promo))
|
||||
if err != nil {
|
||||
return APIErrorResponse{err: err}
|
||||
}
|
||||
|
||||
var response []Survey
|
||||
for _, s := range surveys {
|
||||
if s.Group == "" || strings.Contains(u.Groups, ","+s.Group+",") {
|
||||
response = append(response, s)
|
||||
}
|
||||
}
|
||||
|
||||
return formatApiResponse(response, nil)
|
||||
}
|
||||
}))
|
||||
router.POST("/api/surveys", apiHandler(func(_ httprouter.Params, body []byte) HTTPResponse {
|
||||
@ -32,11 +45,11 @@ func init() {
|
||||
new.Promo = currentPromo
|
||||
}
|
||||
|
||||
return formatApiResponse(NewSurvey(new.Title, new.Promo, new.Shown, new.StartAvailability, new.EndAvailability))
|
||||
return formatApiResponse(NewSurvey(new.Title, new.Promo, new.Group, new.Shown, new.StartAvailability, new.EndAvailability))
|
||||
}, adminRestricted))
|
||||
router.GET("/api/surveys/:sid", apiAuthHandler(surveyAuthHandler(
|
||||
func(s Survey, u *User, _ []byte) HTTPResponse {
|
||||
if (s.Promo == u.Promo && s.Shown) || (u != nil && u.IsAdmin) {
|
||||
if (s.Promo == u.Promo && (s.Group == "" || (u != nil && strings.Contains(u.Groups, ","+s.Group+",")) && s.Shown)) || (u != nil && u.IsAdmin) {
|
||||
return APIResponse{s}
|
||||
} else {
|
||||
return APIErrorResponse{
|
||||
@ -125,6 +138,7 @@ type Survey struct {
|
||||
Id int64 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Promo uint `json:"promo"`
|
||||
Group string `json:"group"`
|
||||
Shown bool `json:"shown"`
|
||||
Corrected bool `json:"corrected"`
|
||||
StartAvailability time.Time `json:"start_availability"`
|
||||
@ -132,14 +146,14 @@ type Survey struct {
|
||||
}
|
||||
|
||||
func getSurveys(cnd string, param ...interface{}) (surveys []Survey, err error) {
|
||||
if rows, errr := DBQuery("SELECT id_survey, title, promo, shown, corrected, start_availability, end_availability FROM surveys "+cnd, param...); errr != nil {
|
||||
if rows, errr := DBQuery("SELECT id_survey, title, promo, grp, shown, corrected, start_availability, end_availability FROM surveys "+cnd, param...); errr != nil {
|
||||
return nil, errr
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var s Survey
|
||||
if err = rows.Scan(&s.Id, &s.Title, &s.Promo, &s.Shown, &s.Corrected, &s.StartAvailability, &s.EndAvailability); err != nil {
|
||||
if err = rows.Scan(&s.Id, &s.Title, &s.Promo, &s.Group, &s.Shown, &s.Corrected, &s.StartAvailability, &s.EndAvailability); err != nil {
|
||||
return
|
||||
}
|
||||
surveys = append(surveys, s)
|
||||
@ -153,17 +167,17 @@ func getSurveys(cnd string, param ...interface{}) (surveys []Survey, err error)
|
||||
}
|
||||
|
||||
func getSurvey(id int) (s Survey, err error) {
|
||||
err = DBQueryRow("SELECT id_survey, title, promo, shown, corrected, start_availability, end_availability FROM surveys WHERE id_survey=?", id).Scan(&s.Id, &s.Title, &s.Promo, &s.Shown, &s.Corrected, &s.StartAvailability, &s.EndAvailability)
|
||||
err = DBQueryRow("SELECT id_survey, title, promo, grp, shown, corrected, start_availability, end_availability FROM surveys WHERE id_survey=?", id).Scan(&s.Id, &s.Title, &s.Promo, &s.Group, &s.Shown, &s.Corrected, &s.StartAvailability, &s.EndAvailability)
|
||||
return
|
||||
}
|
||||
|
||||
func NewSurvey(title string, promo uint, shown bool, startAvailability time.Time, endAvailability time.Time) (*Survey, error) {
|
||||
if res, err := DBExec("INSERT INTO surveys (title, promo, shown, start_availability, end_availability) VALUES (?, ?, ?, ?, ?)", title, promo, shown, startAvailability, endAvailability); err != nil {
|
||||
func NewSurvey(title string, promo uint, group string, shown bool, startAvailability time.Time, endAvailability time.Time) (*Survey, error) {
|
||||
if res, err := DBExec("INSERT INTO surveys (title, promo, grp, shown, start_availability, end_availability) VALUES (?, ?, ?, ?, ?, ?)", title, promo, group, shown, startAvailability, endAvailability); err != nil {
|
||||
return nil, err
|
||||
} else if sid, err := res.LastInsertId(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return &Survey{sid, title, promo, shown, false, startAvailability, endAvailability}, nil
|
||||
return &Survey{sid, title, promo, group, shown, false, startAvailability, endAvailability}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,7 +215,7 @@ func (s Survey) GetScores() (scores map[int64]*float64, err error) {
|
||||
}
|
||||
|
||||
func (s *Survey) Update() (*Survey, error) {
|
||||
if _, err := DBExec("UPDATE surveys SET title = ?, promo = ?, shown = ?, corrected = ?, start_availability = ?, end_availability = ? WHERE id_survey = ?", s.Title, s.Promo, s.Shown, s.Corrected, s.StartAvailability, s.EndAvailability, s.Id); err != nil {
|
||||
if _, err := DBExec("UPDATE surveys SET title = ?, promo = ?, grp = ?, shown = ?, corrected = ?, start_availability = ?, end_availability = ? WHERE id_survey = ?", s.Title, s.Promo, s.Group, s.Shown, s.Corrected, s.StartAvailability, s.EndAvailability, s.Id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return s, err
|
||||
|
Reference in New Issue
Block a user