Skip to content

Commit

Permalink
Adding user_teams api
Browse files Browse the repository at this point in the history
GITLAB-698 (GITLAB-116)
  • Loading branch information
Izaak Alpert committed Jun 13, 2013
1 parent 53d7a8a commit b4444fc
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/gitlab/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Client < API
Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}

include Gitlab::Client::Users
include Gitlab::Client::UserTeams
include Gitlab::Client::Issues
include Gitlab::Client::Notes
include Gitlab::Client::Milestones
Expand Down
130 changes: 130 additions & 0 deletions lib/gitlab/client/user_teams.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
class Gitlab::Client
# Defines methods related to users.
module UserTeams
# Gets a list of users_teams.
#
# @example
# Gitlab.user_teams.user_teams
#
# @return [Array<Gitlab::ObjectifiedHash>]
def user_teams(options={})
get("/user_teams")
end

# Gets information about a user team.
#
# @example
# Gitlab.user_teams.user_teams(2)
#
# @param [Integer] (required) The ID of a user_team.
# @return [Gitlab::ObjectifiedHash]
def user_team(team_id)
get("/user_teams/#{team_id}")
end

# Creates new user team owned by user. Available only for admins.
# Requires authentication from an admin account.
#
# @param [String] (required) - new user team name
# @param [String] (required) - new user team internal name
# @return [Gitlab::ObjectifiedHash] Information about created user.
def create_user_team(name, path)
post("/user_teams", :body => {:name => name, :path=> path})
end

# Get a list of project team members. If user id is specified get a specific user
#
# @example
# Gitlab.user_teams.teams_members(1)
# Gitlab.user_teams.teams_members(1,3)
#
# @param [Integer] (required) - The ID of a user_team
# @param [Integer] (optional) - The ID of a user
# @return [Gitlab::ObjectifiedHash]
def user_team_members(id, user_id = nil)
user_id.to_i.zero? ? get("/user_teams/#{id}/members") : get("/user_teams/#{id}/members/#{user_id}")
end

# Adds a user to user team.
#
# @example
# Gitlab.user_teams.add_team_member(1, 2, 40)
#
# @param [Integer] (required) The team id to add a member to
# @param [Integer] (required) The user id of the user to add to the team
# @param [Integer] (required) access_level Project access level
# @return [Array<Gitlab::ObjectifiedHash>] Information about added team member.
def add_team_member(team_id, user_id, access_level)
post("/user_teams/#{team_id}/members", :body => {:user_id => user_id, :access_level => access_level})
end

# Removes user from user team.
#
# @example
# Gitlab.user_teams.remove_team_member(1, 2)
#
# @param [Integer] (required) The team ID.
# @param [Integer] (required) id The ID of a user.
# @return [Array<Gitlab::ObjectifiedHash>] Information about removed team member.
def remove_team_member(team_id, user_id)
delete("/user_teams/#{team_id}/members/#{user_id}")
end

# Get a list of user team projects. If project_id is specified gets the project specified
#
# @example
# Gitlab.user_teams.user_teams_projects(1)
# Gitlab.user_teams.user_teams_projects(1,2)
#
# @param [Integer] (required) - The ID of a user_team
# @param [Integer] (optional - The ID of a project
# @return [Array<Gitlab::ObjectifiedHash>]
def user_teams_projects(team_id, project_id = nil)
project_id.to_i.zero? ? get("/user_teams/#{team_id}/projects") : get("/user_teams/#{team_id}/projects/#{project_id}")
end

# Gets a user team project.
#
# @example
# Gitlab.user_teams.user_teams(2)
#
# @param [Integer] (required) The ID of a user_team.
# @param [Integer] (required) The ID of a project.
# @return [Gitlab::ObjectifiedHash]
def user_teams_project(team_id, project_id)
get("/user_teams/#{team_id}/projects/#{project_id}")
end



# Add user team project
# Adds a project to a user team.
#
# @example
# Gitlab.user_teams.add_team_project(1, 2, 40)
#
# @param [Integer] (required) The ID of a user team
# @param [Integer] (required) The ID of a project to add
# @param [Integer] (required) greatest_access_level (required) - Maximum project access level
# @return [Array<Gitlab::ObjectifiedHash>] Information about added team project.
def add_team_project(team_id, project_id, access_level)
post("/user_teams/#{team_id}/projects", :body => {:project_id => project_id, :access_level => access_level})
end

