The backend for the project formerly known as signet, now known as beignet.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

51 linhas
1.0 KiB

  1. package endpoints
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "github.com/imosed/signet/auth"
  6. . "github.com/imosed/signet/data"
  7. )
  8. type EscalatePrivilegesRequest struct {
  9. Username string
  10. }
  11. func EscalatePrivileges(w http.ResponseWriter, r *http.Request) {
  12. var req EscalatePrivilegesRequest
  13. err := json.NewDecoder(r.Body).Decode(&req)
  14. if err != nil {
  15. panic("Could not decode body")
  16. }
  17. var resp SuccessResponse
  18. var user User
  19. var claims *auth.Claims
  20. claims, err = auth.GetUserClaims(r)
  21. if claims.Privileges == SuperUser {
  22. Db.Table("users").Where("username = ?", req.Username).Find(&user)
  23. if user.Privileges == SuperUser || user.Privileges == AdminPlus {
  24. resp.Success = false
  25. err = json.NewEncoder(w).Encode(resp)
  26. if err != nil {
  27. panic("Could not deliver failed escalate privileges response")
  28. }
  29. return
  30. }
  31. user.Privileges = AdminPlus
  32. resp.Success = true
  33. } else {
  34. resp.Success = false
  35. }
  36. err = json.NewEncoder(w).Encode(resp)
  37. if err != nil {
  38. panic("Could not deliver successful escalate privileges response")
  39. }
  40. }