Commit 3ce95e7c authored by Mark Fletcher's avatar Mark Fletcher

Disable navigation to Pages config if Pages is disabled

* Regards project-level pages config
- Nav link is now shown only if Pages is enabled for instance
- Navigation to following controllers denied if Pages disabled:
  * projects/pages_controller
  * projects/pages_domains_controller
- 'disabled' partial removed
+ Test for pages_controller introduced
parent 03f13af5
......@@ -89,4 +89,8 @@ class Projects::ApplicationController < ApplicationController
def builds_enabled
return render_404 unless @project.feature_available?(:builds, current_user)
end
def require_pages_enabled!
not_found unless Gitlab.config.pages.enabled
end
end
class Projects::PagesController < Projects::ApplicationController
layout 'project_settings'
before_action :require_pages_enabled!
before_action :authorize_read_pages!, only: [:show]
before_action :authorize_update_pages!, except: [:show]
......
class Projects::PagesDomainsController < Projects::ApplicationController
layout 'project_settings'
before_action :require_pages_enabled!
before_action :authorize_update_pages!, except: [:show]
before_action :domain, only: [:show, :destroy]
......
.panel.panel-default
.nothing-here-block
GitLab Pages are disabled.
Ask your system's administrator to enable it.
......@@ -16,13 +16,10 @@
%hr.clearfix
- if Gitlab.config.pages.enabled
= render 'access'
= render 'use'
- if Gitlab.config.pages.external_http || Gitlab.config.pages.external_https
= render 'access'
= render 'use'
- if Gitlab.config.pages.external_http || Gitlab.config.pages.external_https
= render 'list'
- else
= render 'no_domains'
= render 'destroy'
- else
= render 'disabled'
= render 'no_domains'
= render 'destroy'
......@@ -27,6 +27,7 @@
= link_to namespace_project_settings_ci_cd_path(@project.namespace, @project), title: 'CI/CD Pipelines' do
%span
CI/CD Pipelines
- if Gitlab.config.pages.enabled
= nav_link(controller: :pages) do
= link_to namespace_project_pages_path(@project.namespace, @project), title: 'Pages' do
%span
......
---
title: Disable navigation to Project-level pages configuration when Pages disabled
merge_request: 11008
author:
......@@ -63,13 +63,6 @@ Feature: Project Active Tab
And no other sub tabs should be active
And the active main tab should be Settings
Scenario: On Project Settings/Pages
Given I visit my project's settings page
And I click the "Pages" tab
Then the active sub tab should be Pages
And no other sub tabs should be active
And the active main tab should be Settings
Scenario: On Project Members
Given I visit my project's members page
Then the active sub tab should be Members
......
......@@ -3,10 +3,15 @@ Feature: Project Pages
Given I sign in as a user
And I own a project
Scenario: Pages are disabled
Scenario: I cannot navigate to Pages settings if pages enabled
Given pages are disabled
When I visit the Project Pages
Then I should see that GitLab Pages are disabled
And I visit my project's settings page
Then I should not see the "Pages" tab
Scenario: I can navigate to Pages settings if pages enabled
Given pages are enabled
And I visit my project's settings page
Then I should see the "Pages" tab
Scenario: I can see the pages usage if not deployed
Given pages are enabled
......
......@@ -39,12 +39,6 @@ class Spinach::Features::ProjectActiveTab < Spinach::FeatureSteps
end
end
step 'I click the "Pages" tab' do
page.within '.sub-nav' do
click_link('Pages')
end
end
step 'I click the "Activity" tab' do
page.within '.sub-nav' do
click_link('Activity')
......
......@@ -18,14 +18,22 @@ class Spinach::Features::ProjectPages < Spinach::FeatureSteps
visit namespace_project_pages_path(@project.namespace, @project)
end
step 'I should see that GitLab Pages are disabled' do
expect(page).to have_content('GitLab Pages are disabled')
end
step 'I should see the usage of GitLab Pages' do
expect(page).to have_content('Configure pages')
end
step 'I should see the "Pages" tab' do
page.within '.sub-nav' do
expect(page).to have_link('Pages')
end
end
step 'I should not see the "Pages" tab' do
page.within '.sub-nav' do
expect(page).not_to have_link('Pages')
end
end
step 'pages are deployed' do
pipeline = @project.ensure_pipeline('HEAD', @project.commit('HEAD').sha)
build = build(:ci_build,
......
require 'spec_helper'
describe Projects::PagesController do
let(:user) { create(:user) }
let(:project) { create(:empty_project, :public, :access_requestable) }
let(:request_params) do
{
namespace_id: project.namespace,
project_id: project
}
end
before do
allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
sign_in(user)
project.add_master(user)
end
describe 'GET show' do
it 'returns 200 status' do
get :show, request_params
expect(response).to have_http_status(200)
end
end
describe 'DELETE destroy' do
it 'returns 302 status' do
delete :destroy, request_params
expect(response).to have_http_status(302)
end
end
context 'pages disabled' do
before do
allow(Gitlab.config.pages).to receive(:enabled).and_return(false)
end
describe 'GET show' do
it 'returns 404 status' do
get :show, request_params
expect(response).to have_http_status(404)
end
end
describe 'DELETE destroy' do
it 'returns 404 status' do
delete :destroy, request_params
expect(response).to have_http_status(404)
end
end
end
end
......@@ -2,7 +2,8 @@ require 'spec_helper'
describe Projects::PagesDomainsController do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:project) { create(:empty_project) }
let!(:pages_domain) { create(:pages_domain, project: project) }
let(:request_params) do
{
......@@ -11,14 +12,17 @@ describe Projects::PagesDomainsController do
}
end
let(:pages_domain_params) do
build(:pages_domain, :with_certificate, :with_key, domain: 'my.otherdomain.com').slice(:key, :certificate, :domain)
end
before do
allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
sign_in(user)
project.team << [user, :master]
project.add_master(user)
end
describe 'GET show' do
let!(:pages_domain) { create(:pages_domain, project: project) }
it "displays the 'show' page" do
get(:show, request_params.merge(id: pages_domain.domain))
......@@ -37,10 +41,6 @@ describe Projects::PagesDomainsController do
end
describe 'POST create' do
let(:pages_domain_params) do
build(:pages_domain, :with_certificate, :with_key).slice(:key, :certificate, :domain)
end
it "creates a new pages domain" do
expect do
post(:create, request_params.merge(pages_domain: pages_domain_params))
......@@ -51,8 +51,6 @@ describe Projects::PagesDomainsController do
end
describe 'DELETE destroy' do
let!(:pages_domain) { create(:pages_domain, project: project) }
it "deletes the pages domain" do
expect do
delete(:destroy, request_params.merge(id: pages_domain.domain))
......@@ -61,4 +59,42 @@ describe Projects::PagesDomainsController do
expect(response).to redirect_to(namespace_project_pages_path(project.namespace, project))
end
end
context 'pages disabled' do
before do
allow(Gitlab.config.pages).to receive(:enabled).and_return(false)
end
describe 'GET show' do
it 'returns 404 status' do
get(:show, request_params.merge(id: pages_domain.domain))
expect(response).to have_http_status(404)
end
end
describe 'GET new' do
it 'returns 404 status' do
get :new, request_params
expect(response).to have_http_status(404)
end
end
describe 'POST create' do
it "returns 404 status" do
post(:create, request_params.merge(pages_domain: pages_domain_params))
expect(response).to have_http_status(404)
end
end
describe 'DELETE destroy' do
it "deletes the pages domain" do
delete(:destroy, request_params.merge(id: pages_domain.domain))
expect(response).to have_http_status(404)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment