From e1c5eb480e10329245760edd0760a5b3cb929240 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Wed, 6 Jul 2016 10:15:41 +0100 Subject: implements filter_params --- lib/api/entities.rb | 2 ++ lib/api/helpers.rb | 17 +++++++++++++++++ lib/api/projects.rb | 2 ++ 3 files changed, 21 insertions(+) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 301dbb688a7..f00a4ac2ed6 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 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 -- cgit v1.2.1 From a8cf4e13b33da8d71e16874ebf3dce9ca9d40b76 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Wed, 6 Jul 2016 17:53:40 +0100 Subject: adds basic functionality to the new endpoint of the api --- lib/api/entities.rb | 16 ++++++++++++++-- lib/api/helpers.rb | 17 ----------------- lib/api/projects.rb | 13 +++++++++++-- 3 files changed, 25 insertions(+), 21 deletions(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index f00a4ac2ed6..951cca248a1 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -90,6 +90,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 @@ -341,12 +347,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: -- cgit v1.2.1 From f5d92d120edbd6bc730f10293a5847dd9b0e22fc Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Fri, 8 Jul 2016 09:47:09 +0100 Subject: changes the usage of simpleprojectdetails to already implemented basicprojectsdetails and changes the url to a more reader friendly format --- lib/api/entities.rb | 8 +------- lib/api/projects.rb | 17 +++++------------ 2 files changed, 6 insertions(+), 19 deletions(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 951cca248a1..0def1ed2823 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -90,12 +90,6 @@ 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 @@ -347,7 +341,7 @@ module API end end - class SimpleProjectWithAccess < SimpleProject + class BasicProjectWithAccess < BasicProjectDetails expose :permissions do expose :project_access, using: Entities::ProjectAccess do |project, options| project.project_members.find_by(user_id: options[:user].id) diff --git a/lib/api/projects.rb b/lib/api/projects.rb index c1e66b239aa..c46764c4897 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -25,18 +25,11 @@ module API @projects = current_user.authorized_projects @projects = filter_projects(@projects) @projects = paginate @projects - 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 + if params["format"] + present @projects, with: Entities::BasicProjectWithAccess, user: current_user + else + present @projects, with: Entities::ProjectWithAccess, user: current_user + end end # Get an owned projects list for authenticated user -- cgit v1.2.1 From 87d4d76dc03b54a22cb29c71eaa962b7265f5319 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Fri, 8 Jul 2016 12:06:39 +0100 Subject: fixes missing field on basicprojectdetails --- lib/api/entities.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 0def1ed2823..b62afb4bb4c 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -54,6 +54,7 @@ module API class BasicProjectDetails < Grape::Entity expose :id + expose :http_url_to_repo, :web_url expose :name, :name_with_namespace expose :path, :path_with_namespace end -- cgit v1.2.1 From c4dc0f52c3fbb0b195a23645ebdc78991abb332d Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Mon, 11 Jul 2016 16:05:06 +0100 Subject: adds test to check json fields on simple request and changes the url request format --- lib/api/projects.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/projects.rb b/lib/api/projects.rb index c46764c4897..7aea553bdca 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -25,7 +25,7 @@ module API @projects = current_user.authorized_projects @projects = filter_projects(@projects) @projects = paginate @projects - if params["format"] + if params["simple"] present @projects, with: Entities::BasicProjectWithAccess, user: current_user else present @projects, with: Entities::ProjectWithAccess, user: current_user -- cgit v1.2.1 From be3409ab7ad3a8bf7b0c9eecb588598869459741 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Tue, 12 Jul 2016 10:43:08 +0100 Subject: changes string to symbol in param --- lib/api/projects.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 7aea553bdca..844547665ef 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -25,7 +25,7 @@ module API @projects = current_user.authorized_projects @projects = filter_projects(@projects) @projects = paginate @projects - if params["simple"] + if params[:simple] present @projects, with: Entities::BasicProjectWithAccess, user: current_user else present @projects, with: Entities::ProjectWithAccess, user: current_user -- cgit v1.2.1 From ded67d3b68b438a71bb3771865981c3c7d0b3730 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Wed, 6 Jul 2016 10:15:41 +0100 Subject: implements filter_params --- lib/api/entities.rb | 2 ++ lib/api/helpers.rb | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index b62afb4bb4c..8673350b927 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -353,7 +353,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? -- cgit v1.2.1 From 2179c4052e034e62867749043d53bae7eaf048d7 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Wed, 6 Jul 2016 17:53:40 +0100 Subject: adds basic functionality to the new endpoint of the api --- lib/api/entities.rb | 8 ++++++-- lib/api/helpers.rb | 17 ----------------- lib/api/projects.rb | 11 +++++++++++ 3 files changed, 17 insertions(+), 19 deletions(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 8673350b927..1ecf50cd595 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 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 844547665ef..9448af92a98 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: -- cgit v1.2.1 From 8d9e649c241be6a62a47201b57863a78c94e6f01 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Fri, 8 Jul 2016 09:47:09 +0100 Subject: changes the usage of simpleprojectdetails to already implemented basicprojectsdetails and changes the url to a more reader friendly format --- lib/api/entities.rb | 6 ------ lib/api/projects.rb | 11 ----------- 2 files changed, 17 deletions(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 1ecf50cd595..b62afb4bb4c 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -91,12 +91,6 @@ 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 diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 9448af92a98..844547665ef 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -32,17 +32,6 @@ 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: -- cgit v1.2.1 From 563b303bde6701fc91351701db651e8da68f9b80 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Tue, 12 Jul 2016 17:32:40 +0100 Subject: removes basicprojectwithaccess and replaces it with basicprojectdetails --- lib/api/.projects.rb.swn | Bin 0 -> 28672 bytes lib/api/entities.rb | 8 -------- lib/api/projects.rb | 2 +- 3 files changed, 1 insertion(+), 9 deletions(-) create mode 100644 lib/api/.projects.rb.swn (limited to 'lib/api') diff --git a/lib/api/.projects.rb.swn b/lib/api/.projects.rb.swn new file mode 100644 index 00000000000..890811564d2 Binary files /dev/null and b/lib/api/.projects.rb.swn differ diff --git a/lib/api/entities.rb b/lib/api/entities.rb index b62afb4bb4c..8e03c08f47b 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -342,14 +342,6 @@ module API end end - class BasicProjectWithAccess < BasicProjectDetails - 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| diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 844547665ef..6d2a6f3946c 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -26,7 +26,7 @@ module API @projects = filter_projects(@projects) @projects = paginate @projects if params[:simple] - present @projects, with: Entities::BasicProjectWithAccess, user: current_user + present @projects, with: Entities::BasicProjectDetails, user: current_user else present @projects, with: Entities::ProjectWithAccess, user: current_user end -- cgit v1.2.1 From 3e44aac08dc744915b932a0a7bed0d3f3ab3ab6b Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Tue, 12 Jul 2016 17:36:22 +0100 Subject: fixes test according to four-phase test pattern --- lib/api/.projects.rb.swn | Bin 28672 -> 28672 bytes 1 file changed, 0 insertions(+), 0 deletions(-) (limited to 'lib/api') diff --git a/lib/api/.projects.rb.swn b/lib/api/.projects.rb.swn index 890811564d2..6a9e5f146ea 100644 Binary files a/lib/api/.projects.rb.swn and b/lib/api/.projects.rb.swn differ -- cgit v1.2.1 From 02e38466726730edd212411214a92319fe31df60 Mon Sep 17 00:00:00 2001 From: tiagonbotelho Date: Wed, 13 Jul 2016 10:30:13 +0100 Subject: deletes swn file --- lib/api/.projects.rb.swn | Bin 28672 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 lib/api/.projects.rb.swn (limited to 'lib/api') diff --git a/lib/api/.projects.rb.swn b/lib/api/.projects.rb.swn deleted file mode 100644 index 6a9e5f146ea..00000000000 Binary files a/lib/api/.projects.rb.swn and /dev/null differ -- cgit v1.2.1