users_administration.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2014 The go-github AUTHORS. All rights reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style
  4. // license that can be found in the LICENSE file.
  5. package github
  6. import (
  7. "context"
  8. "fmt"
  9. )
  10. // PromoteSiteAdmin promotes a user to a site administrator of a GitHub Enterprise instance.
  11. //
  12. // GitHub API docs: https://developer.github.com/v3/users/administration/#promote-an-ordinary-user-to-a-site-administrator
  13. func (s *UsersService) PromoteSiteAdmin(ctx context.Context, user string) (*Response, error) {
  14. u := fmt.Sprintf("users/%v/site_admin", user)
  15. req, err := s.client.NewRequest("PUT", u, nil)
  16. if err != nil {
  17. return nil, err
  18. }
  19. return s.client.Do(ctx, req, nil)
  20. }
  21. // DemoteSiteAdmin demotes a user from site administrator of a GitHub Enterprise instance.
  22. //
  23. // GitHub API docs: https://developer.github.com/v3/users/administration/#demote-a-site-administrator-to-an-ordinary-user
  24. func (s *UsersService) DemoteSiteAdmin(ctx context.Context, user string) (*Response, error) {
  25. u := fmt.Sprintf("users/%v/site_admin", user)
  26. req, err := s.client.NewRequest("DELETE", u, nil)
  27. if err != nil {
  28. return nil, err
  29. }
  30. return s.client.Do(ctx, req, nil)
  31. }
  32. // Suspend a user on a GitHub Enterprise instance.
  33. //
  34. // GitHub API docs: https://developer.github.com/v3/users/administration/#suspend-a-user
  35. func (s *UsersService) Suspend(ctx context.Context, user string) (*Response, error) {
  36. u := fmt.Sprintf("users/%v/suspended", user)
  37. req, err := s.client.NewRequest("PUT", u, nil)
  38. if err != nil {
  39. return nil, err
  40. }
  41. return s.client.Do(ctx, req, nil)
  42. }
  43. // Unsuspend a user on a GitHub Enterprise instance.
  44. //
  45. // GitHub API docs: https://developer.github.com/v3/users/administration/#unsuspend-a-user
  46. func (s *UsersService) Unsuspend(ctx context.Context, user string) (*Response, error) {
  47. u := fmt.Sprintf("users/%v/suspended", user)
  48. req, err := s.client.NewRequest("DELETE", u, nil)
  49. if err != nil {
  50. return nil, err
  51. }
  52. return s.client.Do(ctx, req, nil)
  53. }