Commit ef71bf62 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '30529-remove-pages-tab-if-pages-isn-t-enabled' into 'master'

Disable navigation to Pages config if Pages is disabled

Closes #30529

See merge request !11008
parents 68c12e15 3ce95e7c
...@@ -89,4 +89,8 @@ class Projects::ApplicationController < ApplicationController ...@@ -89,4 +89,8 @@ class Projects::ApplicationController < ApplicationController
def builds_enabled def builds_enabled
return render_404 unless @project.feature_available?(:builds, current_user) return render_404 unless @project.feature_available?(:builds, current_user)
end end
def require_pages_enabled!
not_found unless Gitlab.config.pages.enabled
end
end end
class Projects::PagesController < Projects::ApplicationController class Projects::PagesController < Projects::ApplicationController
layout 'project_settings' layout 'project_settings'
before_action :require_pages_enabled!
before_action :authorize_read_pages!, only: [:show] before_action :authorize_read_pages!, only: [:show]
before_action :authorize_update_pages!, except: [:show] before_action :authorize_update_pages!, except: [:show]
......
class Projects::PagesDomainsController < Projects::ApplicationController class Projects::PagesDomainsController < Projects::ApplicationController
layout 'project_settings' layout 'project_settings'
before_action :require_pages_enabled!
before_action :authorize_update_pages!, except: [:show] before_action :authorize_update_pages!, except: [:show]
before_action :domain, only: [:show, :destroy] 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 @@ ...@@ -16,13 +16,10 @@
%hr.clearfix %hr.clearfix
- if Gitlab.config.pages.enabled = render 'access'
= render 'access' = render 'use'
= render 'use' - if Gitlab.config.pages.external_http || Gitlab.config.pages.external_https
- if Gitlab.config.pages.external_http || Gitlab.config.pages.external_https = render 'list'
= render 'list'
- else
= render 'no_domains'
= render 'destroy'
- else - else
= render 'disabled' = render 'no_domains'
= render 'destroy'
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
= link_to namespace_project_settings_ci_cd_path(@project.namespace, @project), title: 'CI/CD Pipelines' do = link_to namespace_project_settings_ci_cd_path(@project.namespace, @project), title: 'CI/CD Pipelines' do
%span %span
CI/CD Pipelines CI/CD Pipelines
= nav_link(controller: :pages) do - if Gitlab.config.pages.enabled
= link_to namespace_project_pages_path(@project.namespace, @project), title: 'Pages' do = nav_link(controller: :pages) do
%span = link_to namespace_project_pages_path(@project.namespace, @project), title: 'Pages' do
Pages %span
Pages
---
title: Disable navigation to Project-level pages configuration when Pages disabled
merge_request: 11008
author:
...@@ -63,13 +63,6 @@ Feature: Project Active Tab ...@@ -63,13 +63,6 @@ Feature: Project Active Tab
And no other sub tabs should be active And no other sub tabs should be active
And the active main tab should be Settings 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 Scenario: On Project Members
Given I visit my project's members page Given I visit my project's members page
Then the active sub tab should be Members Then the active sub tab should be Members
......
...@@ -3,10 +3,15 @@ Feature: Project Pages ...@@ -3,10 +3,15 @@ Feature: Project Pages
Given I sign in as a user Given I sign in as a user
And I own a project And I own a project
Scenario: Pages are disabled Scenario: I cannot navigate to Pages settings if pages enabled
Given pages are disabled Given pages are disabled
When I visit the Project Pages And I visit my project's settings page
Then I should see that GitLab Pages are disabled 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 Scenario: I can see the pages usage if not deployed
Given pages are enabled Given pages are enabled
......
...@@ -39,12 +39,6 @@ class Spinach::Features::ProjectActiveTab < Spinach::FeatureSteps ...@@ -39,12 +39,6 @@ class Spinach::Features::ProjectActiveTab < Spinach::FeatureSteps
end end
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 step 'I click the "Activity" tab' do
page.within '.sub-nav' do page.within '.sub-nav' do
click_link('Activity') click_link('Activity')
......
...@@ -18,14 +18,22 @@ class Spinach::Features::ProjectPages < Spinach::FeatureSteps ...@@ -18,14 +18,22 @@ class Spinach::Features::ProjectPages < Spinach::FeatureSteps
visit namespace_project_pages_path(@project.namespace, @project) visit namespace_project_pages_path(@project.namespace, @project)
end 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 step 'I should see the usage of GitLab Pages' do
expect(page).to have_content('Configure pages') expect(page).to have_content('Configure pages')
end 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 step 'pages are deployed' do
pipeline = @project.ensure_pipeline('HEAD', @project.commit('HEAD').sha) pipeline = @project.ensure_pipeline('HEAD', @project.commit('HEAD').sha)
build = build(:ci_build, 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
require 'spec_helper' require 'spec_helper'
describe Projects::PagesDomainsController do describe Projects::PagesDomainsController do
let(:user) { create(:user) } 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 let(:request_params) do
{ {
...@@ -11,14 +12,17 @@ describe Projects::PagesDomainsController do ...@@ -11,14 +12,17 @@ describe Projects::PagesDomainsController do
} }
end end
let(:pages_domain_params) do
build(:pages_domain, :with_certificate, :with_key, domain: 'my.otherdomain.com').slice(:key, :certificate, :domain)
end
before do before do
allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
sign_in(user) sign_in(user)
project.team << [user, :master] project.add_master(user)
end end
describe 'GET show' do describe 'GET show' do
let!(:pages_domain) { create(:pages_domain, project: project) }
it "displays the 'show' page" do it "displays the 'show' page" do
get(:show, request_params.merge(id: pages_domain.domain)) get(:show, request_params.merge(id: pages_domain.domain))
...@@ -37,10 +41,6 @@ describe Projects::PagesDomainsController do ...@@ -37,10 +41,6 @@ describe Projects::PagesDomainsController do
end end
describe 'POST create' do 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 it "creates a new pages domain" do
expect do expect do
post(:create, request_params.merge(pages_domain: pages_domain_params)) post(:create, request_params.merge(pages_domain: pages_domain_params))
...@@ -51,8 +51,6 @@ describe Projects::PagesDomainsController do ...@@ -51,8 +51,6 @@ describe Projects::PagesDomainsController do
end end
describe 'DELETE destroy' do describe 'DELETE destroy' do
let!(:pages_domain) { create(:pages_domain, project: project) }
it "deletes the pages domain" do it "deletes the pages domain" do
expect do expect do
delete(:destroy, request_params.merge(id: pages_domain.domain)) delete(:destroy, request_params.merge(id: pages_domain.domain))
...@@ -61,4 +59,42 @@ describe Projects::PagesDomainsController do ...@@ -61,4 +59,42 @@ describe Projects::PagesDomainsController do
expect(response).to redirect_to(namespace_project_pages_path(project.namespace, project)) expect(response).to redirect_to(namespace_project_pages_path(project.namespace, project))
end end
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 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