The backend for the project formerly known as signet, now known as beignet.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

escalateprivileges.go 1.2 KiB

pirms 2 gadiem
pirms 1 gada
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package endpoints
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "github.com/imosed/signet/auth"
  6. . "github.com/imosed/signet/data"
  7. "github.com/rs/zerolog/log"
  8. )
  9. type EscalatePrivilegesRequest struct {
  10. UserID uint `json:"userID"`
  11. Privileges uint `json:"privileges"`
  12. }
  13. func ChangePrivileges(w http.ResponseWriter, r *http.Request) {
  14. var req EscalatePrivilegesRequest
  15. err := json.NewDecoder(r.Body).Decode(&req)
  16. if err != nil {
  17. log.Error().Err(err).Msg("Could not decode body in ChangePrivileges call")
  18. return
  19. }
  20. var resp SuccessResponse
  21. var user User
  22. var claims *auth.Claims
  23. claims, err = auth.GetUserClaims(r)
  24. if claims != nil && claims.Privileges <= AdminPlus {
  25. Db.Table("users").Where("id = ?", req.UserID).Find(&user)
  26. if req.Privileges == SuperUser {
  27. resp.Success = false
  28. err = json.NewEncoder(w).Encode(resp)
  29. if err != nil {
  30. log.Error().Err(err).Msg("Could not deliver failed escalate privileges response")
  31. }
  32. return
  33. }
  34. user.Privileges = req.Privileges
  35. Db.Save(user)
  36. resp.Success = true
  37. } else {
  38. w.WriteHeader(403)
  39. return
  40. }
  41. err = json.NewEncoder(w).Encode(resp)
  42. if err != nil {
  43. log.Error().Err(err).Msg("Could not deliver successful escalate privileges response")
  44. }
  45. }