Commit d305a133 authored by Peter Mikula's avatar Peter Mikula Committed by Peter Mikula

calls to (un)block return just the error

parent 9df38fea
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package gitlab package gitlab
import ( import (
"errors"
"fmt" "fmt"
"time" "time"
) )
...@@ -396,37 +397,56 @@ func (s *UsersService) DeleteSSHKeyForUser(user int, kid int) (*Response, error) ...@@ -396,37 +397,56 @@ func (s *UsersService) DeleteSSHKeyForUser(user int, kid int) (*Response, error)
// BlockUser blocks the specified user. Available only for admin. // BlockUser blocks the specified user. Available only for admin.
// //
// GitLab API docs: http://doc.gitlab.com/ce/api/users.html#block-user // GitLab API docs: http://doc.gitlab.com/ce/api/users.html#block-user
func (s *UsersService) BlockUser(user int) (*Response, error) { func (s *UsersService) BlockUser(user int) error {
u := fmt.Sprintf("users/%d/block", user) u := fmt.Sprintf("users/%d/block", user)
req, err := s.client.NewRequest("PUT", u, nil) req, err := s.client.NewRequest("PUT", u, nil)
if err != nil { if err != nil {
return nil, err return err
} }
resp, err := s.client.Do(req, nil) resp, err := s.client.Do(req, nil)
if err != nil { if err != nil {
return resp, err return err
} }
return resp, err switch resp.StatusCode {
case 200:
return nil
case 403:
return errors.New("Cannot block a user that is already blocked by LDAP synchronization")
case 404:
return errors.New("User does not exists")
default:
return fmt.Errorf("Received unexpected result code: %d", resp.StatusCode)
}
} }
// UnblockUser unblocks the specified user. Available only for admin. // UnblockUser unblocks the specified user. Available only for admin.
// //
// GitLab API docs: http://doc.gitlab.com/ce/api/users.html#unblock-user // GitLab API docs: http://doc.gitlab.com/ce/api/users.html#unblock-user
func (s *UsersService) UnblockUser(user int) (*Response, error) { func (s *UsersService) UnblockUser(user int) error {
u := fmt.Sprintf("users/%d/unblock", user) u := fmt.Sprintf("users/%d/unblock", user)
req, err := s.client.NewRequest("PUT", u, nil) req, err := s.client.NewRequest("PUT", u, nil)
if err != nil { if err != nil {
return nil, err return err
} }
resp, err := s.client.Do(req, nil) resp, err := s.client.Do(req, nil)
if err != nil { if err != nil {
return resp, err return err
} }
return resp, err switch resp.StatusCode {
case 200:
return nil
case 403:
return errors.New("Cannot unblock a user that is blocked by LDAP synchronization")
case 404:
return errors.New("User does not exists")
default:
return fmt.Errorf("Received unexpected result code: %d", resp.StatusCode)
}
return err
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment