summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <vsv2711@gmail.com>2015-05-15 10:51:44 +0300
committerValery Sizov <vsv2711@gmail.com>2015-05-15 10:51:44 +0300
commit6fcc731e52cee1e8a6c264f526da8da5e455e407 (patch)
treeb8665dae36c42d48fa7f53b1692e881006807cd1
parentda8c9887459f53401ff575ad49de54c05963cb2c (diff)
downloadgitlab-ci-6fcc731e52cee1e8a6c264f526da8da5e455e407.tar.gz
public accessible build and commit
-rw-r--r--app/controllers/application_controller.rb12
-rw-r--r--app/controllers/builds_controller.rb7
-rw-r--r--app/controllers/commits_controller.rb5
-rw-r--r--app/controllers/projects_controller.rb11
-rw-r--r--app/views/builds/_build.html.haml2
-rw-r--r--app/views/builds/show.html.haml4
-rw-r--r--app/views/commits/show.html.haml2
-rw-r--r--spec/factories/projects.rb10
-rw-r--r--spec/features/builds_spec.rb16
-rw-r--r--spec/features/commits_spec.rb43
10 files changed, 78 insertions, 34 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index c412a45..316fd63 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -36,6 +36,18 @@ class ApplicationController < ActionController::Base
end
end
+ def authenticate_public_page!
+ unless project.public
+ unless current_user
+ redirect_to(new_user_sessions_path(return_to: request.fullpath)) and return
+ end
+
+ unless current_user.can_access_project?(project.gitlab_id)
+ page_404 and return
+ end
+ end
+ end
+
def authenticate_token!
unless project.valid_token?(params[:token])
return head(403)
diff --git a/app/controllers/builds_controller.rb b/app/controllers/builds_controller.rb
index fc9ec18..9fbdb60 100644
--- a/app/controllers/builds_controller.rb
+++ b/app/controllers/builds_controller.rb
@@ -1,7 +1,8 @@
class BuildsController < ApplicationController
- before_filter :authenticate_user!, except: [:status]
+ before_filter :authenticate_user!, except: [:status, :show]
+ before_filter :authenticate_public_page!, only: :show
before_filter :project
- before_filter :authorize_access_project!, except: [:status]
+ before_filter :authorize_access_project!, except: [:status, :show]
before_filter :authorize_manage_project!, except: [:status, :show, :retry, :cancel]
before_filter :authorize_project_developer!, only: [:retry, :cancel]
before_filter :build, except: [:show]
@@ -38,7 +39,7 @@ class BuildsController < ApplicationController
if @build.commands.blank?
return page_404
end
-
+
build = Build.retry(@build)
if params[:return_to]
diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb
index e541ac0..06c24d6 100644
--- a/app/controllers/commits_controller.rb
+++ b/app/controllers/commits_controller.rb
@@ -1,8 +1,9 @@
class CommitsController < ApplicationController
- before_filter :authenticate_user!, except: [:status]
+ before_filter :authenticate_user!, except: [:status, :show]
+ before_filter :authenticate_public_page!, only: :show
before_filter :project
before_filter :commit
- before_filter :authorize_access_project!, except: [:status]
+ before_filter :authorize_access_project!, except: [:status, :show]
def show
@builds = @commit.builds
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 57a29fe..7051045 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -2,6 +2,7 @@ class ProjectsController < ApplicationController
PROJECTS_PER_PAGE = 100
before_filter :authenticate_user!, except: [:build, :badge, :index, :show]
+ before_filter :authenticate_public_page!, only: :show
before_filter :project, only: [:build, :integration, :show, :badge, :edit, :update, :destroy, :toggle_shared_runners]
before_filter :authorize_access_project!, except: [:build, :gitlab, :badge, :index, :show, :new, :create]
before_filter :authorize_manage_project!, only: [:edit, :integration, :update, :destroy, :toggle_shared_runners]
@@ -30,16 +31,6 @@ class ProjectsController < ApplicationController
end
def show
- unless @project.public
- unless current_user
- redirect_to(new_user_sessions_path(return_to: request.fullpath)) and return
- end
-
- unless current_user.can_access_project?(@project.gitlab_id)
- page_404 and return
- end
- end
-
@ref = params[:ref]
@commits = @project.commits
diff --git a/app/views/builds/_build.html.haml b/app/views/builds/_build.html.haml
index 7328e58..1c93576 100644
--- a/app/views/builds/_build.html.haml
+++ b/app/views/builds/_build.html.haml
@@ -39,7 +39,7 @@
#{build.coverage}%
%td
- - if defined?(controls) && current_user.has_developer_access?(@project.gitlab_id)
+ - if defined?(controls) && current_user && current_user.has_developer_access?(@project.gitlab_id)
.pull-right
- if build.active?
= link_to cancel_project_build_path(build.project, build, return_to: request.original_url), title: 'Cancel build' do
diff --git a/app/views/builds/show.html.haml b/app/views/builds/show.html.haml
index d26bee0..afca8ce 100644
--- a/app/views/builds/show.html.haml
+++ b/app/views/builds/show.html.haml
@@ -2,7 +2,7 @@
= link_to @project.name, @project
@
= @commit.short_sha
- - if current_user.can_manage_project?(@project.gitlab_id)
+ - if current_user && current_user.can_manage_project?(@project.gitlab_id)
.pull-right
= link_to project_jobs_path(@project), class: "btn btn-default btn-small" do
%i.icon-edit.icon-white
@@ -89,7 +89,7 @@
.build-widget
%h4.title
Build
- - if current_user.has_developer_access?(@project.gitlab_id)
+ - if current_user && current_user.has_developer_access?(@project.gitlab_id)
.pull-right
- if @build.active?
= link_to "Cancel", cancel_project_build_path(@project, @build), class: 'btn btn-sm btn-danger'
diff --git a/app/views/commits/show.html.haml b/app/views/commits/show.html.haml
index 2d9e561..4464106 100644
--- a/app/views/commits/show.html.haml
+++ b/app/views/commits/show.html.haml
@@ -2,7 +2,7 @@
= @project.name
@
#{gitlab_commit_link(@project, @commit.sha)}
- - if current_user.can_manage_project?(@project.gitlab_id)
+ - if current_user && current_user.can_manage_project?(@project.gitlab_id)
.pull-right
= link_to project_jobs_path(@project), class: "btn btn-default btn-small" do
%i.icon-edit.icon-white
diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb
index 95f43f8..6df53f2 100644
--- a/spec/factories/projects.rb
+++ b/spec/factories/projects.rb
@@ -33,21 +33,25 @@ FactoryGirl.define do
end
default_ref 'master'
-
+
sequence :path do |n|
"gitlab/gitlab-shell#{n}"
end
-
+
sequence :ssh_url_to_repo do |n|
"git@demo.gitlab.com:gitlab/gitlab-shell#{n}.git"
end
-
+
gitlab_id 8
factory :project do
token 'iPWx6WM4lhHNedGfBpPJNP'
end
+ factory :public_project do
+ public true
+ end
+
before :create do |project|
project.build_default_job
end
diff --git a/spec/features/builds_spec.rb b/spec/features/builds_spec.rb
index 91ac95a..d8ad0ce 100644
--- a/spec/features/builds_spec.rb
+++ b/spec/features/builds_spec.rb
@@ -2,7 +2,6 @@ require 'spec_helper'
describe "Builds" do
before do
- login_as :user
@project = FactoryGirl.create :project
@commit = FactoryGirl.create :commit, project: @project
@build = FactoryGirl.create :build, commit: @commit
@@ -10,6 +9,7 @@ describe "Builds" do
describe "GET /:project/builds/:id" do
before do
+ login_as :user
visit project_build_path(@project, @build)
end
@@ -20,6 +20,7 @@ describe "Builds" do
describe "GET /:project/builds/:id/cancel" do
before do
+ login_as :user
@build.run!
visit cancel_project_build_path(@project, @build)
end
@@ -30,6 +31,7 @@ describe "Builds" do
describe "POST /:project/builds/:id/retry" do
before do
+ login_as :user
@build.cancel!
visit project_build_path(@project, @build)
click_link 'Retry'
@@ -38,4 +40,16 @@ describe "Builds" do
it { page.should have_content 'pending' }
it { page.should have_content 'Cancel' }
end
+
+ describe "Show page public accessible" do
+ before do
+ @project = FactoryGirl.create :public_project
+ @commit = FactoryGirl.create :commit, project: @project
+ @build = FactoryGirl.create :build, commit: @commit
+ stub_gitlab_calls
+ visit project_build_path(@project, @build)
+ end
+
+ it { page.should have_content @commit.sha[0..7] }
+ end
end
diff --git a/spec/features/commits_spec.rb b/spec/features/commits_spec.rb
index 01d5eef..2108d2c 100644
--- a/spec/features/commits_spec.rb
+++ b/spec/features/commits_spec.rb
@@ -1,21 +1,42 @@
require 'spec_helper'
describe "Commits" do
- before do
- login_as :user
- @project = FactoryGirl.create :project
- @commit = FactoryGirl.create :commit, project: @project
- @job = FactoryGirl.create :job, project: @project
- @build = FactoryGirl.create :build, commit: @commit, job: @job
+ context "Authenticated user" do
+ before do
+ login_as :user
+ @project = FactoryGirl.create :project
+ @commit = FactoryGirl.create :commit, project: @project
+ @job = FactoryGirl.create :job, project: @project
+ @build = FactoryGirl.create :build, commit: @commit, job: @job
+ end
+
+ describe "GET /:project/commits/:sha" do
+ before do
+ visit project_ref_commit_path(@project, @commit.ref, @commit.sha)
+ end
+
+ it { page.should have_content @commit.sha[0..7] }
+ it { page.should have_content @commit.git_commit_message }
+ it { page.should have_content @commit.git_author_name }
+ end
end
- describe "GET /:project/commits/:sha" do
+ context "Public pages" do
before do
- visit project_ref_commit_path(@project, @commit.ref, @commit.sha)
+ @project = FactoryGirl.create :public_project
+ @commit = FactoryGirl.create :commit, project: @project
+ @job = FactoryGirl.create :job, project: @project
+ @build = FactoryGirl.create :build, commit: @commit, job: @job
end
- it { page.should have_content @commit.sha[0..7] }
- it { page.should have_content @commit.git_commit_message }
- it { page.should have_content @commit.git_author_name }
+ describe "GET /:project/commits/:sha" do
+ before do
+ visit project_ref_commit_path(@project, @commit.ref, @commit.sha)
+ end
+
+ it { page.should have_content @commit.sha[0..7] }
+ it { page.should have_content @commit.git_commit_message }
+ it { page.should have_content @commit.git_author_name }
+ end
end
end