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
-
#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.
-
#block_user(user_id) ⇒ Boolean
Blocks the specified user.
-
#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.
-
#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.
-
#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.
-
#revoke_user_impersonation_token(user_id, impersonation_token_id) ⇒ Gitlab::ObjectifiedHash
Revoke an impersonation 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_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_search(search, options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Search for groups by name.
-
#users(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Gets a list of users.
Instance Method Details
#activities(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Gets a list of user activities (for admin access only).
136 137 138 |
# File 'lib/gitlab/client/users.rb', line 136 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.
244 245 246 247 248 249 250 251 |
# File 'lib/gitlab/client/users.rb', line 244 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
315 316 317 318 |
# File 'lib/gitlab/client/users.rb', line 315 def add_user_custom_attribute(key, value, user_id) url = "/users/#{user_id}/custom_attributes/#{key}" put(url, body: { value: value }) end |
#block_user(user_id) ⇒ Boolean
Blocks the specified user. Available only for admin.
98 99 100 |
# File 'lib/gitlab/client/users.rb', line 98 def block_user(user_id) post("/users/#{user_id}/block") end |
#create_ssh_key(title, key, options = {}) ⇒ Gitlab::ObjectifiedHash
Creates a new SSH key.
181 182 183 184 185 186 187 188 |
# File 'lib/gitlab/client/users.rb', line 181 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
368 369 370 371 372 |
# File 'lib/gitlab/client/users.rb', line 368 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 |
#delete_email(id, user_id = nil) ⇒ Boolean
Delete email Will delete a email an authorized user if no user ID passed.
263 264 265 266 |
# File 'lib/gitlab/client/users.rb', line 263 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.
199 200 201 202 203 204 205 206 |
# File 'lib/gitlab/client/users.rb', line 199 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.
87 88 89 |
# File 'lib/gitlab/client/users.rb', line 87 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
329 330 331 |
# File 'lib/gitlab/client/users.rb', line 329 def delete_user_custom_attribute(key, user_id) delete("/users/#{user_id}/custom_attributes/#{key}") end |
#edit_user(user_id, options = {}) ⇒ Gitlab::ObjectifiedHash
Updates a user.
76 77 78 |
# File 'lib/gitlab/client/users.rb', line 76 def edit_user(user_id, = {}) put("/users/#{user_id}", body: ) end |
#email(id) ⇒ Gitlab::ObjectifiedHash
Get a single email.
229 230 231 |
# File 'lib/gitlab/client/users.rb', line 229 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.
217 218 219 220 |
# File 'lib/gitlab/client/users.rb', line 217 def emails(user_id = nil) url = user_id.to_i.zero? ? '/user/emails' : "/users/#{user_id}/emails" get(url) end |
#revoke_user_impersonation_token(user_id, impersonation_token_id) ⇒ Gitlab::ObjectifiedHash
Revoke an impersonation token
382 383 384 |
# File 'lib/gitlab/client/users.rb', line 382 def revoke_user_impersonation_token(user_id, impersonation_token_id) delete("/users/#{user_id}/impersonation_tokens/#{impersonation_token_id}") end |
#session(email, password) ⇒ Gitlab::ObjectifiedHash
This method doesn’t require private_token to be set.
Creates a new user session.
122 123 124 |
# File 'lib/gitlab/client/users.rb', line 122 def session(email, password) post('/session', body: { email: email, password: password }, unauthenticated: true) end |
#ssh_key(id) ⇒ Gitlab::ObjectifiedHash
Gets information about SSH key.
167 168 169 |
# File 'lib/gitlab/client/users.rb', line 167 def ssh_key(id) get("/user/keys/#{id}") end |
#ssh_keys(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Gets a list of user’s SSH keys.
151 152 153 154 155 156 157 158 |
# File 'lib/gitlab/client/users.rb', line 151 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.
109 110 111 |
# File 'lib/gitlab/client/users.rb', line 109 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_custom_attribute(key, user_id) ⇒ Gitlab::ObjectifiedHash
Gets single user custom_attribute.
302 303 304 |
# File 'lib/gitlab/client/users.rb', line 302 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.
290 291 292 |
# File 'lib/gitlab/client/users.rb', line 290 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
353 354 355 |
# File 'lib/gitlab/client/users.rb', line 353 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
341 342 343 |
# File 'lib/gitlab/client/users.rb', line 341 def user_impersonation_tokens(user_id) get("/users/#{user_id}/impersonation_tokens") end |
#user_search(search, options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Search for groups by name
278 279 280 281 |
# File 'lib/gitlab/client/users.rb', line 278 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 |