diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-12 12:10:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-12 12:10:03 +0300 |
commit | 7717a594e88951ba2b92358aa9a10a0030799678 (patch) | |
tree | 6206e93f20ee0ab44cbf31ae6dcb9d918d77fefe /app | |
parent | a20bd972bcc5e653641e6291a80957ce85958988 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
6 files changed, 146 insertions, 1 deletions
diff --git a/app/assets/javascripts/repository/components/blob_content_viewer.vue b/app/assets/javascripts/repository/components/blob_content_viewer.vue index 7ad9fb56972..2cc5a8a79d2 100644 --- a/app/assets/javascripts/repository/components/blob_content_viewer.vue +++ b/app/assets/javascripts/repository/components/blob_content_viewer.vue @@ -1,5 +1,5 @@ <script> -import { GlLoadingIcon } from '@gitlab/ui'; +import { GlLoadingIcon, GlButton } from '@gitlab/ui'; import { uniqueId } from 'lodash'; import BlobContent from '~/blob/components/blob_content.vue'; import BlobHeader from '~/blob/components/blob_header.vue'; @@ -17,12 +17,16 @@ import ForkSuggestion from './fork_suggestion.vue'; import { loadViewer, viewerProps } from './blob_viewers'; export default { + i18n: { + pipelineEditor: __('Pipeline Editor'), + }, components: { BlobHeader, BlobEdit, BlobButtonGroup, BlobContent, GlLoadingIcon, + GlButton, ForkSuggestion, }, mixins: [getRefMixin], @@ -105,6 +109,7 @@ export default { rawPath: '', externalStorageUrl: '', replacePath: '', + pipelineEditorPath: '', deletePath: '', simpleViewer: {}, richViewer: null, @@ -242,6 +247,18 @@ export default { :needs-to-fork="showForkSuggestion" @edit="editBlob" /> + + <gl-button + v-if="blobInfo.pipelineEditorPath" + class="gl-mr-3" + category="secondary" + variant="confirm" + data-testid="pipeline-editor" + :href="blobInfo.pipelineEditorPath" + > + {{ $options.i18n.pipelineEditor }} + </gl-button> + <blob-button-group v-if="isLoggedIn" :path="path" diff --git a/app/assets/javascripts/repository/queries/blob_info.query.graphql b/app/assets/javascripts/repository/queries/blob_info.query.graphql index 8e0b5e21ca3..cf3892802fd 100644 --- a/app/assets/javascripts/repository/queries/blob_info.query.graphql +++ b/app/assets/javascripts/repository/queries/blob_info.query.graphql @@ -31,6 +31,7 @@ query getBlobInfo($projectPath: ID!, $filePath: String!, $ref: String!) { storedExternally rawPath replacePath + pipelineEditorPath simpleViewer { fileType tooLarge diff --git a/app/graphql/types/repository/blob_type.rb b/app/graphql/types/repository/blob_type.rb index ef7f535212f..104171e6772 100644 --- a/app/graphql/types/repository/blob_type.rb +++ b/app/graphql/types/repository/blob_type.rb @@ -68,6 +68,9 @@ module Types field :replace_path, GraphQL::Types::String, null: true, description: 'Web path to replace the blob content.' + field :pipeline_editor_path, GraphQL::Types::String, null: true, + description: 'Web path to edit .gitlab-ci.yml file.' + field :file_type, GraphQL::Types::String, null: true, description: 'Expected format of the blob based on the extension.' diff --git a/app/models/namespaces/user_namespace.rb b/app/models/namespaces/user_namespace.rb index 22b7a0a3b2b..d4d7d352e71 100644 --- a/app/models/namespaces/user_namespace.rb +++ b/app/models/namespaces/user_namespace.rb @@ -3,6 +3,26 @@ # TODO: currently not created/mapped in the database, will be done in another issue # https://gitlab.com/gitlab-org/gitlab/-/issues/341070 module Namespaces + #################################################################### + # PLEASE DO NOT OVERRIDE METHODS IN THIS CLASS! + # + # This class is a placeholder for STI. But we also want to ensure + # tests using `:namespace` factory are still testing the same functionality. + # + # Many legacy tests use `:namespace` which has a slight semantic + # mismatch as it always has been a User (personal) namespace. + # + # If you need to make a change here, please ping the + # Manage/Workspaces group so we can ensure that the + # changes do not break existing functionality. + # + # As Namespaces evolve we may be able to relax this restriction + # but for now, please check in with us <3 + # + # For details, see the discussion in + # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/74152 + #################################################################### + class UserNamespace < Namespace def self.sti_name 'User' diff --git a/app/presenters/blob_presenter.rb b/app/presenters/blob_presenter.rb index 38e30f26033..866b19db145 100644 --- a/app/presenters/blob_presenter.rb +++ b/app/presenters/blob_presenter.rb @@ -62,6 +62,10 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated url_helpers.project_create_blob_path(project, ref_qualified_path) end + def pipeline_editor_path + project_ci_pipeline_editor_path(project, branch_name: blob.commit_id) if can_collaborate_with_project?(project) && blob.path == project.ci_config_path_or_default + end + def fork_and_edit_path fork_path_for_current_user(project, edit_blob_path) end diff --git a/app/presenters/projects/security/configuration_presenter.rb b/app/presenters/projects/security/configuration_presenter.rb new file mode 100644 index 00000000000..8f8f5bea0b6 --- /dev/null +++ b/app/presenters/projects/security/configuration_presenter.rb @@ -0,0 +1,100 @@ +# frozen_string_literal: true + +module Projects + module Security + class ConfigurationPresenter < Gitlab::View::Presenter::Delegated + include AutoDevopsHelper + include ::Security::LatestPipelineInformation + + delegator_override_with Gitlab::Utils::StrongMemoize + + presents ::Project, as: :project + + def to_h + { + auto_devops_enabled: auto_devops_source?, + auto_devops_help_page_path: help_page_path('topics/autodevops/index'), + auto_devops_path: auto_devops_settings_path(project), + can_enable_auto_devops: can_enable_auto_devops?, + features: features, + help_page_path: help_page_path('user/application_security/index'), + latest_pipeline_path: latest_pipeline_path, + # TODO: gitlab_ci_present will incorrectly report `false` if the CI/CD configuration file name + # has been customized and a file with the given custom name exists in the repo. This edge case + # will be addressed in https://gitlab.com/gitlab-org/gitlab/-/issues/342465 + gitlab_ci_present: project.repository.gitlab_ci_yml.present?, + gitlab_ci_history_path: gitlab_ci_history_path, + auto_fix_enabled: autofix_enabled, + can_toggle_auto_fix_settings: can_toggle_autofix, + auto_fix_user_path: auto_fix_user_path + } + end + + def to_html_data_attribute + data = to_h + data[:features] = data[:features].to_json + data[:auto_fix_enabled] = data[:auto_fix_enabled].to_json + + data + end + + private + + def autofix_enabled; end + + def auto_fix_user_path; end + + def can_enable_auto_devops? + feature_available?(:builds, current_user) && + can?(current_user, :admin_project, self) && + !archived? + end + + def can_toggle_autofix; end + + def gitlab_ci_history_path + return '' if project.empty_repo? + + gitlab_ci = ::Gitlab::FileDetector::PATTERNS[:gitlab_ci] + ::Gitlab::Routing.url_helpers.project_blame_path(project, File.join(project.default_branch_or_main, gitlab_ci)) + end + + def features + scans = scan_types.map do |scan_type| + scan(scan_type, configured: scanner_enabled?(scan_type)) + end + + # These scans are "fake" (non job) entries. Add them manually. + scans << scan(:corpus_management, configured: true) + scans << scan(:dast_profiles, configured: true) + end + + def latest_pipeline_path + return help_page_path('ci/pipelines') unless latest_default_branch_pipeline + + project_pipeline_path(self, latest_default_branch_pipeline) + end + + def scan(type, configured: false) + scan = ::Gitlab::Security::ScanConfiguration.new(project: project, type: type, configured: configured) + + { + type: scan.type, + configured: scan.configured?, + configuration_path: scan.configuration_path, + available: scan.available? + } + end + + def scan_types + ::Security::SecurityJobsFinder.allowed_job_types + ::Security::LicenseComplianceJobsFinder.allowed_job_types + end + + def project_settings + project.security_setting + end + end + end +end + +Projects::Security::ConfigurationPresenter.prepend_mod_with('Projects::Security::ConfigurationPresenter') |