Fix groups api: differ between users and admin

This commit is contained in:
Christian Simon 2013-02-01 15:00:12 +01:00
parent fc0c692870
commit 149ccd5d91
2 changed files with 50 additions and 44 deletions

View file

@ -33,7 +33,7 @@ module Gitlab
end end
class Group < Grape::Entity class Group < Grape::Entity
expose :id, :name, :path, :name, :owner_id, :type expose :id, :name, :path, :owner_id
end end
class GroupDetail < Grape::Entity class GroupDetail < Grape::Entity

View file

@ -3,48 +3,54 @@ module Gitlab
class Groups < Grape::API class Groups < Grape::API
before { authenticate! } before { authenticate! }
resource :groups do resource :groups do
# Get a groups list # Get a groups list
# #
# Example Request: # Example Request:
# GET /groups # GET /groups
get do get do
@groups = paginate Group if current_user.admin
present @groups, with: Entities::Group @groups = paginate Group
else
@groups = paginate current_user.groups
end
present @groups, with: Entities::Group
end
end # Create group. Available only for admin
#
# Parameters:
# name (required) - Name
# path (required) - Path
# Example Request:
# POST /groups
post do
authenticated_as_admin!
attrs = attributes_for_keys [:name, :path]
@group = Group.new(attrs)
@group.owner = current_user
# Create group. Available only for admin if @group.save
# present @group, with: Entities::Group
# Parameters: else
# name (required) - Name not_found!
# path (required) - Path end
# Example Request: end
# POST /groups
post do
authenticated_as_admin!
attrs = attributes_for_keys [:name, :path]
@group = Group.new(attrs)
@group.owner = current_user
if @group.save # Get a single group, with containing projects
present @group, with: Entities::Group #
else # Parameters:
not_found! # id (required) - The ID of a group
end # Example Request:
end # GET /groups/:id
get ":id" do
# Get a single group, with containing projects @group = Group.find(params[:id])
# if current_user.admin or current_user.groups.include? @group
# Parameters: present @group, with: Entities::GroupDetail
# id (required) - The ID of a group else
# Example Request: not_found!
# GET /groups/:id end
get ":id" do end
@group = Group.find(params[:id]) end
present @group, with: Entities::GroupDetail
end
end
end end
end end