mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-12-03 14:51:05 +01:00
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package api
|
|
|
|
import (
|
|
"github.com/semaphoreui/semaphore/api/helpers"
|
|
"github.com/semaphoreui/semaphore/db"
|
|
"github.com/gorilla/context"
|
|
"net/http"
|
|
)
|
|
|
|
func setOption(w http.ResponseWriter, r *http.Request) {
|
|
currentUser := context.Get(r, "user").(*db.User)
|
|
|
|
if !currentUser.Admin {
|
|
helpers.WriteJSON(w, http.StatusForbidden, map[string]string{
|
|
"error": "User must be admin",
|
|
})
|
|
return
|
|
}
|
|
|
|
var option db.Option
|
|
if !helpers.Bind(w, r, &option) {
|
|
return
|
|
}
|
|
|
|
err := helpers.Store(r).SetOption(option.Key, option.Value)
|
|
if err != nil {
|
|
helpers.WriteJSON(w, http.StatusInternalServerError, map[string]string{
|
|
"error": "Can not set option",
|
|
})
|
|
return
|
|
}
|
|
|
|
helpers.WriteJSON(w, http.StatusOK, option)
|
|
}
|
|
|
|
func getOptions(w http.ResponseWriter, r *http.Request) {
|
|
currentUser := context.Get(r, "user").(*db.User)
|
|
|
|
if !currentUser.Admin {
|
|
helpers.WriteJSON(w, http.StatusForbidden, map[string]string{
|
|
"error": "User must be admin",
|
|
})
|
|
return
|
|
}
|
|
|
|
options, err := helpers.Store(r).GetOptions(db.RetrieveQueryParams{})
|
|
if err != nil {
|
|
helpers.WriteJSON(w, http.StatusInternalServerError, map[string]string{
|
|
"error": "Can not get options",
|
|
})
|
|
return
|
|
}
|
|
|
|
helpers.WriteJSON(w, http.StatusOK, options)
|
|
}
|