Files
gitlabhq/lib/api/groups.rb
T
Dmitriy Zaporozhets c84b14d2a1 Merge branch 'master' of dev.gitlab.org:gitlab/gitlabhq into ce-to-ee
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>

Conflicts:
	app/controllers/autocomplete_controller.rb
	app/controllers/omniauth_callbacks_controller.rb
	app/controllers/projects/services_controller.rb
	app/helpers/projects_helper.rb
	app/services/audit_event_service.rb
	db/schema.rb
	doc/api/users.md
	doc/update/6.x-or-7.x-to-7.13.md
	features/project/project.feature
2015-07-14 15:40:46 +02:00

99 lines
2.8 KiB
Ruby

module API
# groups API
class Groups < Grape::API
before { authenticate! }
resource :groups do
# Get a groups list
#
# Example Request:
# GET /groups
get do
@groups = if current_user.admin
Group.all
else
current_user.groups
end
@groups = @groups.search(params[:search]) if params[:search].present?
@groups = paginate @groups
present @groups, with: Entities::Group
end
# Create group. Available only for users who can create groups.
#
# Parameters:
# name (required) - The name of the group
# path (required) - The path of the group
# Example Request:
# POST /groups
post do
authorize! :create_group, current_user
required_attributes! [:name, :path]
attrs = attributes_for_keys [:name, :path, :description]
@group = Group.new(attrs)
if @group.save
# NOTE: add backwards compatibility for single ldap link
ldap_attrs = attributes_for_keys [:ldap_cn, :ldap_access]
if ldap_attrs.present?
@group.ldap_group_links.create({
cn: ldap_attrs[:ldap_cn],
group_access: ldap_attrs[:ldap_access]
})
end
@group.add_owner(current_user)
present @group, with: Entities::Group
else
render_api_error!("Failed to save group #{@group.errors.messages}", 400)
end
end
# Get a single group, with containing projects
#
# Parameters:
# id (required) - The ID of a group
# Example Request:
# GET /groups/:id
get ":id" do
group = find_group(params[:id])
present group, with: Entities::GroupDetail
end
# Remove group
#
# Parameters:
# id (required) - The ID of a group
# Example Request:
# DELETE /groups/:id
delete ":id" do
group = find_group(params[:id])
authorize! :admin_group, group
DestroyGroupService.new(group, current_user).execute
end
# Transfer a project to the Group namespace
#
# Parameters:
# id - group id
# project_id - project id
# Example Request:
# POST /groups/:id/projects/:project_id
post ":id/projects/:project_id" do
authenticated_as_admin!
group = Group.find_by(id: params[:id])
project = Project.find(params[:project_id])
result = ::Projects::TransferService.new(project, current_user).execute(group)
if result
present group
else
render_api_error!("Failed to transfer project #{project.errors.messages}", 400)
end
end
end
end
end