diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 301dbb688a7894e508210893aa066f80a72c5d4a..f00a4ac2ed694e005ae379c6fdd6f55784b9e74a 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -344,7 +344,9 @@ 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 77e407b54c54f95920fb8b22a4375a4bcc06eb8b..3a1837effd8a234bc8433d9c45bb6872be79fd13 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -287,6 +287,23 @@ 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 0cc1edd65c83566d96b91a83be01c3fdec70de68..deade7cad9051e5e78e8c4e6716648c16ad3d6b1 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -25,6 +25,8 @@ 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