Module: Gitlab::Client::Users
- Included in:
- Gitlab::Client
- Defined in:
- lib/gitlab/client/users.rb
Overview
Defines methods related to users.
Instance Method Summary collapse
-
#activate_user(user_id) ⇒ Boolean
Activate the specified user.
-
#activities(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Gets a list of user activities (for admin access only).
-
#add_email(email, user_id = nil, skip_confirmation = nil) ⇒ Gitlab::ObjectifiedHash
Creates a new email Will create a new email an authorized user if no user ID passed.
-
#add_user_custom_attribute(key, value, user_id) ⇒ Gitlab::ObjectifiedHash
Creates a new custom_attribute.
-
#approve_user(user_id) ⇒ Boolean
Approves the specified user.
-
#block_user(user_id) ⇒ Boolean
Blocks the specified user.
-
#create_personal_access_token(user_id, name, scopes, expires_at = nil) ⇒ Gitlab::ObjectifiedHash
Create personal access token.
-
#create_service_account(*args) ⇒ Gitlab::ObjectifiedHash
Creates a service account.
-
#create_ssh_key(title, key, options = {}) ⇒ Gitlab::ObjectifiedHash
Creates a new SSH key.
-
#create_user(*args) ⇒ Gitlab::ObjectifiedHash
Creates a new user.
-
#create_user_impersonation_token(user_id, name, scopes, expires_at = nil) ⇒ Gitlab::ObjectifiedHash
Create impersonation token.
-
#deactivate_user(user_id) ⇒ Boolean
Deactivates the specified user.
-
#delete_email(id, user_id = nil) ⇒ Boolean
Delete email Will delete a email an authorized user if no user ID passed.
-
#delete_ssh_key(id, options = {}) ⇒ Gitlab::ObjectifiedHash
Deletes an SSH key.
-
#delete_user(user_id) ⇒ Gitlab::ObjectifiedHash
Deletes a user.
-
#delete_user_custom_attribute(key, user_id) ⇒ Boolean
Delete custom_attribute Will delete a custom_attribute.
-
#disable_two_factor(user_id) ⇒ Gitlab::ObjectifiedHash
Disables two factor authentication (2FA) for the specified user.
-
#edit_user(user_id, options = {}) ⇒ Gitlab::ObjectifiedHash
Updates a user.
-
#email(id) ⇒ Gitlab::ObjectifiedHash
Get a single email.
-
#emails(user_id = nil) ⇒ Gitlab::ObjectifiedHash
Gets user emails.
-
#memberships(user_id) ⇒ Object
Lists all projects and groups a user is a member of.
-
#revoke_personal_access_token(personal_access_token_id) ⇒ Gitlab::ObjectifiedHash
Revoke a personal access token.
-
#revoke_user_impersonation_token(user_id, impersonation_token_id) ⇒ Gitlab::ObjectifiedHash
Revoke an impersonation token.
-
#rotate_personal_access_token(personal_access_token_id, expires_at = nil) ⇒ Gitlab::ObjectifiedHash
Rotate a personal access token.
-
#session(email, password) ⇒ Gitlab::ObjectifiedHash
Creates a new user session.
-
#ssh_key(id) ⇒ Gitlab::ObjectifiedHash
Gets information about SSH key.
-
#ssh_keys(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Gets a list of user’s SSH keys.
-
#unblock_user(user_id) ⇒ Boolean
Unblocks the specified user.
-
#user(id = nil) ⇒ Gitlab::ObjectifiedHash
Gets information about a user.
-
#user_by_username(username, options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Get user by username.
-
#user_custom_attribute(key, user_id) ⇒ Gitlab::ObjectifiedHash
Gets single user custom_attribute.
-
#user_custom_attributes(user_id) ⇒ Gitlab::ObjectifiedHash
Gets user custom_attributes.
-
#user_impersonation_token(user_id, impersonation_token_id) ⇒ Gitlab::ObjectifiedHash
Get impersonation token information.
-
#user_impersonation_tokens(user_id) ⇒ Array<Gitlab::ObjectifiedHash>
Get all impersonation tokens for a user.
-
#user_personal_access_tokens(user_id) ⇒ Array<Gitlab::ObjectifiedHash>
Get all personal access tokens for a user.
-
#user_search(search, options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Search for users by name.
-
#users(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Gets a list of users.
Instance Method Details
#activate_user(user_id) ⇒ Boolean
Activate the specified user. Available only for admin.
147 148 149 |
# File 'lib/gitlab/client/users.rb', line 147 def activate_user(user_id) post("/users/#{user_id}/activate") end |
#activities(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Gets a list of user activities (for admin access only).
185 186 187 |
# File 'lib/gitlab/client/users.rb', line 185 def activities( = {}) get('/user/activities', query: ) end |
#add_email(email, user_id = nil, skip_confirmation = nil) ⇒ Gitlab::ObjectifiedHash
Creates a new email Will create a new email an authorized user if no user ID passed.
293 294 295 296 297 298 299 300 |
# File 'lib/gitlab/client/users.rb', line 293 def add_email(email, user_id = nil, skip_confirmation = nil) url = user_id.to_i.zero? ? '/user/emails' : "/users/#{user_id}/emails" if skip_confirmation.nil? post(url, body: { email: email }) else post(url, body: { email: email, skip_confirmation: skip_confirmation }) end end |
#add_user_custom_attribute(key, value, user_id) ⇒ Gitlab::ObjectifiedHash
Creates a new custom_attribute
377 378 379 380 |
# File 'lib/gitlab/client/users.rb', line 377 def add_user_custom_attribute(key, value, user_id) url = "/users/#{user_id}/custom_attributes/#{key}" put(url, body: { value: value }) end |
#approve_user(user_id) ⇒ Boolean
Approves the specified user. Available only for admin.
158 159 160 |
# File 'lib/gitlab/client/users.rb', line 158 def approve_user(user_id) post("/users/#{user_id}/approve") end |
#block_user(user_id) ⇒ Boolean
Blocks the specified user. Available only for admin.
114 115 116 |
# File 'lib/gitlab/client/users.rb', line 114 def block_user(user_id) post("/users/#{user_id}/block") end |
#create_personal_access_token(user_id, name, scopes, expires_at = nil) ⇒ Gitlab::ObjectifiedHash
Create personal access token
458 459 460 461 462 |
# File 'lib/gitlab/client/users.rb', line 458 def create_personal_access_token(user_id, name, scopes, expires_at = nil) body = { name: name, scopes: scopes } body[:expires_at] = expires_at if expires_at post("/users/#{user_id}/personal_access_tokens", body: body) end |
#create_service_account(*args) ⇒ Gitlab::ObjectifiedHash
Creates a service account. Requires authentication from an admin account.
70 71 72 73 74 75 |
# File 'lib/gitlab/client/users.rb', line 70 def create_service_account(*args) raise ArgumentError, 'Missing required parameters' unless args[1] body = { name: args[0], username: args[1] } post('/service_accounts', body: body) end |
#create_ssh_key(title, key, options = {}) ⇒ Gitlab::ObjectifiedHash
Creates a new SSH key.
230 231 232 233 234 235 236 237 |
# File 'lib/gitlab/client/users.rb', line 230 def create_ssh_key(title, key, = {}) user_id = .delete :user_id if user_id.to_i.zero? post('/user/keys', body: { title: title, key: key }) else post("/users/#{user_id}/keys", body: { title: title, key: key }) end end |
#create_user(*args) ⇒ Gitlab::ObjectifiedHash
Creates a new user. Requires authentication from an admin account.
52 53 54 55 56 57 58 59 |
# File 'lib/gitlab/client/users.rb', line 52 def create_user(*args) = args.last.is_a?(Hash) ? args.pop : {} raise ArgumentError, 'Missing required parameters' unless args[2] body = { email: args[0], password: args[1], username: args[2], name: args[0] } body.merge!() post('/users', body: body) end |
#create_user_impersonation_token(user_id, name, scopes, expires_at = nil) ⇒ Gitlab::ObjectifiedHash
Create impersonation token
430 431 432 433 434 |
# File 'lib/gitlab/client/users.rb', line 430 def create_user_impersonation_token(user_id, name, scopes, expires_at = nil) body = { name: name, scopes: scopes } body[:expires_at] = expires_at if expires_at post("/users/#{user_id}/impersonation_tokens", body: body) end |
#deactivate_user(user_id) ⇒ Boolean
Deactivates the specified user. Available only for admin.
136 137 138 |
# File 'lib/gitlab/client/users.rb', line 136 def deactivate_user(user_id) post("/users/#{user_id}/deactivate") end |
#delete_email(id, user_id = nil) ⇒ Boolean
Delete email Will delete a email an authorized user if no user ID passed.
312 313 314 315 |
# File 'lib/gitlab/client/users.rb', line 312 def delete_email(id, user_id = nil) url = user_id.to_i.zero? ? "/user/emails/#{id}" : "/users/#{user_id}/emails/#{id}" delete(url) end |
#delete_ssh_key(id, options = {}) ⇒ Gitlab::ObjectifiedHash
Deletes an SSH key.
248 249 250 251 252 253 254 255 |
# File 'lib/gitlab/client/users.rb', line 248 def delete_ssh_key(id, = {}) user_id = .delete :user_id if user_id.to_i.zero? delete("/user/keys/#{id}") else delete("/users/#{user_id}/keys/#{id}") end end |
#delete_user(user_id) ⇒ Gitlab::ObjectifiedHash
Deletes a user.
103 104 105 |
# File 'lib/gitlab/client/users.rb', line 103 def delete_user(user_id) delete("/users/#{user_id}") end |
#delete_user_custom_attribute(key, user_id) ⇒ Boolean
Delete custom_attribute Will delete a custom_attribute
391 392 393 |
# File 'lib/gitlab/client/users.rb', line 391 def delete_user_custom_attribute(key, user_id) delete("/users/#{user_id}/custom_attributes/#{key}") end |
#disable_two_factor(user_id) ⇒ Gitlab::ObjectifiedHash
Disables two factor authentication (2FA) for the specified user.
517 518 519 |
# File 'lib/gitlab/client/users.rb', line 517 def disable_two_factor(user_id) patch("/users/#{user_id}/disable_two_factor") end |
#edit_user(user_id, options = {}) ⇒ Gitlab::ObjectifiedHash
Updates a user.
92 93 94 |
# File 'lib/gitlab/client/users.rb', line 92 def edit_user(user_id, = {}) put("/users/#{user_id}", body: ) end |
#email(id) ⇒ Gitlab::ObjectifiedHash
Get a single email.
278 279 280 |
# File 'lib/gitlab/client/users.rb', line 278 def email(id) get("/user/emails/#{id}") end |
#emails(user_id = nil) ⇒ Gitlab::ObjectifiedHash
Gets user emails. Will return emails an authorized user if no user ID passed.
266 267 268 269 |
# File 'lib/gitlab/client/users.rb', line 266 def emails(user_id = nil) url = user_id.to_i.zero? ? '/user/emails' : "/users/#{user_id}/emails" get(url) end |
#memberships(user_id) ⇒ Object
Lists all projects and groups a user is a member of
495 496 497 |
# File 'lib/gitlab/client/users.rb', line 495 def memberships(user_id) get("/users/#{user_id}/memberships") end |
#revoke_personal_access_token(personal_access_token_id) ⇒ Gitlab::ObjectifiedHash
Revoke a personal access token
506 507 508 |
# File 'lib/gitlab/client/users.rb', line 506 def revoke_personal_access_token(personal_access_token_id) delete("/personal_access_tokens/#{personal_access_token_id}") end |
#revoke_user_impersonation_token(user_id, impersonation_token_id) ⇒ Gitlab::ObjectifiedHash
Revoke an impersonation token
485 486 487 |
# File 'lib/gitlab/client/users.rb', line 485 def revoke_user_impersonation_token(user_id, impersonation_token_id) delete("/users/#{user_id}/impersonation_tokens/#{impersonation_token_id}") end |
#rotate_personal_access_token(personal_access_token_id, expires_at = nil) ⇒ Gitlab::ObjectifiedHash
Rotate a personal access token
471 472 473 474 475 |
# File 'lib/gitlab/client/users.rb', line 471 def rotate_personal_access_token(personal_access_token_id, expires_at = nil) body = {} body[:expires_at] = expires_at if expires_at post("/personal_access_tokens/#{personal_access_token_id}/rotate", body: body) end |
#session(email, password) ⇒ Gitlab::ObjectifiedHash
This method doesn’t require private_token to be set.
Creates a new user session.
171 172 173 |
# File 'lib/gitlab/client/users.rb', line 171 def session(email, password) post('/session', body: { email: email, password: password }, unauthenticated: true) end |
#ssh_key(id) ⇒ Gitlab::ObjectifiedHash
Gets information about SSH key.
216 217 218 |
# File 'lib/gitlab/client/users.rb', line 216 def ssh_key(id) get("/user/keys/#{id}") end |
#ssh_keys(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Gets a list of user’s SSH keys.
200 201 202 203 204 205 206 207 |
# File 'lib/gitlab/client/users.rb', line 200 def ssh_keys( = {}) user_id = .delete :user_id if user_id.to_i.zero? get('/user/keys', query: ) else get("/users/#{user_id}/keys", query: ) end end |
#unblock_user(user_id) ⇒ Boolean
Unblocks the specified user. Available only for admin.
125 126 127 |
# File 'lib/gitlab/client/users.rb', line 125 def unblock_user(user_id) post("/users/#{user_id}/unblock") end |
#user(id = nil) ⇒ Gitlab::ObjectifiedHash
Gets information about a user. Will return information about an authorized user if no ID passed.
30 31 32 |
# File 'lib/gitlab/client/users.rb', line 30 def user(id = nil) id.to_i.zero? ? get('/user') : get("/users/#{id}") end |
#user_by_username(username, options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Get user by username
340 341 342 343 |
# File 'lib/gitlab/client/users.rb', line 340 def user_by_username(username, = {}) [:username] = username get('/users', query: ) end |
#user_custom_attribute(key, user_id) ⇒ Gitlab::ObjectifiedHash
Gets single user custom_attribute.
364 365 366 |
# File 'lib/gitlab/client/users.rb', line 364 def user_custom_attribute(key, user_id) get("/users/#{user_id}/custom_attributes/#{key}") end |
#user_custom_attributes(user_id) ⇒ Gitlab::ObjectifiedHash
Gets user custom_attributes.
352 353 354 |
# File 'lib/gitlab/client/users.rb', line 352 def user_custom_attributes(user_id) get("/users/#{user_id}/custom_attributes") end |
#user_impersonation_token(user_id, impersonation_token_id) ⇒ Gitlab::ObjectifiedHash
Get impersonation token information
415 416 417 |
# File 'lib/gitlab/client/users.rb', line 415 def user_impersonation_token(user_id, impersonation_token_id) get("/users/#{user_id}/impersonation_tokens/#{impersonation_token_id}") end |
#user_impersonation_tokens(user_id) ⇒ Array<Gitlab::ObjectifiedHash>
Get all impersonation tokens for a user
403 404 405 |
# File 'lib/gitlab/client/users.rb', line 403 def user_impersonation_tokens(user_id) get("/users/#{user_id}/impersonation_tokens") end |
#user_personal_access_tokens(user_id) ⇒ Array<Gitlab::ObjectifiedHash>
Get all personal access tokens for a user
443 444 445 |
# File 'lib/gitlab/client/users.rb', line 443 def user_personal_access_tokens(user_id) get("/personal_access_tokens?user_id=#{user_id}") end |
#user_search(search, options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Search for users by name
327 328 329 330 |
# File 'lib/gitlab/client/users.rb', line 327 def user_search(search, = {}) [:search] = search get('/users', query: ) end |
#users(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Gets a list of users.
17 18 19 |
# File 'lib/gitlab/client/users.rb', line 17 def users( = {}) get('/users', query: ) end |