MCPcopy
hub / github.com/semaphoreui/semaphore / setOption

Function setOption

api/options.go:10–34  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

8)
9
10func setOption(w http.ResponseWriter, r *http.Request) {
11 currentUser := helpers.GetFromContext(r, "user").(*db.User)
12
13 if !currentUser.Admin {
14 helpers.WriteJSON(w, http.StatusForbidden, map[string]string{
15 "error": "User must be admin",
16 })
17 return
18 }
19
20 var option db.Option
21 if !helpers.Bind(w, r, &option) {
22 return
23 }
24
25 err := helpers.Store(r).SetOption(option.Key, option.Value)
26 if err != nil {
27 helpers.WriteJSON(w, http.StatusInternalServerError, map[string]string{
28 "error": "Can not set option",
29 })
30 return
31 }
32
33 helpers.WriteJSON(w, http.StatusOK, option)
34}
35
36func getOptions(w http.ResponseWriter, r *http.Request) {
37 currentUser := helpers.GetFromContext(r, "user").(*db.User)

Callers

nothing calls this directly

Calls 5

GetFromContextFunction · 0.92
WriteJSONFunction · 0.92
BindFunction · 0.92
StoreFunction · 0.92
SetOptionMethod · 0.65

Tested by

no test coverage detected