Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
go-gitlab
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
go-gitlab
Commits
480adfd0
Commit
480adfd0
authored
Mar 17, 2016
by
Sander van Harmelen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #40 from peterm0x/master
Support for user identities & fix for block/unblock
parents
fba2237f
d305a133
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
12 deletions
+36
-12
users.go
users.go
+36
-12
No files found.
users.go
View file @
480adfd0
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
package
gitlab
package
gitlab
import
(
import
(
"errors"
"fmt"
"fmt"
"time"
"time"
)
)
...
@@ -55,6 +56,12 @@ type User struct {
...
@@ -55,6 +56,12 @@ type User struct {
ProjectsLimit
int
`json:"projects_limit"`
ProjectsLimit
int
`json:"projects_limit"`
CurrentSignInAt
*
time
.
Time
`json:"current_sign_in_at"`
CurrentSignInAt
*
time
.
Time
`json:"current_sign_in_at"`
TwoFactorEnabled
bool
`json:"two_factor_enabled"`
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.
// ListUsersOptions represents the available ListUsers() options.
...
@@ -390,39 +397,56 @@ func (s *UsersService) DeleteSSHKeyForUser(user int, kid int) (*Response, error)
...
@@ -390,39 +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
)
(
*
User
,
*
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
,
nil
,
err
return
err
}
}
usr
:=
new
(
User
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
nil
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
usr
)
if
err
!=
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.
// 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
)
(
*
User
,
*
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
,
nil
,
err
return
err
}
}
usr
:=
new
(
User
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
nil
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
usr
)
if
err
!=
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
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment