Class: Readiness::GitLab::Users
- Inherits:
-
Client
- Object
- Client
- Readiness::GitLab::Users
show all
- Defined in:
- lib/support_readiness/gitlab/users.rb
Overview
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.block!(client, user) ⇒ Boolean
-
.create_token!(client, user, params) ⇒ Object
Creates a personal access token for a user within GitLab.
-
.emails(client, user) ⇒ Array
Fetches the email addresses for a user.
-
.find(client, uid) ⇒ Hash
Locates a user within GitLab.
-
.find!(client, uid, attributes = []) ⇒ Object
Locates a user within GitLab.
-
.gpg_keys(client, user) ⇒ Array
Lists SSH keys for a user.
-
.memberships(client, user, params = []) ⇒ Array
Lists all memberships for a user.
-
.only_maintainer?(client, user) ⇒ Boolean
Determines if a user is the only maintainer on projects they are within.
-
.projects(client, user, filters = []) ⇒ Array
-
.revoke_token!(client, tid) ⇒ Boolean
Revokes a personal access token within GitLab.
-
.rotate_token!(client, tid) ⇒ Hash
Rotates a personal access token (revokes it and makes a new one with the same user).
-
.search_by_email(client, email) ⇒ Array
Locates the first 20 users matching a email within GitLab.
-
.search_by_username(client, username) ⇒ Array
Locates the first 20 users matching a username within GitLab.
-
.ssh_keys(client, user) ⇒ Array
Lists SSH keys for a user.
-
.tokens(client, user, filters = []) ⇒ Array
Lists all personal access tokens for a user.
-
.unblock!(client, user) ⇒ Boolean
Unblocks a user in GitLab.
-
.update!(client, user) ⇒ Object
Updates a user within GitLab.
Instance Method Summary
collapse
Methods inherited from Client
auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries
Constructor Details
#initialize(object = {}) ⇒ Users
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/support_readiness/gitlab/users.rb', line 25
def initialize(object = {})
@avatar_url = object['avatar_url']
@bio = object['bio']
@bot = object['bot']
@can_create_group = object['can_create_group']
@can_create_project = object['can_create_project']
@color_scheme_id = object['color_scheme_id']
@commit_email = object['commit_email']
@confirmed_at = object['confirmed_at']
@created_at = object['created_at']
@created_by = object['created_by']
@current_sign_in_at = object['current_sign_in_at']
@current_sign_in_ip = object['current_sign_in_ip']
@discord = object['discord']
@email = object['email']
@email_reset_offered_at = object['email_reset_offered_at']
@enterprise_group_associated_at = object['enterprise_group_associated_at']
@enterprise_group_id = object['enterprise_group_id']
@external = object['external']
@extra_shared_runners_minutes_limit = object['extra_shared_runners_minutes_limit']
@followers = object['followers']
@following = object['following']
@highest_role = object['highest_role']
@id = object['id']
@identities = object['identities']
@is_admin = object['is_admin']
@is_auditor = object['is_auditor']
@is_followed = object['is_followed']
@job_title = object['job_title']
@last_activity_on = object['last_activity_on']
@last_sign_in_at = object['last_sign_in_at']
@last_sign_in_ip = object['last_sign_in_ip']
@linkedin = object['linkedin']
@local_time = object['local_time']
@location = object['location']
@locked = object['locked']
@name = object['name']
@namespace_id = object['namespace_id']
@note = object['note']
@organization = object['organization']
@plan = object['plan']
@private_profile = object['private_profile']
@projects_limit = object['projects_limit']
@pronouns = object['pronouns']
@provisioned_by_group_id = object['provisioned_by_group_id']
@public_email = object['public_email']
@scim_identities = object['scim_identities']
@shared_runners_minutes_limit = object['shared_runners_minutes_limit']
@sign_in_count = object['sign_in_count']
@skype = object['skype']
@state = object['state']
@theme_id = object['theme_id']
@trial = object['trial']
@twitter = object['twitter']
@two_factor_enabled = object['two_factor_enabled']
@username = object['username']
@using_license_seat = object['using_license_seat']
@website_url = object['website_url']
@web_url = object['web_url']
@work_information = object['work_information']
end
|
Instance Attribute Details
#avatar_url ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def avatar_url
@avatar_url
end
|
#bio ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def bio
@bio
end
|
#bot ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def bot
@bot
end
|
#can_create_group ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def can_create_group
@can_create_group
end
|
#can_create_project ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def can_create_project
@can_create_project
end
|
#color_scheme_id ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def color_scheme_id
@color_scheme_id
end
|
#commit_email ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def commit_email
@commit_email
end
|
#confirmed_at ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def confirmed_at
@confirmed_at
end
|
#created_at ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def created_at
@created_at
end
|
#created_by ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def created_by
@created_by
end
|
#current_sign_in_at ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def current_sign_in_at
@current_sign_in_at
end
|
#current_sign_in_ip ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def current_sign_in_ip
@current_sign_in_ip
end
|
#discord ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def discord
@discord
end
|
#email ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def email
@email
end
|
#email_reset_offered_at ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def email_reset_offered_at
@email_reset_offered_at
end
|
#enterprise_group_associated_at ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def enterprise_group_associated_at
@enterprise_group_associated_at
end
|
#enterprise_group_id ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def enterprise_group_id
@enterprise_group_id
end
|
#external ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def external
@external
end
|
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def
@extra_shared_runners_minutes_limit
end
|
#followers ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def followers
@followers
end
|
#following ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def following
@following
end
|
#highest_role ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def highest_role
@highest_role
end
|
#id ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def id
@id
end
|
#identities ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def identities
@identities
end
|
#is_admin ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def is_admin
@is_admin
end
|
#is_auditor ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def is_auditor
@is_auditor
end
|
#is_followed ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def is_followed
@is_followed
end
|
#job_title ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def job_title
@job_title
end
|
#last_activity_on ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def last_activity_on
@last_activity_on
end
|
#last_sign_in_at ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def last_sign_in_at
@last_sign_in_at
end
|
#last_sign_in_ip ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def last_sign_in_ip
@last_sign_in_ip
end
|
#linkedin ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def linkedin
@linkedin
end
|
#local_time ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def local_time
@local_time
end
|
#location ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def location
@location
end
|
#locked ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def locked
@locked
end
|
#name ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def name
@name
end
|
#namespace_id ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def namespace_id
@namespace_id
end
|
#note ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def note
@note
end
|
#organization ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def organization
@organization
end
|
#plan ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def plan
@plan
end
|
#private_profile ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def private_profile
@private_profile
end
|
#projects_limit ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def projects_limit
@projects_limit
end
|
#pronouns ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def pronouns
@pronouns
end
|
#provisioned_by_group_id ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def provisioned_by_group_id
@provisioned_by_group_id
end
|
#public_email ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def public_email
@public_email
end
|
#scim_identities ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def scim_identities
@scim_identities
end
|
#shared_runners_minutes_limit ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def shared_runners_minutes_limit
@shared_runners_minutes_limit
end
|
#sign_in_count ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def sign_in_count
@sign_in_count
end
|
#skype ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def skype
@skype
end
|
#state ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def state
@state
end
|
#theme_id ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def theme_id
@theme_id
end
|
#trial ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def trial
@trial
end
|
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def
@twitter
end
|
#two_factor_enabled ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def two_factor_enabled
@two_factor_enabled
end
|
#username ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def username
@username
end
|
#using_license_seat ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def using_license_seat
@using_license_seat
end
|
#web_url ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def web_url
@web_url
end
|
#website_url ⇒ Object
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def website_url
@website_url
end
|
14
15
16
|
# File 'lib/support_readiness/gitlab/users.rb', line 14
def work_information
@work_information
end
|
Class Method Details
.block!(client, user) ⇒ Boolean
Blocks a user in GitLab. This will exit on error
457
458
459
460
461
|
# File 'lib/support_readiness/gitlab/users.rb', line 457
def self.block!(client, user)
response = client.connection.post "users/#{user.id}/block"
handle_request_error(1, 'GitLab', response.status, { action: 'Block a user', id: user.id }) unless response.status == 201
true
end
|
.create_token!(client, user, params) ⇒ Object
Creates a personal access token for a user within GitLab. This will exit on error
385
386
387
388
389
|
# File 'lib/support_readiness/gitlab/users.rb', line 385
def self.create_token!(client, user, params)
response = client.connection.post "users/#{user.id}/personal_access_tokens", params.to_json
handle_request_error(1, 'GitLab', response.status, { action: 'Create PAT for a user', id: "#{user.id}" }) unless response.status == 200
Oj.load(response.body)
end
|
.emails(client, user) ⇒ Array
Fetches the email addresses for a user
505
506
507
508
509
|
# File 'lib/support_readiness/gitlab/users.rb', line 505
def self.emails(client, user)
response = client.connection.get "users/#{user.id}/emails"
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
Oj.load(response.body)
end
|
.find(client, uid) ⇒ Hash
Locates a user within GitLab. This will not exit on error (except Authentication errors)
104
105
106
107
108
109
110
|
# File 'lib/support_readiness/gitlab/users.rb', line 104
def self.find(client, uid)
response = client.connection.get "users/#{uid}"
handle_request_error(0, 'GitLab', response.status, { action: 'get', id: uid }) unless response.status == 200
return Users.new(Oj.load(response.body)) if response.status == 200
Oj.load(response.body)
end
|
.find!(client, uid, attributes = []) ⇒ Object
Locates a user within GitLab. This will exit on error
129
130
131
132
133
|
# File 'lib/support_readiness/gitlab/users.rb', line 129
def self.find!(client, uid, attributes = [])
response = client.connection.get "users/#{uid}"
handle_request_error(1, 'GitLab', response.status, { action: 'Find user', id: uid }) unless response.status == 200
Users.new(Oj.load(response.body))
end
|
.gpg_keys(client, user) ⇒ Array
Lists SSH keys for a user.
318
319
320
321
322
|
# File 'lib/support_readiness/gitlab/users.rb', line 318
def self.gpg_keys(client, user)
response = client.connection.get "users/#{user.id}/gpg_keys"
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
Oj.load(response.body)
end
|
.memberships(client, user, params = []) ⇒ Array
Lists all memberships for a user. This method can take a long time to run depending on the parameters used.
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
# File 'lib/support_readiness/gitlab/users.rb', line 226
def self.memberships(client, user, params = [])
array = []
page = 1
loop do
response = client.connection.get "users/#{user.id}/memberships?per_page=100&page=#{page}&#{to_param_string(params)}"
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
body = Oj.load(response.body)
array += body
break if body.count < 100
page += 1
end
array
end
|
.only_maintainer?(client, user) ⇒ Boolean
Determines if a user is the only maintainer on projects they are within
527
528
529
530
531
532
533
|
# File 'lib/support_readiness/gitlab/users.rb', line 527
def self.only_maintainer?(client, user)
Users.projects(client, user).each do |p|
members = Projects.all_members(client, p)
return true if members = members.select { |m| m['access_level'] >= 40 && m['username'] != user.username }.count.zero?
end
false
end
|
.projects(client, user, filters = []) ⇒ Array
Lists all user projects. This method can take a long time to run depending on the parameters used.
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
# File 'lib/support_readiness/gitlab/users.rb', line 261
def self.projects(client, user, filters = [])
array = []
page = 1
loop do
response = client.connection.get "users/#{user.id}/projects?per_page=100&page=#{page}&#{to_param_string(filters)}"
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
body = Oj.load(response.body)
array += body.map { |p| Projects.new(p) }
break if body.count < 100
page += 1
end
array
end
|
.revoke_token!(client, tid) ⇒ Boolean
Revokes a personal access token within GitLab. This will exit on error
409
410
411
412
413
|
# File 'lib/support_readiness/gitlab/users.rb', line 409
def self.revoke_token!(client, tid)
response = client.connection.delete "personal_access_tokens/#{tid}"
handle_request_error(1, 'GitLab', response.status, { action: 'Revoke PAT', id: tid }) unless response.status == 204
true
end
|
.rotate_token!(client, tid) ⇒ Hash
Rotates a personal access token (revokes it and makes a new one with the same user). This will exit on error
433
434
435
436
437
|
# File 'lib/support_readiness/gitlab/users.rb', line 433
def self.rotate_token!(client, tid)
response = client.connection.post "personal_access_tokens/#{tid}/rotate"
handle_request_error(1, 'GitLab', response.status, { action: 'Rotate PAT', id: tid }) unless response.status == 200
Oj.load(response.body)
end
|
.search_by_email(client, email) ⇒ Array
Locates the first 20 users matching a email within GitLab.
175
176
177
178
179
|
# File 'lib/support_readiness/gitlab/users.rb', line 175
def self.search_by_email(client, email)
response = client.connection.get "users?search=#{CGI.escape(email)}"
handle_request_error(0, 'GitLab', response.status, { action: 'Find user by email', id: email }) unless response.status == 200
Oj.load(response.body).map { |u| Users.new(u) }
end
|
.search_by_username(client, username) ⇒ Array
Locates the first 20 users matching a username within GitLab.
152
153
154
155
156
|
# File 'lib/support_readiness/gitlab/users.rb', line 152
def self.search_by_username(client, username)
response = client.connection.get "users?username=#{username}"
handle_request_error(0, 'GitLab', response.status, { action: 'Find user by username', id: username }) unless response.status == 200
Oj.load(response.body).map { |u| Users.new(u) }
end
|
.ssh_keys(client, user) ⇒ Array
Lists SSH keys for a user.
294
295
296
297
298
|
# File 'lib/support_readiness/gitlab/users.rb', line 294
def self.ssh_keys(client, user)
response = client.connection.get "users/#{user.id}/keys"
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
Oj.load(response.body)
end
|
.tokens(client, user, filters = []) ⇒ Array
Lists all personal access tokens for a user. This method can take a long time to run depending on the parameters used.
344
345
346
347
348
349
350
351
352
353
354
355
356
357
|
# File 'lib/support_readiness/gitlab/users.rb', line 344
def self.tokens(client, user, filters = [])
array = []
page = 1
loop do
response = client.connection.get "personal_access_tokens?user_id=#{user.id}&per_page=100&page=#{page}&#{to_param_string(filters)}"
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
body = Oj.load(response.body)
array += body
break if body.count < 100
page += 1
end
array
end
|
.unblock!(client, user) ⇒ Boolean
Unblocks a user in GitLab. This will exit on error
481
482
483
484
485
|
# File 'lib/support_readiness/gitlab/users.rb', line 481
def self.unblock!(client, user)
response = client.connection.post "users/#{user.id}/unblock"
handle_request_error(1, 'GitLab', response.status, { action: 'Unblock a user', id: user.id }) unless response.status == 201
true
end
|
.update!(client, user) ⇒ Object
Updates a user within GitLab. This will exit on error
200
201
202
203
204
|
# File 'lib/support_readiness/gitlab/users.rb', line 200
def self.update!(client, user)
response = client.connection.put "users/#{user.id}", to_clean_json(user)
handle_request_error(1, 'GitLab', response.status, { action: 'Update an user', id: "#{user.id}" }) unless response.status == 200
Users.new(Oj.load(response.body))
end
|