From 22a9d958fed88e2ffbab8277068879be61876735 Mon Sep 17 00:00:00 2001 From: Christian Simon Date: Tue, 8 Jan 2013 22:05:00 +0100 Subject: [PATCH 1/3] Add api for creating/listing/viewing groups --- lib/api.rb | 3 ++- lib/api/entities.rb | 10 +++++++++ lib/api/groups.rb | 50 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 lib/api/groups.rb diff --git a/lib/api.rb b/lib/api.rb index f58b82ff98e..81a5919f1d3 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -11,7 +11,8 @@ module Gitlab format :json error_format :json helpers APIHelpers - + + mount Groups mount Users mount Projects mount Issues diff --git a/lib/api/entities.rb b/lib/api/entities.rb index e5b2685abf5..3010968ed82 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -30,6 +30,16 @@ module Gitlab end end + class Group < Grape::Entity + expose :id, :name, :path, :name, :owner_id, :type + end + + class GroupDetail < Grape::Entity + expose :id, :name, :path, :name, :owner_id, :type + expose :projects, using: Entities::Project + end + + class RepoObject < Grape::Entity expose :name, :commit end diff --git a/lib/api/groups.rb b/lib/api/groups.rb new file mode 100644 index 00000000000..bc856eccdab --- /dev/null +++ b/lib/api/groups.rb @@ -0,0 +1,50 @@ +module Gitlab + # groups API + class Groups < Grape::API + before { authenticate! } + + resource :groups do + # Get a groups list + # + # Example Request: + # GET /groups + get do + @groups = paginate Group + present @groups, with: Entities::Group + + 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 + + if @group.save + present @group, with: Entities::Group + else + not_found! + 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 = Group.find(params[:id]) + present @group, with: Entities::GroupDetail + end + + end + end +end -- GitLab From 3f5e6526038161035284964b8d9a24f8f2f95d75 Mon Sep 17 00:00:00 2001 From: Christian Simon Date: Tue, 8 Jan 2013 22:14:57 +0100 Subject: [PATCH 2/3] Show namespace, path and full path via project API --- lib/api/entities.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 3010968ed82..43529d7811d 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -18,7 +18,7 @@ module Gitlab end class Project < Grape::Entity - expose :id, :name, :description, :default_branch + expose :id, :name, :description, :default_branch, :path, :path_with_namespace, :namespace_id expose :owner, using: Entities::UserBasic expose :private_flag, as: :private expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :created_at -- GitLab From 70cc9008868888a1c79d7b7a4a3b4e0b4ea0b971 Mon Sep 17 00:00:00 2001 From: Christian Simon Date: Tue, 8 Jan 2013 22:15:22 +0100 Subject: [PATCH 3/3] Admin sees all Projects --- lib/api/projects.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 55c81f3158a..a6de40b0c5c 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -9,7 +9,11 @@ module Gitlab # Example Request: # GET /projects get do - @projects = paginate current_user.authorized_projects + if current_user.admin + @projects = paginate Project + else + @projects = paginate current_user.projects + end present @projects, with: Entities::Project end -- GitLab