summaryrefslogtreecommitdiff
path: root/lib/ci
diff options
context:
space:
mode:
authorValery Sizov <vsv2711@gmail.com>2015-09-15 13:50:24 +0300
committerValery Sizov <vsv2711@gmail.com>2015-09-15 13:50:24 +0300
commit22bf844869bde4e480d981b2f267bc692e701eb4 (patch)
tree09e0ff53115309652e61df7ef712a37daf41bee4 /lib/ci
parent9a3d0f1d92ee99792b40c401f83121adb8fd3387 (diff)
downloadgitlab-ce-22bf844869bde4e480d981b2f267bc692e701eb4.tar.gz
fix specs. Stage 3
Diffstat (limited to 'lib/ci')
-rw-r--r--lib/ci/api/entities.rb6
-rw-r--r--lib/ci/api/projects.rb27
2 files changed, 19 insertions, 14 deletions
diff --git a/lib/ci/api/entities.rb b/lib/ci/api/entities.rb
index 1277d68a364..07f25129663 100644
--- a/lib/ci/api/entities.rb
+++ b/lib/ci/api/entities.rb
@@ -34,8 +34,12 @@ module Ci
end
class Project < Grape::Entity
- expose :id, :name, :timeout, :token, :default_ref, :gitlab_url, :path,
+ expose :id, :name, :token, :default_ref, :gitlab_url, :path,
:always_build, :polling_interval, :public, :ssh_url_to_repo, :gitlab_id
+
+ expose :timeout do |model|
+ model.timeout
+ end
end
class RunnerProject < Grape::Entity
diff --git a/lib/ci/api/projects.rb b/lib/ci/api/projects.rb
index 556de3bff9f..138667c980f 100644
--- a/lib/ci/api/projects.rb
+++ b/lib/ci/api/projects.rb
@@ -17,7 +17,7 @@ module Ci
project = Ci::Project.find(params[:project_id])
- unauthorized! unless current_user.can_manage_project?(project.gitlab_id)
+ unauthorized! unless can?(current_user, :manage_project, project.gl_project)
web_hook = project.web_hooks.new({ url: params[:web_hook] })
@@ -34,9 +34,10 @@ module Ci
# Example Request:
# GET /projects
get do
- gitlab_projects = Ci::Project.from_gitlab(
- current_user, :authorized, { page: params[:page], per_page: params[:per_page], ci_enabled_first: true }
- )
+ gitlab_projects = current_user.authorized_projects
+ gitlab_projects = filter_projects(gitlab_projects)
+ gitlab_projects = paginate gitlab_projects
+
ids = gitlab_projects.map { |project| project.id }
projects = Ci::Project.where("gitlab_id IN (?)", ids).load
@@ -48,9 +49,10 @@ module Ci
# Example Request:
# GET /projects/owned
get "owned" do
- gitlab_projects = Ci::Project.from_gitlab(
- current_user, :owned, { page: params[:page], per_page: params[:per_page], ci_enabled_first: true }
- )
+ gitlab_projects = current_user.owned_projects
+ gitlab_projects = filter_projects(gitlab_projects)
+ gitlab_projects = paginate gitlab_projects
+
ids = gitlab_projects.map { |project| project.id }
projects = Ci::Project.where("gitlab_id IN (?)", ids).load
@@ -65,8 +67,7 @@ module Ci
# GET /projects/:id
get ":id" do
project = Ci::Project.find(params[:id])
-
- unauthorized! unless can?(current_user, :read_project, gl_project)
+ unauthorized! unless can?(current_user, :read_project, project.gl_project)
present project, with: Entities::Project
end
@@ -118,7 +119,7 @@ module Ci
put ":id" do
project = Ci::Project.find(params[:id])
- unauthorized! unless can?(current_user, :manage_project, gl_project)
+ unauthorized! unless can?(current_user, :manage_project, project.gl_project)
attrs = attributes_for_keys [:name, :gitlab_id, :path, :gitlab_url, :default_ref, :ssh_url_to_repo]
@@ -144,7 +145,7 @@ module Ci
delete ":id" do
project = Ci::Project.find(params[:id])
- unauthorized! unless can?(current_user, :manage_project, gl_project)
+ unauthorized! unless can?(current_user, :manage_project, project.gl_project)
project.destroy
end
@@ -160,7 +161,7 @@ module Ci
project = Ci::Project.find(params[:id])
runner = Ci::Runner.find(params[:runner_id])
- unauthorized! unless can?(current_user, :manage_project, gl_project)
+ unauthorized! unless can?(current_user, :manage_project, project.gl_project)
options = {
project_id: project.id,
@@ -188,7 +189,7 @@ module Ci
project = Ci::Project.find(params[:id])
runner = Ci::Runner.find(params[:runner_id])
- unauthorized! unless can?(current_user, :manage_project, gl_project)
+ unauthorized! unless can?(current_user, :manage_project, project.gl_project)
options = {
project_id: project.id,