From 6f894bec097a4cfa378cee908d81f3cba67a09e5 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 24 Mar 2016 08:09:39 +0100 Subject: Add definition of before action that has been moved Closes #14528 --- CHANGELOG | 1 + app/controllers/ci/projects_controller.rb | 6 +++++- spec/controllers/ci/projects_controller_spec.rb | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 5d9f4961ef5..7c3727a6896 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ v 8.7.0 (unreleased) v 8.6.2 (unreleased) - Comments on confidential issues don't show up in activity feed to non-members + - Fix NoMethodError when visiting CI root path at `/ci` v 8.6.1 - Add option to reload the schema before restoring a database backup. !2807 diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb index 081e01a75e0..c0e7f434ff5 100644 --- a/app/controllers/ci/projects_controller.rb +++ b/app/controllers/ci/projects_controller.rb @@ -1,8 +1,8 @@ module Ci class ProjectsController < Ci::ApplicationController before_action :project - before_action :authorize_read_project!, except: [:badge] before_action :no_cache, only: [:badge] + before_action :authorize_read_project!, except: [:badge, :index] skip_before_action :authenticate_user!, only: [:badge] protect_from_forgery @@ -35,5 +35,9 @@ module Ci response.headers["Pragma"] = "no-cache" response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" end + + def authorize_read_project! + return access_denied! unless can?(current_user, :read_project, project) + end end end diff --git a/spec/controllers/ci/projects_controller_spec.rb b/spec/controllers/ci/projects_controller_spec.rb index db0748f323f..9a886e4c124 100644 --- a/spec/controllers/ci/projects_controller_spec.rb +++ b/spec/controllers/ci/projects_controller_spec.rb @@ -5,6 +5,16 @@ describe Ci::ProjectsController do let!(:project) { create(:project, visibility, ci_id: 1) } let(:ci_id) { project.ci_id } + describe '#index' do + let(:user) { create(:user) } + before { sign_in(user) } + before { get(:index) } + + it 'returns 200' do + expect(response.status).to eq 200 + end + end + ## # Specs for *deprecated* CI badge # -- cgit v1.2.1 From b7685b57d3fc9a2e27096c5984d92fd104ff71b7 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 24 Mar 2016 14:16:12 +0100 Subject: Redirect to root path when visiting `/ci` --- app/controllers/ci/projects_controller.rb | 4 ++++ app/views/ci/projects/index.html.haml | 20 -------------------- spec/controllers/ci/projects_controller_spec.rb | 21 ++++++++++++++++----- 3 files changed, 20 insertions(+), 25 deletions(-) delete mode 100644 app/views/ci/projects/index.html.haml diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb index c0e7f434ff5..8bf71a1adbb 100644 --- a/app/controllers/ci/projects_controller.rb +++ b/app/controllers/ci/projects_controller.rb @@ -6,6 +6,10 @@ module Ci skip_before_action :authenticate_user!, only: [:badge] protect_from_forgery + def index + redirect_to root_path + end + def show # Temporary compatibility with CI badges pointing to CI project page redirect_to namespace_project_path(project.namespace, project) diff --git a/app/views/ci/projects/index.html.haml b/app/views/ci/projects/index.html.haml deleted file mode 100644 index 9c2290bc4a5..00000000000 --- a/app/views/ci/projects/index.html.haml +++ /dev/null @@ -1,20 +0,0 @@ -.wiki - %h1 - GitLab CI is now integrated in GitLab UI - %h2 For existing projects - - %p - Check the following pages to find the CI status you're looking for: - - %ul - %li Projects page - shows CI status for each project. - %li Project commits page - show CI status for each commit. - - - - %h2 For new projects - - %p - If you want to enable CI for a new project it is easy as adding - = link_to ".gitlab-ci.yml", "http://doc.gitlab.com/ce/ci/yaml/README.html" - file to your repository diff --git a/spec/controllers/ci/projects_controller_spec.rb b/spec/controllers/ci/projects_controller_spec.rb index 9a886e4c124..5022a3e2c80 100644 --- a/spec/controllers/ci/projects_controller_spec.rb +++ b/spec/controllers/ci/projects_controller_spec.rb @@ -6,12 +6,23 @@ describe Ci::ProjectsController do let(:ci_id) { project.ci_id } describe '#index' do - let(:user) { create(:user) } - before { sign_in(user) } - before { get(:index) } + context 'user signed in' do + before do + sign_in(create(:user)) + get(:index) + end + + it 'redirects to /' do + expect(response).to redirect_to(root_path) + end + end + + context 'user not signed in' do + before { get(:index) } - it 'returns 200' do - expect(response.status).to eq 200 + it 'redirects to sign in page' do + expect(response).to redirect_to(new_user_session_path) + end end end -- cgit v1.2.1