diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 8673350b927e0b7753b65bcfcf663de9d66fd274..1ecf50cd5957e5cba6b4fb530bb00dc613bbaa6e 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -91,6 +91,12 @@ module API end 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 @@ -353,9 +359,7 @@ module API 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 3a1837effd8a234bc8433d9c45bb6872be79fd13..77e407b54c54f95920fb8b22a4375a4bcc06eb8b 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 844547665ef5d41a370fd5b3b1f42c394aeb58f0..9448af92a98ec1f36359c09333bf70716af81f6f 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -32,6 +32,17 @@ module API end 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: