提交 a8cf4e13 编写于 作者: T tiagonbotelho

adds basic functionality to the new endpoint of the api

上级 e1c5eb48
...@@ -90,6 +90,12 @@ module API ...@@ -90,6 +90,12 @@ module API
end end
end end
class SimpleProject < Grape::Entity
expose :id
expose :name, :name_with_namespace
expose :http_url_to_repo
end
class ProjectMember < UserBasic class ProjectMember < UserBasic
expose :access_level do |user, options| expose :access_level do |user, options|
options[:project].project_members.find_by(user_id: user.id).access_level options[:project].project_members.find_by(user_id: user.id).access_level
...@@ -341,12 +347,18 @@ module API ...@@ -341,12 +347,18 @@ module API
end end
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 class ProjectWithAccess < Project
expose :permissions do expose :permissions do
expose :project_access, using: Entities::ProjectAccess do |project, options| 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) project.project_members.find_by(user_id: options[:user].id)
]
end end
expose :group_access, using: Entities::GroupAccess do |project, options| expose :group_access, using: Entities::GroupAccess do |project, options|
......
...@@ -287,23 +287,6 @@ module API ...@@ -287,23 +287,6 @@ module API
# Projects helpers # 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) def filter_projects(projects)
# If the archived parameter is passed, limit results accordingly # If the archived parameter is passed, limit results accordingly
if params[:archived].present? if params[:archived].present?
......
...@@ -25,11 +25,20 @@ module API ...@@ -25,11 +25,20 @@ module API
@projects = current_user.authorized_projects @projects = current_user.authorized_projects
@projects = filter_projects(@projects) @projects = filter_projects(@projects)
@projects = paginate @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 present @projects, with: Entities::ProjectWithAccess, user: current_user
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 # Get an owned projects list for authenticated user
# #
# Example Request: # Example Request:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册