| 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 |
|
| 6 |
package github |
| 7 |
|
| 8 |
import ( |
| 9 |
"context" |
| 10 |
"fmt" |
| 11 |
) |
| 12 |
|
| 13 |
// PromoteSiteAdmin promotes a user to a site administrator of a GitHub Enterprise instance. |
| 14 |
// |
| 15 |
// GitHub API docs: https://docs.github.com/[email protected]/rest/enterprise-admin/users#promote-a-user-to-be-a-site-administrator |
| 16 |
// |
| 17 |
//meta:operation PUT /users/{username}/site_admin |
| 18 |
func (s *UsersService) PromoteSiteAdmin(ctx context.Context, user string) (*Response, error) { |
| 19 |
u := fmt.Sprintf("users/%v/site_admin", user) |
| 20 |
|
| 21 |
req, err := s.client.NewRequest("PUT", u, nil) |
| 22 |
if err != nil { |
| 23 |
return nil, err |
| 24 |
} |
| 25 |
|
| 26 |
return s.client.Do(ctx, req, nil) |
| 27 |
} |
| 28 |
|
| 29 |
// DemoteSiteAdmin demotes a user from site administrator of a GitHub Enterprise instance. |
| 30 |
// |
| 31 |
// GitHub API docs: https://docs.github.com/[email protected]/rest/enterprise-admin/users#demote-a-site-administrator |
| 32 |
// |
| 33 |
//meta:operation DELETE /users/{username}/site_admin |
| 34 |
func (s *UsersService) DemoteSiteAdmin(ctx context.Context, user string) (*Response, error) { |
| 35 |
u := fmt.Sprintf("users/%v/site_admin", user) |
| 36 |
|
| 37 |
req, err := s.client.NewRequest("DELETE", u, nil) |
| 38 |
if err != nil { |
| 39 |
return nil, err |
| 40 |
} |
| 41 |
|
| 42 |
return s.client.Do(ctx, req, nil) |
| 43 |
} |
| 44 |
|
| 45 |
// UserSuspendOptions represents the reason a user is being suspended. |
| 46 |
type UserSuspendOptions struct { |
| 47 |
Reason *string `json:"reason,omitempty"` |
| 48 |
} |
| 49 |
|
| 50 |
// Suspend a user on a GitHub Enterprise instance. |
| 51 |
// |
| 52 |
// GitHub API docs: https://docs.github.com/[email protected]/rest/enterprise-admin/users#suspend-a-user |
| 53 |
// |
| 54 |
//meta:operation PUT /users/{username}/suspended |
| 55 |
func (s *UsersService) Suspend(ctx context.Context, user string, opts *UserSuspendOptions) (*Response, error) { |
| 56 |
u := fmt.Sprintf("users/%v/suspended", user) |
| 57 |
|
| 58 |
req, err := s.client.NewRequest("PUT", u, opts) |
| 59 |
if err != nil { |
| 60 |
return nil, err |
| 61 |
} |
| 62 |
|
| 63 |
return s.client.Do(ctx, req, nil) |
| 64 |
} |
| 65 |
|
| 66 |
// Unsuspend a user on a GitHub Enterprise instance. |
| 67 |
// |
| 68 |
// GitHub API docs: https://docs.github.com/[email protected]/rest/enterprise-admin/users#unsuspend-a-user |
| 69 |
// |
| 70 |
//meta:operation DELETE /users/{username}/suspended |
| 71 |
func (s *UsersService) Unsuspend(ctx context.Context, user string) (*Response, error) { |
| 72 |
u := fmt.Sprintf("users/%v/suspended", user) |
| 73 |
|
| 74 |
req, err := s.client.NewRequest("DELETE", u, nil) |
| 75 |
if err != nil { |
| 76 |
return nil, err |
| 77 |
} |
| 78 |
|
| 79 |
return s.client.Do(ctx, req, nil) |
| 80 |
} |