diff options
-rw-r--r-- | app/views/admin/application_settings/_help_page.html.haml | 2 | ||||
-rw-r--r-- | app/views/layouts/header/_help_dropdown.html.haml | 2 | ||||
-rw-r--r-- | changelogs/unreleased/feat-add-support-page-link-in-help-menu.yml | 5 | ||||
-rw-r--r-- | changelogs/unreleased/sh-fix-gitaly-access-control.yml | 5 | ||||
-rw-r--r-- | doc/api/settings.md | 2 | ||||
-rw-r--r-- | lib/api/settings.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/project_template.rb | 10 | ||||
-rw-r--r-- | lib/tasks/gitlab/update_templates.rake | 62 | ||||
-rw-r--r-- | locale/gitlab.pot | 5 | ||||
-rw-r--r-- | qa/qa/service/kubernetes_cluster.rb | 1 | ||||
-rw-r--r-- | spec/features/admin/admin_settings_spec.rb | 34 | ||||
-rw-r--r-- | spec/lib/gitlab/gitaly_client_spec.rb | 10 | ||||
-rw-r--r-- | spec/lib/gitlab/project_template_spec.rb | 6 | ||||
-rw-r--r-- | spec/support/helpers/graphql_helpers.rb | 8 | ||||
-rw-r--r-- | spec/tasks/gitlab/update_templates_rake_spec.rb | 25 |
16 files changed, 152 insertions, 29 deletions
diff --git a/app/views/admin/application_settings/_help_page.html.haml b/app/views/admin/application_settings/_help_page.html.haml index a869f1bd4df..5e5ab1e4269 100644 --- a/app/views/admin/application_settings/_help_page.html.haml +++ b/app/views/admin/application_settings/_help_page.html.haml @@ -16,6 +16,6 @@ .form-group = f.label :help_page_support_url, _('Support page URL'), class: 'label-bold' = f.text_field :help_page_support_url, class: 'form-control', placeholder: 'http://company.example.com/getting-help', :'aria-describedby' => 'support_help_block' - %span.form-text.text-muted#support_help_block= _('Alternate support URL for help page') + %span.form-text.text-muted#support_help_block= _('Alternate support URL for help page and help dropdown') = f.submit _('Save changes'), class: "btn btn-success" diff --git a/app/views/layouts/header/_help_dropdown.html.haml b/app/views/layouts/header/_help_dropdown.html.haml index 5643a508ddc..41d7aa3741a 100644 --- a/app/views/layouts/header/_help_dropdown.html.haml +++ b/app/views/layouts/header/_help_dropdown.html.haml @@ -2,6 +2,8 @@ - if current_user_menu?(:help) %li = link_to _("Help"), help_path + %li + = link_to _("Support"), support_url = render_if_exists "shared/learn_gitlab_menu_item" %li.divider %li diff --git a/changelogs/unreleased/feat-add-support-page-link-in-help-menu.yml b/changelogs/unreleased/feat-add-support-page-link-in-help-menu.yml new file mode 100644 index 00000000000..2cddd52212e --- /dev/null +++ b/changelogs/unreleased/feat-add-support-page-link-in-help-menu.yml @@ -0,0 +1,5 @@ +--- +title: Add admin-configurable "Support page URL" link to top Help dropdown menu +merge_request: 30459 +author: Diego Louzán +type: added diff --git a/changelogs/unreleased/sh-fix-gitaly-access-control.yml b/changelogs/unreleased/sh-fix-gitaly-access-control.yml new file mode 100644 index 00000000000..bdd33f3ff45 --- /dev/null +++ b/changelogs/unreleased/sh-fix-gitaly-access-control.yml @@ -0,0 +1,5 @@ +--- +title: Fix exception handling in Gitaly autodetection +merge_request: 31285 +author: +type: fixed diff --git a/doc/api/settings.md b/doc/api/settings.md index 68da88af698..c3ac70f0579 100644 --- a/doc/api/settings.md +++ b/doc/api/settings.md @@ -230,7 +230,7 @@ are listed in the descriptions of the relevant settings. | `gravatar_enabled` | boolean | no | Enable Gravatar. | | `hashed_storage_enabled` | boolean | no | Create new projects using hashed storage paths: Enable immutable, hash-based paths and repository names to store repositories on disk. This prevents repositories from having to be moved or renamed when the Project URL changes and may improve disk I/O performance. (EXPERIMENTAL) | | `help_page_hide_commercial_content` | boolean | no | Hide marketing-related entries from help. | -| `help_page_support_url` | string | no | Alternate support URL for help page. | +| `help_page_support_url` | string | no | Alternate support URL for help page and help dropdown. | | `help_page_text` | string | no | Custom text displayed on the help page. | | `help_text` | string | no | **(PREMIUM)** GitLab server administrator information | | `hide_third_party_offers` | boolean | no | Do not display offers from third parties within GitLab. | diff --git a/lib/api/settings.rb b/lib/api/settings.rb index 4275d911708..aa9e879160d 100644 --- a/lib/api/settings.rb +++ b/lib/api/settings.rb @@ -59,7 +59,7 @@ module API optional :grafana_url, type: String, desc: 'Grafana URL' optional :gravatar_enabled, type: Boolean, desc: 'Flag indicating if the Gravatar service is enabled' optional :help_page_hide_commercial_content, type: Boolean, desc: 'Hide marketing-related entries from help' - optional :help_page_support_url, type: String, desc: 'Alternate support URL for help page' + optional :help_page_support_url, type: String, desc: 'Alternate support URL for help page and help dropdown' optional :help_page_text, type: String, desc: 'Custom text displayed on the help page' optional :home_page_url, type: String, desc: 'We will redirect non-logged in users to this page' optional :housekeeping_enabled, type: Boolean, desc: 'Enable automatic repository housekeeping (git repack, git gc)' diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index c98de722fe1..4783832961d 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -413,7 +413,7 @@ module Gitlab metadata_file = File.read(storage_metadata_file_path(storage)) metadata_hash = JSON.parse(metadata_file) metadata_hash['gitaly_filesystem_id'] - rescue Errno::ENOENT, Errno::ACCESS, JSON::ParserError + rescue Errno::ENOENT, Errno::EACCES, JSON::ParserError nil end diff --git a/lib/gitlab/project_template.rb b/lib/gitlab/project_template.rb index 99885be8755..dbf469a44c1 100644 --- a/lib/gitlab/project_template.rb +++ b/lib/gitlab/project_template.rb @@ -13,11 +13,15 @@ module Gitlab end def archive_path - Rails.root.join("vendor/project_templates/#{name}.tar.gz") + self.class.archive_directory.join(archive_filename) + end + + def archive_filename + "#{name}.tar.gz" end def clone_url - "https://gitlab.com/gitlab-org/project-templates/#{name}.git" + "#{preview}.git" end def ==(other) @@ -54,7 +58,7 @@ module Gitlab end def archive_directory - Rails.root.join("vendor_directory/project_templates") + Rails.root.join("vendor/project_templates") end end end diff --git a/lib/tasks/gitlab/update_templates.rake b/lib/tasks/gitlab/update_templates.rake index e058e9fe069..8267c235a7f 100644 --- a/lib/tasks/gitlab/update_templates.rake +++ b/lib/tasks/gitlab/update_templates.rake @@ -5,25 +5,43 @@ namespace :gitlab do end desc "GitLab | Update project templates" - task :update_project_templates do - include Gitlab::ImportExport::CommandLineUtil + task :update_project_templates, [] => :environment do |_task, args| + # we need an instance method from Gitlab::ImportExport::CommandLineUtil and don't + # want to include it in the task, as this would affect subsequent tasks as well + downloader = Class.new do + extend Gitlab::ImportExport::CommandLineUtil + + def self.call(uploader, upload_path) + download_or_copy_upload(uploader, upload_path) + end + end + + template_names = args.extras.to_set if Rails.env.production? - puts "This rake task is not meant fo production instances".red - exit(1) + raise "This rake task is not meant for production instances" end admin = User.find_by(admin: true) unless admin - puts "No admin user could be found".red - exit(1) + raise "No admin user could be found" end - Gitlab::ProjectTemplate.all.each do |template| + tmp_namespace_path = "tmp-project-import-#{Time.now.to_i}" + puts "Creating temporary namespace #{tmp_namespace_path}" + tmp_namespace = Namespace.create!(owner: admin, name: tmp_namespace_path, path: tmp_namespace_path) + + templates = if template_names.empty? + Gitlab::ProjectTemplate.all + else + Gitlab::ProjectTemplate.all.select { |template| template_names.include?(template.name) } + end + + templates.each do |template| params = { import_url: template.clone_url, - namespace_id: admin.namespace.id, + namespace_id: tmp_namespace.id, path: template.name, skip_wiki: true } @@ -32,19 +50,17 @@ namespace :gitlab do project = Projects::CreateService.new(admin, params).execute unless project.persisted? - puts project.errors.messages - exit(1) + raise "Failed to create project: #{project.errors.messages}" end loop do - if project.finished? + if project.import_finished? puts "Import finished for #{template.name}" break end - if project.failed? - puts "Failed to import from #{project_params[:import_url]}".red - exit(1) + if project.import_failed? + raise "Failed to import from #{project_params[:import_url]}" end puts "Waiting for the import to finish" @@ -54,11 +70,23 @@ namespace :gitlab do end Projects::ImportExport::ExportService.new(project, admin).execute - download_or_copy_upload(project.export_file, template.archive_path) - Projects::DestroyService.new(admin, project).execute + downloader.call(project.export_file, template.archive_path) + + unless Projects::DestroyService.new(project, admin).execute + puts "Failed to destroy project #{template.name} (but namespace will be cleaned up later)" + end + puts "Exported #{template.name}".green end - puts "Done".green + + success = true + ensure + if tmp_namespace + puts "Destroying temporary namespace #{tmp_namespace_path}" + tmp_namespace.destroy + end + + puts "Done".green if success end def update(template) diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 591dc2a7e39..feae99fb95a 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -966,7 +966,7 @@ msgstr "" msgid "Allows you to add and manage Kubernetes clusters." msgstr "" -msgid "Alternate support URL for help page" +msgid "Alternate support URL for help page and help dropdown" msgstr "" msgid "Alternatively, you can use a %{personal_access_token_link}. When you create your Personal Access Token, you will need to select the <code>repo</code> scope, so we can display a list of your public and private repositories which are available to import." @@ -10586,6 +10586,9 @@ msgstr "" msgid "Sunday" msgstr "" +msgid "Support" +msgstr "" + msgid "Support for custom certificates is disabled. Ask your system's administrator to enable it." msgstr "" diff --git a/qa/qa/service/kubernetes_cluster.rb b/qa/qa/service/kubernetes_cluster.rb index 40263e94065..7b3451ed799 100644 --- a/qa/qa/service/kubernetes_cluster.rb +++ b/qa/qa/service/kubernetes_cluster.rb @@ -29,6 +29,7 @@ module QA #{auth_options} --enable-basic-auth --region #{Runtime::Env.gcloud_region} + --disk-size 10GB && gcloud container clusters get-credentials --region #{Runtime::Env.gcloud_region} diff --git a/spec/features/admin/admin_settings_spec.rb b/spec/features/admin/admin_settings_spec.rb index a074bbcff0a..c77605f3869 100644 --- a/spec/features/admin/admin_settings_spec.rb +++ b/spec/features/admin/admin_settings_spec.rb @@ -356,16 +356,18 @@ describe 'Admin updates settings' do end it 'Change Help page' do + new_support_url = 'http://example.com/help' + page.within('.as-help-page') do fill_in 'Help page text', with: 'Example text' check 'Hide marketing-related entries from help' - fill_in 'Support page URL', with: 'http://example.com/help' + fill_in 'Support page URL', with: new_support_url click_button 'Save changes' end expect(current_settings.help_page_text).to eq "Example text" expect(current_settings.help_page_hide_commercial_content).to be_truthy - expect(current_settings.help_page_support_url).to eq "http://example.com/help" + expect(current_settings.help_page_support_url).to eq new_support_url expect(page).to have_content "Application settings saved successfully" end @@ -415,6 +417,34 @@ describe 'Admin updates settings' do end end + context 'Nav bar' do + it 'Shows default help links in nav' do + default_support_url = 'https://about.gitlab.com/getting-help/' + + visit root_dashboard_path + + find('.header-help-dropdown-toggle').click + + page.within '.header-help' do + expect(page).to have_link(text: 'Help', href: help_path) + expect(page).to have_link(text: 'Support', href: default_support_url) + end + end + + it 'Shows custom support url in nav when set' do + new_support_url = 'http://example.com/help' + stub_application_setting(help_page_support_url: new_support_url) + + visit root_dashboard_path + + find('.header-help-dropdown-toggle').click + + page.within '.header-help' do + expect(page).to have_link(text: 'Support', href: new_support_url) + end + end + end + def check_all_events page.check('Active') page.check('Push') diff --git a/spec/lib/gitlab/gitaly_client_spec.rb b/spec/lib/gitlab/gitaly_client_spec.rb index e1d24ae8977..e9fb6c0125c 100644 --- a/spec/lib/gitlab/gitaly_client_spec.rb +++ b/spec/lib/gitlab/gitaly_client_spec.rb @@ -17,6 +17,16 @@ describe Gitlab::GitalyClient do }) end + describe '.filesystem_id_from_disk' do + it 'catches errors' do + [Errno::ENOENT, Errno::EACCES, JSON::ParserError].each do |error| + allow(File).to receive(:read).with(described_class.storage_metadata_file_path('default')).and_raise(error) + + expect(described_class.filesystem_id_from_disk('default')).to be_nil + end + end + end + describe '.stub_class' do it 'returns the gRPC health check stub' do expect(described_class.stub_class(:health_check)).to eq(::Grpc::Health::V1::Health::Stub) diff --git a/spec/lib/gitlab/project_template_spec.rb b/spec/lib/gitlab/project_template_spec.rb index 8c2fc048a54..8b82ea7faa5 100644 --- a/spec/lib/gitlab/project_template_spec.rb +++ b/spec/lib/gitlab/project_template_spec.rb @@ -44,6 +44,12 @@ describe Gitlab::ProjectTemplate do end end + describe '.archive_directory' do + subject { described_class.archive_directory } + + it { is_expected.to be_a Pathname } + end + describe 'instance methods' do subject { described_class.new('phoenix', 'Phoenix Framework', 'Phoenix description', 'link-to-template') } diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb index ae1b859ae3f..d86371d70b9 100644 --- a/spec/support/helpers/graphql_helpers.rb +++ b/spec/support/helpers/graphql_helpers.rb @@ -3,6 +3,8 @@ module GraphqlHelpers MutationDefinition = Struct.new(:query, :variables) + NoData = Class.new(StandardError) + # makes an underscored string look like a fieldname # "merge_request" => "mergeRequest" def self.fieldnamerize(underscored_field_name) @@ -158,8 +160,9 @@ module GraphqlHelpers post_graphql(mutation.query, current_user: current_user, variables: mutation.variables) end + # Raises an error if no data is found def graphql_data - json_response['data'] + json_response['data'] || (raise NoData, graphql_errors) end def graphql_errors @@ -173,8 +176,9 @@ module GraphqlHelpers end end + # Raises an error if no response is found def graphql_mutation_response(mutation_name) - graphql_data[GraphqlHelpers.fieldnamerize(mutation_name)] + graphql_data.fetch(GraphqlHelpers.fieldnamerize(mutation_name)) end def nested_fields?(field) diff --git a/spec/tasks/gitlab/update_templates_rake_spec.rb b/spec/tasks/gitlab/update_templates_rake_spec.rb new file mode 100644 index 00000000000..7b17549b8c7 --- /dev/null +++ b/spec/tasks/gitlab/update_templates_rake_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'rake_helper' + +describe 'gitlab:update_project_templates rake task' do + let!(:tmpdir) { Dir.mktmpdir } + + before do + Rake.application.rake_require 'tasks/gitlab/update_templates' + create(:admin) + allow(Gitlab::ProjectTemplate) + .to receive(:archive_directory) + .and_return(Pathname.new(tmpdir)) + end + + after do + FileUtils.rm_rf(tmpdir) + end + + it 'updates valid project templates' do + expect { run_rake_task('gitlab:update_project_templates', ['rails']) } + .to change { Dir.entries(tmpdir) } + .by(['rails.tar.gz']) + end +end |