The backend for the project formerly known as signet, now known as beignet.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

escalateprivileges.go 1.0 KiB

2 years ago
1 year ago
2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. }