Skip to content
Snippets Groups Projects
Commit 52091660 authored by Naman Jagdish Gala's avatar Naman Jagdish Gala 💬
Browse files

Add support in UI to select pages default domain redirect

Related: #481334

Changelog: added
parent b6886fba
No related branches found
No related tags found
No related merge requests found
Pipeline #1579848205 canceled
Pipeline: rspec-ee:predictive

#1579860062

    Pipeline: rspec:predictive

    #1579860042

      Pipeline: Ruby 3.2.5 as-if-foss

      #1579851179

        ......@@ -730,6 +730,16 @@ def show_dashboard_projects_welcome_page?
        dashboard_projects_landing_paths.include?(request.path) && !current_user.authorized_projects.present?
        end
        def project_pages_domain_choices
        pages_url = build_pages_url(@project)
        default_option = [['Do not redirect', ''], [pages_url, pages_url]]
        domain_options = @project&.pages_domains&.map { |domain| [domain.url, domain.url] } || []
        options_for_select(
        default_option + domain_options
        )
        end
        private
        def visibility_level_name(project)
        ......
        ......@@ -580,6 +580,7 @@ def self.integration_association_name(name)
        delegate :mr_default_target_self, :mr_default_target_self=
        delegate :previous_default_branch, :previous_default_branch=
        delegate :squash_option, :squash_option=
        delegate :pages_default_domain_redirect, :pages_default_domain_redirect=
        with_options allow_nil: true do
        delegate :merge_commit_template, :merge_commit_template=
        ......
        ......@@ -16,6 +16,8 @@ def execute
        validate!
        update_pages_default_domain_redirect
        ensure_wiki_exists if enabling_wiki?
        if changing_repository_storage?
        ......@@ -60,6 +62,12 @@ def add_pages_unique_domain
        Gitlab::Pages.add_unique_domain_to(project)
        end
        def update_pages_default_domain_redirect
        return unless params[:project_setting_attributes]&.key?(:pages_default_domain_redirect)
        Gitlab::Pages.update_default_domain_redirect(project, params.dig(:project_setting_attributes, :pages_default_domain_redirect))
        end
        def validate!
        unless valid_visibility_level_change?(project, project.visibility_attribute_value(params))
        raise_validation_error(s_('UpdateProject|New visibility level not allowed!'))
        ......@@ -68,6 +76,7 @@ def validate!
        validate_default_branch_change
        validate_renaming_project_with_tags
        validate_restrict_user_defined_variables_change
        validate_pages_default_domain_redirect
        end
        def validate_restrict_user_defined_variables_change
        ......@@ -129,6 +138,15 @@ def validate_renaming_project_with_tags
        )
        end
        def validate_pages_default_domain_redirect
        default_domain_redirect = params.dig(:project_setting_attributes, :pages_default_domain_redirect)
        return unless default_domain_redirect
        return if project.pages_domain_present?(default_domain_redirect)
        raise_api_error(s_("UpdateProject|The `pages_default_domain_redirect` attribute is missing from the domain list in the Pages project configuration. Assign `pages_default_domain_redirect` to the Pages project or reset it."))
        end
        def ambiguous_head_documentation_link
        url = Rails.application.routes.url_helpers.help_page_path('user/project/repository/branches/index.md', anchor: 'error-ambiguous-head-branch-exists')
        ......
        ......@@ -20,5 +20,13 @@
        %p.gl-pl-6
        = s_("GitLabPages|When enabled, a unique domain is generated to access pages.").html_safe
        .form-group
        = f.fields_for :project_setting do |settings|
        = f.label :pages_default_domain_redirect, class: 'label-bold' do
        = s_('GitLabPages|Redirect domains')
        = settings.select :pages_default_domain_redirect, project_pages_domain_choices, {}, class: 'gl-form-select custom-select'
        .form-text.gl-text-subtle
        = s_('GitLabPages|If selected, all domains, including the default domain, will be redirected to this domain.')
        .gl-mt-3
        = f.submit s_('GitLabPages|Save changes'), pajamas_button: true
        ......@@ -44,6 +44,12 @@ def add_unique_domain_to(project)
        project.project_setting.pages_unique_domain = generate_unique_domain(project)
        end
        def update_default_domain_redirect(project, default_domain_redirect)
        return unless enabled?
        project.project_setting.pages_default_domain_redirect = default_domain_redirect
        end
        def multiple_versions_enabled_for?(project)
        return false if project.blank?
        ......
        ......@@ -24964,6 +24964,9 @@ msgstr ""
        msgid "GitLabPages|Force HTTPS (requires valid certificates)"
        msgstr ""
         
        msgid "GitLabPages|If selected, all domains, including the default domain, will be redirected to this domain."
        msgstr ""
        msgid "GitLabPages|Maximum size (MB)"
        msgstr ""
         
        ......@@ -24976,6 +24979,9 @@ msgstr ""
        msgid "GitLabPages|Pages"
        msgstr ""
         
        msgid "GitLabPages|Redirect domains"
        msgstr ""
        msgid "GitLabPages|Remove certificate"
        msgstr ""
         
        ......@@ -59260,6 +59266,9 @@ msgstr ""
        msgid "UpdateProject|Pruning unreachable objects can lead to repository corruption."
        msgstr ""
         
        msgid "UpdateProject|The `pages_default_domain_redirect` attribute is missing from the domain list in the Pages project configuration. Assign `pages_default_domain_redirect` to the Pages project or reset it."
        msgstr ""
        msgid "UpdateProject|Updating default branch is blocked by security policy"
        msgstr ""
         
        ......@@ -971,6 +971,24 @@ def expect_rename_of_base_repository_in_registry(dry_run:, path: nil)
        end
        end
        describe 'when updating pages default domain redirect', feature_category: :pages do
        before do
        stub_pages_setting(enabled: true)
        end
        context 'when selecting an existing domain' do
        before do
        allow(project).to receive(:pages_domain_present?).and_return(true)
        end
        it 'updates the pages default domain redirect setting' do
        expect { update_project(project, user, project_setting_attributes: { pages_default_domain_redirect: "http://example.com" }) }
        .to change { project.project_setting.pages_default_domain_redirect }
        .from(nil).to("http://example.com")
        end
        end
        end
        describe 'when updating ci_inbound_job_token_scope_enabled' do
        let(:category) { described_class }
        let(:user) { admin }
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment