diff options
Diffstat (limited to 'vendor/github.com/xanzy/go-gitlab/users.go')
-rw-r--r-- | vendor/github.com/xanzy/go-gitlab/users.go | 165 |
1 files changed, 112 insertions, 53 deletions
diff --git a/vendor/github.com/xanzy/go-gitlab/users.go b/vendor/github.com/xanzy/go-gitlab/users.go index c8015cda7a..36d8549ca9 100644 --- a/vendor/github.com/xanzy/go-gitlab/users.go +++ b/vendor/github.com/xanzy/go-gitlab/users.go @@ -24,9 +24,11 @@ import ( // List a couple of standard errors. var ( - ErrUserBlockPrevented = errors.New("Cannot block a user that is already blocked by LDAP synchronization") - ErrUserNotFound = errors.New("User does not exist") - ErrUserUnblockPrevented = errors.New("Cannot unblock a user that is blocked by LDAP synchronization") + ErrUserActivatePrevented = errors.New("Cannot activate a user that is blocked by admin or by LDAP synchronization") + ErrUserBlockPrevented = errors.New("Cannot block a user that is already blocked by LDAP synchronization") + ErrUserDeactivatePrevented = errors.New("Cannot deactivate a user that is blocked by admin or by LDAP synchronization, or that has any activity in past 180 days") + ErrUserNotFound = errors.New("User does not exist") + ErrUserUnblockPrevented = errors.New("Cannot unblock a user that is blocked by LDAP synchronization") ) // UsersService handles communication with the user related methods of @@ -116,7 +118,7 @@ type ListUsersOptions struct { // ListUsers gets a list of users. // // GitLab API docs: https://docs.gitlab.com/ce/api/users.html#list-users -func (s *UsersService) ListUsers(opt *ListUsersOptions, options ...OptionFunc) ([]*User, *Response, error) { +func (s *UsersService) ListUsers(opt *ListUsersOptions, options ...RequestOptionFunc) ([]*User, *Response, error) { req, err := s.client.NewRequest("GET", "users", opt, options) if err != nil { return nil, nil, err @@ -134,7 +136,7 @@ func (s *UsersService) ListUsers(opt *ListUsersOptions, options ...OptionFunc) ( // GetUser gets a single user. // // GitLab API docs: https://docs.gitlab.com/ce/api/users.html#single-user -func (s *UsersService) GetUser(user int, options ...OptionFunc) (*User, *Response, error) { +func (s *UsersService) GetUser(user int, options ...RequestOptionFunc) (*User, *Response, error) { u := fmt.Sprintf("users/%d", user) req, err := s.client.NewRequest("GET", u, nil, options) @@ -155,32 +157,33 @@ func (s *UsersService) GetUser(user int, options ...OptionFunc) (*User, *Respons // // GitLab API docs: https://docs.gitlab.com/ce/api/users.html#user-creation type CreateUserOptions struct { - Email *string `url:"email,omitempty" json:"email,omitempty"` - Password *string `url:"password,omitempty" json:"password,omitempty"` - ResetPassword *bool `url:"reset_password,omitempty" json:"reset_password,omitempty"` - Username *string `url:"username,omitempty" json:"username,omitempty"` - Name *string `url:"name,omitempty" json:"name,omitempty"` - Skype *string `url:"skype,omitempty" json:"skype,omitempty"` - Linkedin *string `url:"linkedin,omitempty" json:"linkedin,omitempty"` - Twitter *string `url:"twitter,omitempty" json:"twitter,omitempty"` - WebsiteURL *string `url:"website_url,omitempty" json:"website_url,omitempty"` - Organization *string `url:"organization,omitempty" json:"organization,omitempty"` - ProjectsLimit *int `url:"projects_limit,omitempty" json:"projects_limit,omitempty"` - ExternUID *string `url:"extern_uid,omitempty" json:"extern_uid,omitempty"` - Provider *string `url:"provider,omitempty" json:"provider,omitempty"` - Bio *string `url:"bio,omitempty" json:"bio,omitempty"` - Location *string `url:"location,omitempty" json:"location,omitempty"` - Admin *bool `url:"admin,omitempty" json:"admin,omitempty"` - CanCreateGroup *bool `url:"can_create_group,omitempty" json:"can_create_group,omitempty"` - SkipConfirmation *bool `url:"skip_confirmation,omitempty" json:"skip_confirmation,omitempty"` - External *bool `url:"external,omitempty" json:"external,omitempty"` - PrivateProfile *bool `url:"private_profile,omitempty" json:"private_profile,omitempty"` + Email *string `url:"email,omitempty" json:"email,omitempty"` + Password *string `url:"password,omitempty" json:"password,omitempty"` + ResetPassword *bool `url:"reset_password,omitempty" json:"reset_password,omitempty"` + ForceRandomPassword *bool `url:"force_random_password,omitempty" json:"force_random_password,omitempty"` + Username *string `url:"username,omitempty" json:"username,omitempty"` + Name *string `url:"name,omitempty" json:"name,omitempty"` + Skype *string `url:"skype,omitempty" json:"skype,omitempty"` + Linkedin *string `url:"linkedin,omitempty" json:"linkedin,omitempty"` + Twitter *string `url:"twitter,omitempty" json:"twitter,omitempty"` + WebsiteURL *string `url:"website_url,omitempty" json:"website_url,omitempty"` + Organization *string `url:"organization,omitempty" json:"organization,omitempty"` + ProjectsLimit *int `url:"projects_limit,omitempty" json:"projects_limit,omitempty"` + ExternUID *string `url:"extern_uid,omitempty" json:"extern_uid,omitempty"` + Provider *string `url:"provider,omitempty" json:"provider,omitempty"` + Bio *string `url:"bio,omitempty" json:"bio,omitempty"` + Location *string `url:"location,omitempty" json:"location,omitempty"` + Admin *bool `url:"admin,omitempty" json:"admin,omitempty"` + CanCreateGroup *bool `url:"can_create_group,omitempty" json:"can_create_group,omitempty"` + SkipConfirmation *bool `url:"skip_confirmation,omitempty" json:"skip_confirmation,omitempty"` + External *bool `url:"external,omitempty" json:"external,omitempty"` + PrivateProfile *bool `url:"private_profile,omitempty" json:"private_profile,omitempty"` } // CreateUser creates a new user. Note only administrators can create new users. // // GitLab API docs: https://docs.gitlab.com/ce/api/users.html#user-creation -func (s *UsersService) CreateUser(opt *CreateUserOptions, options ...OptionFunc) (*User, *Response, error) { +func (s *UsersService) CreateUser(opt *CreateUserOptions, options ...RequestOptionFunc) (*User, *Response, error) { req, err := s.client.NewRequest("POST", "users", opt, options) if err != nil { return nil, nil, err @@ -224,7 +227,7 @@ type ModifyUserOptions struct { // of a user. // // GitLab API docs: https://docs.gitlab.com/ce/api/users.html#user-modification -func (s *UsersService) ModifyUser(user int, opt *ModifyUserOptions, options ...OptionFunc) (*User, *Response, error) { +func (s *UsersService) ModifyUser(user int, opt *ModifyUserOptions, options ...RequestOptionFunc) (*User, *Response, error) { u := fmt.Sprintf("users/%d", user) req, err := s.client.NewRequest("PUT", u, opt, options) @@ -248,7 +251,7 @@ func (s *UsersService) ModifyUser(user int, opt *ModifyUserOptions, options ...O // latter not. // // GitLab API docs: https://docs.gitlab.com/ce/api/users.html#user-deletion -func (s *UsersService) DeleteUser(user int, options ...OptionFunc) (*Response, error) { +func (s *UsersService) DeleteUser(user int, options ...RequestOptionFunc) (*Response, error) { u := fmt.Sprintf("users/%d", user) req, err := s.client.NewRequest("DELETE", u, nil, options) @@ -262,7 +265,7 @@ func (s *UsersService) DeleteUser(user int, options ...OptionFunc) (*Response, e // CurrentUser gets currently authenticated user. // // GitLab API docs: https://docs.gitlab.com/ce/api/users.html#current-user -func (s *UsersService) CurrentUser(options ...OptionFunc) (*User, *Response, error) { +func (s *UsersService) CurrentUser(options ...RequestOptionFunc) (*User, *Response, error) { req, err := s.client.NewRequest("GET", "user", nil, options) if err != nil { return nil, nil, err @@ -290,7 +293,7 @@ type SSHKey struct { // ListSSHKeys gets a list of currently authenticated user's SSH keys. // // GitLab API docs: https://docs.gitlab.com/ce/api/users.html#list-ssh-keys -func (s *UsersService) ListSSHKeys(options ...OptionFunc) ([]*SSHKey, *Response, error) { +func (s *UsersService) ListSSHKeys(options ...RequestOptionFunc) ([]*SSHKey, *Response, error) { req, err := s.client.NewRequest("GET", "user/keys", nil, options) if err != nil { return nil, nil, err @@ -316,7 +319,7 @@ type ListSSHKeysForUserOptions ListOptions // // GitLab API docs: // https://docs.gitlab.com/ce/api/users.html#list-ssh-keys-for-user -func (s *UsersService) ListSSHKeysForUser(user int, opt *ListSSHKeysForUserOptions, options ...OptionFunc) ([]*SSHKey, *Response, error) { +func (s *UsersService) ListSSHKeysForUser(user int, opt *ListSSHKeysForUserOptions, options ...RequestOptionFunc) ([]*SSHKey, *Response, error) { u := fmt.Sprintf("users/%d/keys", user) req, err := s.client.NewRequest("GET", u, opt, options) @@ -336,7 +339,7 @@ func (s *UsersService) ListSSHKeysForUser(user int, opt *ListSSHKeysForUserOptio // GetSSHKey gets a single key. // // GitLab API docs: https://docs.gitlab.com/ce/api/users.html#single-ssh-key -func (s *UsersService) GetSSHKey(key int, options ...OptionFunc) (*SSHKey, *Response, error) { +func (s *UsersService) GetSSHKey(key int, options ...RequestOptionFunc) (*SSHKey, *Response, error) { u := fmt.Sprintf("user/keys/%d", key) req, err := s.client.NewRequest("GET", u, nil, options) @@ -364,7 +367,7 @@ type AddSSHKeyOptions struct { // AddSSHKey creates a new key owned by the currently authenticated user. // // GitLab API docs: https://docs.gitlab.com/ce/api/users.html#add-ssh-key -func (s *UsersService) AddSSHKey(opt *AddSSHKeyOptions, options ...OptionFunc) (*SSHKey, *Response, error) { +func (s *UsersService) AddSSHKey(opt *AddSSHKeyOptions, options ...RequestOptionFunc) (*SSHKey, *Response, error) { req, err := s.client.NewRequest("POST", "user/keys", opt, options) if err != nil { return nil, nil, err @@ -383,7 +386,7 @@ func (s *UsersService) AddSSHKey(opt *AddSSHKeyOptions, options ...OptionFunc) ( // admin. // // GitLab API docs: https://docs.gitlab.com/ce/api/users.html#add-ssh-key-for-user -func (s *UsersService) AddSSHKeyForUser(user int, opt *AddSSHKeyOptions, options ...OptionFunc) (*SSHKey, *Response, error) { +func (s *UsersService) AddSSHKeyForUser(user int, opt *AddSSHKeyOptions, options ...RequestOptionFunc) (*SSHKey, *Response, error) { u := fmt.Sprintf("users/%d/keys", user) req, err := s.client.NewRequest("POST", u, opt, options) @@ -406,7 +409,7 @@ func (s *UsersService) AddSSHKeyForUser(user int, opt *AddSSHKeyOptions, options // // GitLab API docs: // https://docs.gitlab.com/ce/api/users.html#delete-ssh-key-for-current-owner -func (s *UsersService) DeleteSSHKey(key int, options ...OptionFunc) (*Response, error) { +func (s *UsersService) DeleteSSHKey(key int, options ...RequestOptionFunc) (*Response, error) { u := fmt.Sprintf("user/keys/%d", key) req, err := s.client.NewRequest("DELETE", u, nil, options) @@ -422,7 +425,7 @@ func (s *UsersService) DeleteSSHKey(key int, options ...OptionFunc) (*Response, // // GitLab API docs: // https://docs.gitlab.com/ce/api/users.html#delete-ssh-key-for-given-user -func (s *UsersService) DeleteSSHKeyForUser(user, key int, options ...OptionFunc) (*Response, error) { +func (s *UsersService) DeleteSSHKeyForUser(user, key int, options ...RequestOptionFunc) (*Response, error) { u := fmt.Sprintf("users/%d/keys/%d", user, key) req, err := s.client.NewRequest("DELETE", u, nil, options) @@ -436,7 +439,7 @@ func (s *UsersService) DeleteSSHKeyForUser(user, key int, options ...OptionFunc) // BlockUser blocks the specified user. Available only for admin. // // GitLab API docs: https://docs.gitlab.com/ce/api/users.html#block-user -func (s *UsersService) BlockUser(user int, options ...OptionFunc) error { +func (s *UsersService) BlockUser(user int, options ...RequestOptionFunc) error { u := fmt.Sprintf("users/%d/block", user) req, err := s.client.NewRequest("POST", u, nil, options) @@ -464,7 +467,7 @@ func (s *UsersService) BlockUser(user int, options ...OptionFunc) error { // UnblockUser unblocks the specified user. Available only for admin. // // GitLab API docs: https://docs.gitlab.com/ce/api/users.html#unblock-user -func (s *UsersService) UnblockUser(user int, options ...OptionFunc) error { +func (s *UsersService) UnblockUser(user int, options ...RequestOptionFunc) error { u := fmt.Sprintf("users/%d/unblock", user) req, err := s.client.NewRequest("POST", u, nil, options) @@ -489,6 +492,62 @@ func (s *UsersService) UnblockUser(user int, options ...OptionFunc) error { } } +// DeactivateUser deactivate the specified user. Available only for admin. +// +// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#deactivate-user +func (s *UsersService) DeactivateUser(user int, options ...RequestOptionFunc) error { + u := fmt.Sprintf("users/%d/deactivate", user) + + req, err := s.client.NewRequest("POST", 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 ErrUserDeactivatePrevented + case 404: + return ErrUserNotFound + default: + return fmt.Errorf("Received unexpected result code: %d", resp.StatusCode) + } +} + +// ActivateUser activate the specified user. Available only for admin. +// +// GitLab API docs: https://docs.gitlab.com/ce/api/users.html#activate-user +func (s *UsersService) ActivateUser(user int, options ...RequestOptionFunc) error { + u := fmt.Sprintf("users/%d/activate", user) + + req, err := s.client.NewRequest("POST", 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 ErrUserActivatePrevented + case 404: + return ErrUserNotFound + default: + return fmt.Errorf("Received unexpected result code: %d", resp.StatusCode) + } +} + // Email represents an Email. // // GitLab API docs: https://doc.gitlab.com/ce/api/users.html#list-emails @@ -500,7 +559,7 @@ type Email struct { // ListEmails gets a list of currently authenticated user's Emails. // // GitLab API docs: https://docs.gitlab.com/ce/api/users.html#list-emails -func (s *UsersService) ListEmails(options ...OptionFunc) ([]*Email, *Response, error) { +func (s *UsersService) ListEmails(options ...RequestOptionFunc) ([]*Email, *Response, error) { req, err := s.client.NewRequest("GET", "user/emails", nil, options) if err != nil { return nil, nil, err @@ -526,7 +585,7 @@ type ListEmailsForUserOptions ListOptions // // GitLab API docs: // https://docs.gitlab.com/ce/api/users.html#list-emails-for-user -func (s *UsersService) ListEmailsForUser(user int, opt *ListEmailsForUserOptions, options ...OptionFunc) ([]*Email, *Response, error) { +func (s *UsersService) ListEmailsForUser(user int, opt *ListEmailsForUserOptions, options ...RequestOptionFunc) ([]*Email, *Response, error) { u := fmt.Sprintf("users/%d/emails", user) req, err := s.client.NewRequest("GET", u, opt, options) @@ -546,7 +605,7 @@ func (s *UsersService) ListEmailsForUser(user int, opt *ListEmailsForUserOptions // GetEmail gets a single email. // // GitLab API docs: https://docs.gitlab.com/ce/api/users.html#single-email -func (s *UsersService) GetEmail(email int, options ...OptionFunc) (*Email, *Response, error) { +func (s *UsersService) GetEmail(email int, options ...RequestOptionFunc) (*Email, *Response, error) { u := fmt.Sprintf("user/emails/%d", email) req, err := s.client.NewRequest("GET", u, nil, options) @@ -573,7 +632,7 @@ type AddEmailOptions struct { // AddEmail creates a new email owned by the currently authenticated user. // // GitLab API docs: https://docs.gitlab.com/ce/api/users.html#add-email -func (s *UsersService) AddEmail(opt *AddEmailOptions, options ...OptionFunc) (*Email, *Response, error) { +func (s *UsersService) AddEmail(opt *AddEmailOptions, options ...RequestOptionFunc) (*Email, *Response, error) { req, err := s.client.NewRequest("POST", "user/emails", opt, options) if err != nil { return nil, nil, err @@ -592,7 +651,7 @@ func (s *UsersService) AddEmail(opt *AddEmailOptions, options ...OptionFunc) (*E // admin. // // GitLab API docs: https://docs.gitlab.com/ce/api/users.html#add-email-for-user -func (s *UsersService) AddEmailForUser(user int, opt *AddEmailOptions, options ...OptionFunc) (*Email, *Response, error) { +func (s *UsersService) AddEmailForUser(user int, opt *AddEmailOptions, options ...RequestOptionFunc) (*Email, *Response, error) { u := fmt.Sprintf("users/%d/emails", user) req, err := s.client.NewRequest("POST", u, opt, options) @@ -615,7 +674,7 @@ func (s *UsersService) AddEmailForUser(user int, opt *AddEmailOptions, options . // // GitLab API docs: // https://docs.gitlab.com/ce/api/users.html#delete-email-for-current-owner -func (s *UsersService) DeleteEmail(email int, options ...OptionFunc) (*Response, error) { +func (s *UsersService) DeleteEmail(email int, options ...RequestOptionFunc) (*Response, error) { u := fmt.Sprintf("user/emails/%d", email) req, err := s.client.NewRequest("DELETE", u, nil, options) @@ -631,7 +690,7 @@ func (s *UsersService) DeleteEmail(email int, options ...OptionFunc) (*Response, // // GitLab API docs: // https://docs.gitlab.com/ce/api/users.html#delete-email-for-given-user -func (s *UsersService) DeleteEmailForUser(user, email int, options ...OptionFunc) (*Response, error) { +func (s *UsersService) DeleteEmailForUser(user, email int, options ...RequestOptionFunc) (*Response, error) { u := fmt.Sprintf("users/%d/emails/%d", user, email) req, err := s.client.NewRequest("DELETE", u, nil, options) @@ -671,7 +730,7 @@ type GetAllImpersonationTokensOptions struct { // // GitLab API docs: // https://docs.gitlab.com/ce/api/users.html#get-all-impersonation-tokens-of-a-user -func (s *UsersService) GetAllImpersonationTokens(user int, opt *GetAllImpersonationTokensOptions, options ...OptionFunc) ([]*ImpersonationToken, *Response, error) { +func (s *UsersService) GetAllImpersonationTokens(user int, opt *GetAllImpersonationTokensOptions, options ...RequestOptionFunc) ([]*ImpersonationToken, *Response, error) { u := fmt.Sprintf("users/%d/impersonation_tokens", user) req, err := s.client.NewRequest("GET", u, opt, options) @@ -692,7 +751,7 @@ func (s *UsersService) GetAllImpersonationTokens(user int, opt *GetAllImpersonat // // GitLab API docs: // https://docs.gitlab.com/ce/api/users.html#get-an-impersonation-token-of-a-user -func (s *UsersService) GetImpersonationToken(user, token int, options ...OptionFunc) (*ImpersonationToken, *Response, error) { +func (s *UsersService) GetImpersonationToken(user, token int, options ...RequestOptionFunc) (*ImpersonationToken, *Response, error) { u := fmt.Sprintf("users/%d/impersonation_tokens/%d", user, token) req, err := s.client.NewRequest("GET", u, nil, options) @@ -724,7 +783,7 @@ type CreateImpersonationTokenOptions struct { // // GitLab API docs: // https://docs.gitlab.com/ce/api/users.html#create-an-impersonation-token -func (s *UsersService) CreateImpersonationToken(user int, opt *CreateImpersonationTokenOptions, options ...OptionFunc) (*ImpersonationToken, *Response, error) { +func (s *UsersService) CreateImpersonationToken(user int, opt *CreateImpersonationTokenOptions, options ...RequestOptionFunc) (*ImpersonationToken, *Response, error) { u := fmt.Sprintf("users/%d/impersonation_tokens", user) req, err := s.client.NewRequest("POST", u, opt, options) @@ -745,7 +804,7 @@ func (s *UsersService) CreateImpersonationToken(user int, opt *CreateImpersonati // // GitLab API docs: // https://docs.gitlab.com/ce/api/users.html#revoke-an-impersonation-token -func (s *UsersService) RevokeImpersonationToken(user, token int, options ...OptionFunc) (*Response, error) { +func (s *UsersService) RevokeImpersonationToken(user, token int, options ...RequestOptionFunc) (*Response, error) { u := fmt.Sprintf("users/%d/impersonation_tokens/%d", user, token) req, err := s.client.NewRequest("DELETE", u, nil, options) @@ -777,7 +836,7 @@ type GetUserActivitiesOptions struct { // // GitLab API docs: // https://docs.gitlab.com/ce/api/users.html#get-user-activities-admin-only -func (s *UsersService) GetUserActivities(opt *GetUserActivitiesOptions, options ...OptionFunc) ([]*UserActivity, *Response, error) { +func (s *UsersService) GetUserActivities(opt *GetUserActivitiesOptions, options ...RequestOptionFunc) ([]*UserActivity, *Response, error) { req, err := s.client.NewRequest("GET", "user/activities", opt, options) if err != nil { return nil, nil, err @@ -806,7 +865,7 @@ type UserStatus struct { // // GitLab API docs: // https://docs.gitlab.com/ce/api/users.html#user-status -func (s *UsersService) CurrentUserStatus(options ...OptionFunc) (*UserStatus, *Response, error) { +func (s *UsersService) CurrentUserStatus(options ...RequestOptionFunc) (*UserStatus, *Response, error) { req, err := s.client.NewRequest("GET", "user/status", nil, options) if err != nil { return nil, nil, err @@ -825,7 +884,7 @@ func (s *UsersService) CurrentUserStatus(options ...OptionFunc) (*UserStatus, *R // // GitLab API docs: // https://docs.gitlab.com/ce/api/users.html#get-the-status-of-a-user -func (s *UsersService) GetUserStatus(user int, options ...OptionFunc) (*UserStatus, *Response, error) { +func (s *UsersService) GetUserStatus(user int, options ...RequestOptionFunc) (*UserStatus, *Response, error) { u := fmt.Sprintf("users/%d/status", user) req, err := s.client.NewRequest("GET", u, nil, options) @@ -855,7 +914,7 @@ type UserStatusOptions struct { // // GitLab API docs: // https://docs.gitlab.com/ce/api/users.html#set-user-status -func (s *UsersService) SetUserStatus(opt *UserStatusOptions, options ...OptionFunc) (*UserStatus, *Response, error) { +func (s *UsersService) SetUserStatus(opt *UserStatusOptions, options ...RequestOptionFunc) (*UserStatus, *Response, error) { req, err := s.client.NewRequest("PUT", "user/status", opt, options) if err != nil { return nil, nil, err |