...

Source file src/github.com/google/go-github/v33/github/users_administration.go

Documentation: github.com/google/go-github/v33/github

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

View as plain text