Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add memberships endpoint #648

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/gitlab/client/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,16 @@ def revoke_user_impersonation_token(user_id, impersonation_token_id)
delete("/users/#{user_id}/impersonation_tokens/#{impersonation_token_id}")
end

# Lists all projects and groups a user is a member of
#
# @example
# Gitlab.memberships(2)
#
# @param [Integer] user_id The ID of the user.
def memberships(user_id)
get("/users/#{user_id}/memberships")
end

# Revoke a personal access token
#
# @example
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/memberships.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"source_id": 1,"source_name": "Project one","source_type": "Project","access_level": "20"},{"source_id": 3,"source_name": "Group three","source_type": "Namespace","access_level": "20"}]
18 changes: 18 additions & 0 deletions spec/gitlab/client/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,24 @@
end
end

describe '.memberships' do
before do
stub_get('/user/2/memberships', 'memberships')
@memberships = Gitlab.memberships(2)
end

it 'gets the correct resource' do
expect(a_get('/user/2/memberships')).to have_been_made
end

it 'returns an information about all project and groups of user' do
expect(@memberships.first.source_id).to eq 1
expect(@memberships.first.source_name).to eq 'Project one'
expect(@memberships.first.source_type).to eq 'Project'
expect(@memberships.first.access_level).to eq 20
end
end

describe 'get all personal access tokens' do
describe 'get all' do
before do
Expand Down
Loading