summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortiagonbotelho <tiagonbotelho@hotmail.com>2016-07-06 10:15:41 +0100
committertiagonbotelho <tiagonbotelho@hotmail.com>2016-07-06 10:15:41 +0100
commit34d11a319807481ad9a336914aef86b07f1ba055 (patch)
treeea9f31edeababa943f5d310524d03db89687834b
parent06c7d6f3a863a1ac8d9f47fed8423387d6e672a6 (diff)
downloadgitlab-ce-34d11a319807481ad9a336914aef86b07f1ba055.tar.gz
implements filter_params
-rw-r--r--lib/api/entities.rb2
-rw-r--r--lib/api/helpers.rb17
-rw-r--r--lib/api/projects.rb2
3 files changed, 21 insertions, 0 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 8cc4368b5c2..757896fd59b 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -331,7 +331,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 77e407b54c5..3a1837effd8 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 0cc1edd65c8..deade7cad90 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