Commit 480adfd0 authored by Sander van Harmelen's avatar Sander van Harmelen

Merge pull request #40 from peterm0x/master

Support for user identities & fix for block/unblock
parents fba2237f d305a133
......@@ -17,6 +17,7 @@
package gitlab
import (
"errors"
"fmt"
"time"
)
......@@ -33,28 +34,34 @@ type UsersService struct {
//
// GitLab API docs: http://doc.gitlab.com/ce/api/users.html
type User struct {
ID int `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
Name string `json:"name"`
State string `json:"state"`
CreatedAt time.Time `json:"created_at"`
Bio string `json:"bio"`
Skype string `json:"skype"`
Linkedin string `json:"linkedin"`
Twitter string `json:"twitter"`
WebsiteURL string `json:"website_url"`
ExternUID string `json:"extern_uid"`
Provider string `json:"provider"`
ThemeID int `json:"theme_id"`
ColorSchemeID int `json:"color_scheme_id"`
IsAdmin bool `json:"is_admin"`
AvatarURL string `json:"avatar_url"`
CanCreateGroup bool `json:"can_create_group"`
CanCreateProject bool `json:"can_create_project"`
ProjectsLimit int `json:"projects_limit"`
CurrentSignInAt *time.Time `json:"current_sign_in_at"`
TwoFactorEnabled bool `json:"two_factor_enabled"`
ID int `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
Name string `json:"name"`
State string `json:"state"`
CreatedAt time.Time `json:"created_at"`
Bio string `json:"bio"`
Skype string `json:"skype"`
Linkedin string `json:"linkedin"`
Twitter string `json:"twitter"`
WebsiteURL string `json:"website_url"`
ExternUID string `json:"extern_uid"`
Provider string `json:"provider"`
ThemeID int `json:"theme_id"`
ColorSchemeID int `json:"color_scheme_id"`
IsAdmin bool `json:"is_admin"`
AvatarURL string `json:"avatar_url"`
CanCreateGroup bool `json:"can_create_group"`
CanCreateProject bool `json:"can_create_project"`
ProjectsLimit int `json:"projects_limit"`
CurrentSignInAt *time.Time `json:"current_sign_in_at"`
TwoFactorEnabled bool `json:"two_factor_enabled"`
Identities []*UserIdentity `json:"identities"`
}
type UserIdentity struct {
Provider string `json:"provider"`
ExternUID string `json:"extern_uid"`
}
// ListUsersOptions represents the available ListUsers() options.
......@@ -390,39 +397,56 @@ func (s *UsersService) DeleteSSHKeyForUser(user int, kid int) (*Response, error)
// BlockUser blocks the specified user. Available only for admin.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/users.html#block-user
func (s *UsersService) BlockUser(user int) (*User, *Response, error) {
func (s *UsersService) BlockUser(user int) error {
u := fmt.Sprintf("users/%d/block", user)
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, nil, err
return err
}
usr := new(User)
resp, err := s.client.Do(req, usr)
resp, err := s.client.Do(req, nil)
if err != nil {
return nil, resp, err
return err
}
return usr, 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.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/users.html#unblock-user
func (s *UsersService) UnblockUser(user int) (*User, *Response, error) {
func (s *UsersService) UnblockUser(user int) error {
u := fmt.Sprintf("users/%d/unblock", user)
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, nil, err
return err
}
usr := new(User)
resp, err := s.client.Do(req, usr)
resp, err := s.client.Do(req, nil)
if err != nil {
return nil, resp, err
return err
}
return usr, 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