Commit d5d24976 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'zj-disable-pages-in-subgroups' into 'master'

Don't show references to Pages when not available

Closes #34864

See merge request !13888
parents a768e1b7 04cd47dd
...@@ -94,6 +94,6 @@ class Projects::ApplicationController < ApplicationController ...@@ -94,6 +94,6 @@ class Projects::ApplicationController < ApplicationController
end end
def require_pages_enabled! def require_pages_enabled!
not_found unless Gitlab.config.pages.enabled not_found unless @project.pages_available?
end end
end end
...@@ -195,6 +195,10 @@ class Namespace < ActiveRecord::Base ...@@ -195,6 +195,10 @@ class Namespace < ActiveRecord::Base
parent.present? parent.present?
end end
def subgroup?
has_parent?
end
def soft_delete_without_removing_associations def soft_delete_without_removing_associations
# We can't use paranoia's `#destroy` since this will hard-delete projects. # We can't use paranoia's `#destroy` since this will hard-delete projects.
# Project uses `pending_delete` instead of the acts_as_paranoia gem. # Project uses `pending_delete` instead of the acts_as_paranoia gem.
......
...@@ -1231,6 +1231,10 @@ class Project < ActiveRecord::Base ...@@ -1231,6 +1231,10 @@ class Project < ActiveRecord::Base
File.join(pages_path, 'public') File.join(pages_path, 'public')
end end
def pages_available?
Gitlab.config.pages.enabled && !namespace.subgroup?
end
def remove_private_deploy_keys def remove_private_deploy_keys
exclude_keys_linked_to_other_projects = <<-SQL exclude_keys_linked_to_other_projects = <<-SQL
NOT EXISTS ( NOT EXISTS (
......
...@@ -208,7 +208,7 @@ ...@@ -208,7 +208,7 @@
= link_to project_settings_ci_cd_path(@project), title: 'CI / CD' do = link_to project_settings_ci_cd_path(@project), title: 'CI / CD' do
%span %span
CI / CD CI / CD
- if Gitlab.config.pages.enabled - if @project.pages_available?
= nav_link(controller: :pages) do = nav_link(controller: :pages) do
= link_to project_pages_path(@project), title: 'Pages' do = link_to project_pages_path(@project), title: 'Pages' do
%span %span
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
= link_to project_settings_ci_cd_path(@project), title: 'Pipelines' do = link_to project_settings_ci_cd_path(@project), title: 'Pipelines' do
%span %span
Pipelines Pipelines
- if Gitlab.config.pages.enabled - if @project.pages_available?
= nav_link(controller: :pages) do = nav_link(controller: :pages) do
= link_to project_pages_path(@project), title: 'Pages' do = link_to project_pages_path(@project), title: 'Pages' do
%span %span
......
---
title: Remove pages settings when not available
merge_request:
author:
type: changed
...@@ -2,7 +2,7 @@ require 'spec_helper' ...@@ -2,7 +2,7 @@ require 'spec_helper'
describe Projects::PagesController do describe Projects::PagesController do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :public, :access_requestable) } let(:project) { create(:project, :public) }
let(:request_params) do let(:request_params) do
{ {
...@@ -23,6 +23,17 @@ describe Projects::PagesController do ...@@ -23,6 +23,17 @@ describe Projects::PagesController do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
context 'when the project is in a subgroup' do
let(:group) { create(:group, :nested) }
let(:project) { create(:project, namespace: group) }
it 'returns a 404 status code' do
get :show, request_params
expect(response).to have_http_status(404)
end
end
end end
describe 'DELETE destroy' do describe 'DELETE destroy' do
......
...@@ -2234,6 +2234,28 @@ describe Project do ...@@ -2234,6 +2234,28 @@ describe Project do
end end
end end
describe '#pages_available?' do
let(:project) { create(:project, group: group) }
subject { project.pages_available? }
before do
allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
end
context 'when the project is in a top level namespace' do
let(:group) { create(:group) }
it { is_expected.to be(true) }
end
context 'when the project is in a subgroup' do
let(:group) { create(:group, :nested) }
it { is_expected.to be(false) }
end
end
describe '#remove_private_deploy_keys' do describe '#remove_private_deploy_keys' do
let!(:project) { create(:project) } let!(:project) { create(:project) }
......
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