Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

#1277 Add functions for new api endpoints to approve and reject user #1280

Merged
merged 5 commits into from
Oct 26, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions users.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,64 @@ func (s *UsersService) UnblockUser(user int, options ...RequestOptionFunc) error
}
}

// ApproveUser approve the specified user. Available only for admin.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#approve-user
func (s *UsersService) ApproveUser(user int, options ...RequestOptionFunc) error {
u := fmt.Sprintf("users/%d/approve", user)

req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return err
}

resp, err := s.client.Do(req, nil)
if err != nil && resp == nil {
return err
}

switch resp.StatusCode {
case 201:
return nil
case 403:
return ErrUserApprovePrevented
case 404:
return ErrUserNotFound
default:
return fmt.Errorf("Received unexpected result code: %d", resp.StatusCode)
}
}

// RejectUser reject the specified user. Available only for admin.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#reject-user
func (s *UsersService) RejectUser(user int, options ...RequestOptionFunc) error {
u := fmt.Sprintf("users/%d/reject", user)

req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
if err != nil {
return err
}

resp, err := s.client.Do(req, nil)
if err != nil && resp == nil {
return err
}

switch resp.StatusCode {
case 201:
TheKas marked this conversation as resolved.
Show resolved Hide resolved
return nil
case 403:
return ErrUserRejectPrevented
case 404:
return ErrUserNotFound
case 409:
return ErrConflict
TheKas marked this conversation as resolved.
Show resolved Hide resolved
default:
return fmt.Errorf("Received unexpected result code: %d", resp.StatusCode)
}
}

// DeactivateUser deactivate the specified user. Available only for admin.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#deactivate-user
Expand Down