# Remove user team project
# Removes project from user team.
#
# @example
# Gitlab.user_teams.remove_team_project(1, 2)
#
# @param [Integer] (required) The ID of a user team
# @param [Integer] (required) The ID of a team project
# @return [Array<Gitlab::ObjectifiedHash>] Information about removed team project.
def remove_team_project(team_id, user_id)
delete("/user_teams/#{team_id}/projects/#{project_id}")
end

end


end
1 change: 1 addition & 0 deletions spec/fixtures/user_team.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id":1,"name":"Foo","path":"foo","owner_id":1}
1 change: 1 addition & 0 deletions spec/fixtures/user_team_member.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id":1,"username":"jsmith","email":"jsmith@example.com","name":"John Smith","state":"active","created_at":"2013-06-11T18:08:28Z","access_level":40}
1 change: 1 addition & 0 deletions spec/fixtures/user_team_members.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":1,"username":"jsmith","email":"john@example.com","name":"John Smith","state":"active","created_at":"2013-06-11T18:12:20Z","access_level":40},{"id":2,"username":"jack","email":"jack@example.com","name":"Jack Smith","state":"active","created_at":"2013-06-11T18:12:24Z","access_level":20},{"id":3,"username":"wilma","email":"wilma@mayerblanda.ca","name":"Beatrice Jewess","state":"active","created_at":"2013-06-11T18:12:26Z","access_level":10},{"id":6,"username":"mvon","email":"aliza_stark@schmeler.info","name":"Michale Von","state":"active","created_at":"2013-06-11T18:08:28Z","access_level":40}]
1 change: 1 addition & 0 deletions spec/fixtures/user_teams.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":1,"name":"Foo","path":"foo","owner_id":1}]
131 changes: 131 additions & 0 deletions spec/gitlab/client/user_teams_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
require 'spec_helper'

describe Gitlab::Client do
describe ".user_teams" do
before do
stub_get("/user_teams/1", "user_team")
@user_team = Gitlab.user_team(1)
end

it "should get the correct resource" do
a_get("/user_teams/1").should have_been_made
end

it "should return information about a user_team" do
@user_team.name.should == "Foo"
end
end

describe ".user_team" do
before do
stub_get("/user_teams", "user_teams")
@user_teams = Gitlab.user_teams
end

it "should get the correct resource" do
a_get("/user_teams").should have_been_made
end

it "should return an array of user_teams" do
@user_teams.should be_an Array
@user_teams.first.name.should == "Foo"
end
end


describe ".create_user_team" do
before do
stub_post("/user_teams", "user_team")
@user_team = Gitlab.create_user_team("Foo", "foo")
end

it "should get the correct resource" do
body = {:name => "Foo", :path=> "foo"}
a_post("/user_teams").with(:body => body).should have_been_made
end

it "should return information about a created user" do
@user_team.name.should == "Foo"
end
end


describe ".team_members" do
before do
stub_get("/user_teams/3/members", "user_team_members")
@team_members = Gitlab.user_team_members(3)
end

it "should get the correct resource" do
a_get("/user_teams/3/members").should have_been_made
end

it "should return an array of team members" do
@team_members.should be_an Array
@team_members.first.name.should == "John Smith"
end
end

describe ".team_member" do
before do
stub_get("/user_teams/3/members/1", "user_team_member")
@team_members = Gitlab.user_team_members(3, 1)
end

it "should get the correct resource" do
a_get("/user_teams/3/members/1").should have_been_made
end

it "should return information about a team member" do
@team_members.name.should == "John Smith"
end
end
=begin
describe ".add_team_member" do
before do
stub_post("/projects/3/members", "team_member")
@team_member = Gitlab.add_team_member(3, 1, 40)
end
it "should get the correct resource" do
a_post("/projects/3/members").
with(:body => {:user_id => '1', :access_level => '40'}).should have_been_made
end
it "should return information about an added team member" do
@team_member.name.should == "John Smith"
end
end
describe ".edit_team_member" do
before do
stub_put("/projects/3/members/1", "team_member")
@team_member = Gitlab.edit_team_member(3, 1, 40)
end
it "should get the correct resource" do
a_put("/projects/3/members/1").
with(:body => {:access_level => '40'}).should have_been_made
end
it "should return information about an edited team member" do
@team_member.name.should == "John Smith"
end
end
describe ".remove_team_member" do
before do
stub_delete("/projects/3/members/1", "team_member")
@team_member = Gitlab.remove_team_member(3, 1)
end
it "should get the correct resource" do
a_delete("/projects/3/members/1").should have_been_made
end
it "should return information about a removed team member" do
@team_member.name.should == "John Smith"
end
end
=end
end

0 comments on commit b4444fc

Please sign in to comment.