summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortiagonbotelho <tiagonbotelho@hotmail.com>2016-07-06 17:53:40 +0100
committertiagonbotelho <tiagonbotelho@hotmail.com>2016-07-06 17:53:40 +0100
commit54a234b94062d3fb669fcbdd76ed4460a39eb3ca (patch)
treee61f902fc8905ded4b20f477c4362282e1f18e87
parent34d11a319807481ad9a336914aef86b07f1ba055 (diff)
downloadgitlab-ce-54a234b94062d3fb669fcbdd76ed4460a39eb3ca.tar.gz
adds basic functionality to the new endpoint of the api
-rw-r--r--lib/api/entities.rb16
-rw-r--r--lib/api/helpers.rb17
-rw-r--r--lib/api/projects.rb13
3 files changed, 25 insertions, 21 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 757896fd59b..0f26a1f00a2 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -79,6 +79,12 @@ module API
expose :public_builds
end
+ class SimpleProject < Grape::Entity
+ expose :id
+ expose :name, :name_with_namespace
+ expose :http_url_to_repo
+ end
+
class ProjectMember < UserBasic
expose :access_level do |user, options|
options[:project].project_members.find_by(user_id: user.id).access_level
@@ -328,12 +334,18 @@ module API
end
end
+ class SimpleProjectWithAccess < SimpleProject
+ expose :permissions do
+ expose :project_access, using: Entities::ProjectAccess do |project, options|
+ project.project_members.find_by(user_id: options[:user].id)
+ end
+ end
+ end
+
class ProjectWithAccess < Project
expose :permissions do
expose :project_access, using: Entities::ProjectAccess do |project, options|
- project = Project.find_by(project[:id])
project.project_members.find_by(user_id: options[:user].id)
- ]
end
expose :group_access, using: Entities::GroupAccess do |project, options|
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 3a1837effd8..77e407b54c5 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -287,23 +287,6 @@ module API
# Projects helpers
- def filter_params(projects)
- project_entries = []
-
- # Removes the redundant information of the object
- projects.each do |project|
- entry = {
- id: project.id,
- http_url_to_repo: project.http_url_to_repo,
- name_with_namespace: project.name_with_namespace
- }
-
- project_entries << entry
- end
-
- project_entries
- end
-
def filter_projects(projects)
# If the archived parameter is passed, limit results accordingly
if params[:archived].present?
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index deade7cad90..c1e66b239aa 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -25,11 +25,20 @@ module API
@projects = current_user.authorized_projects
@projects = filter_projects(@projects)
@projects = paginate @projects
- @projects = filter_params(@projects)
- puts present @projects, with: Entities::ProjectWithAccess, user: current_user
present @projects, with: Entities::ProjectWithAccess, user: current_user
end
+ # Get a simplified project list for authenticated user
+ #
+ # Example Request:
+ # GET /projects/simple
+ get '/simple' do
+ @projects = current_user.authorized_projects
+ @projects = filter_projects(@projects)
+ @projects = paginate @projects
+ present @projects, with: Entities::SimpleProjectWithAccess, user: current_user
+ end
+
# Get an owned projects list for authenticated user
#
# Example Request: