Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.markdownlint.json1
-rw-r--r--app/assets/javascripts/snippets/components/edit.vue2
-rw-r--r--app/assets/javascripts/snippets/components/show.vue2
-rw-r--r--app/assets/javascripts/snippets/components/snippet_blob_edit.vue2
-rw-r--r--app/assets/javascripts/vue_merge_request_widget/components/states/ready_to_merge.vue12
-rw-r--r--app/assets/stylesheets/framework/lists.scss6
-rw-r--r--app/assets/stylesheets/pages/members.scss4
-rw-r--r--app/controllers/projects/forks_controller.rb13
-rw-r--r--app/finders/fork_targets_finder.rb6
-rw-r--r--app/graphql/gitlab_schema.rb4
-rw-r--r--app/graphql/mutations/metrics/dashboard/annotations/delete.rb2
-rw-r--r--app/graphql/types/jira_user_type.rb2
-rw-r--r--app/models/issue.rb27
-rw-r--r--app/models/issue_link.rb38
-rw-r--r--app/models/system_note_metadata.rb3
-rw-r--r--app/serializers/fork_namespace_entity.rb6
-rw-r--r--app/serializers/linked_issue_entity.rb37
-rw-r--r--app/serializers/linked_project_issue_entity.rb29
-rw-r--r--app/serializers/linked_project_issue_serializer.rb5
-rw-r--r--app/services/issuable_links/create_service.rb115
-rw-r--r--app/services/issuable_links/destroy_service.rb31
-rw-r--r--app/services/issuable_links/list_service.rb27
-rw-r--r--app/services/issue_links/create_service.rb42
-rw-r--r--app/services/issue_links/destroy_service.rb24
-rw-r--r--app/services/issue_links/list_service.rb18
-rw-r--r--app/services/issues/duplicate_service.rb9
-rw-r--r--app/services/issues/move_service.rb9
-rw-r--r--app/services/projects/fork_service.rb4
-rw-r--r--app/services/quick_actions/interpret_service.rb1
-rw-r--r--app/services/system_note_service.rb8
-rw-r--r--app/services/system_notes/issuables_service.rb28
-rw-r--r--app/views/admin/dashboard/index.html.haml4
-rw-r--r--app/views/shared/members/_member.html.haml2
-rw-r--r--changelogs/unreleased/235912-fork-interface-with-prevent-forking-outside-a-group-is-extremely-s.yml5
-rw-r--r--changelogs/unreleased/remove-upcoming-db-deprecation-warning.yml5
-rw-r--r--config/routes/issues.rb2
-rw-r--r--doc/administration/auth/cognito.md2
-rw-r--r--doc/administration/gitaly/index.md18
-rw-r--r--doc/administration/troubleshooting/tracing_correlation_id.md2
-rw-r--r--doc/api/feature_flags.md4
-rw-r--r--doc/api/graphql/getting_started.md4
-rw-r--r--doc/api/graphql/reference/gitlab_schema.graphql4
-rw-r--r--doc/api/graphql/reference/gitlab_schema.json4
-rw-r--r--doc/api/graphql/reference/index.md2
-rw-r--r--doc/api/services.md2
-rw-r--r--doc/ci/directed_acyclic_graph/index.md2
-rw-r--r--doc/ci/multi_project_pipelines.md3
-rw-r--r--doc/development/documentation/feature_flags.md4
-rw-r--r--doc/development/elasticsearch.md2
-rw-r--r--doc/development/geo/framework.md2
-rw-r--r--doc/development/telemetry/snowplow.md2
-rw-r--r--doc/development/telemetry/usage_ping.md77
-rw-r--r--doc/integration/salesforce.md2
-rw-r--r--doc/operations/feature_flags.md4
-rw-r--r--doc/operations/incident_management/alerts.md8
-rw-r--r--doc/operations/incident_management/generic_alerts.md125
-rw-r--r--doc/operations/incident_management/img/alert_list_v13_1.png (renamed from doc/user/project/operations/img/alert_list_v13_1.png)bin38265 -> 38265 bytes
-rw-r--r--doc/operations/incident_management/index.md2
-rw-r--r--doc/operations/metrics/alerts.md2
-rw-r--r--doc/operations/product_analytics.md4
-rw-r--r--doc/user/application_security/dast/index.md4
-rw-r--r--doc/user/group/iterations/index.md4
-rw-r--r--doc/user/group/saml_sso/group_managed_accounts.md3
-rw-r--r--doc/user/project/integrations/generic_alerts.md124
-rw-r--r--doc/user/project/integrations/overview.md2
-rw-r--r--doc/user/project/integrations/servicenow.md41
-rw-r--r--doc/user/project/merge_requests/squash_and_merge.md4
-rw-r--r--lib/gitlab/config_checker/external_database_checker.rb55
-rw-r--r--lib/gitlab/database.rb30
-rw-r--r--lib/gitlab/quick_actions/relate_actions.rb29
-rw-r--r--locale/gitlab.pot10
-rw-r--r--spec/factories/issue_links.rb8
-rw-r--r--spec/finders/fork_targets_finder_spec.rb8
-rw-r--r--spec/frontend/add_context_commits_modal/components/__snapshots__/add_context_commits_modal_spec.js.snap2
-rw-r--r--spec/graphql/mutations/discussions/toggle_resolve_spec.rb2
-rw-r--r--spec/lib/gitlab/config_checker/external_database_checker_spec.rb81
-rw-r--r--spec/lib/gitlab/database_spec.rb40
-rw-r--r--spec/models/issue_link_spec.rb53
-rw-r--r--spec/models/issue_spec.rb44
-rw-r--r--spec/requests/api/graphql/mutations/metrics/dashboard/annotations/create_spec.rb4
-rw-r--r--spec/requests/api/graphql/mutations/metrics/dashboard/annotations/delete_spec.rb2
-rw-r--r--spec/requests/api/graphql/mutations/todos/mark_done_spec.rb2
-rw-r--r--spec/requests/api/graphql/mutations/todos/restore_spec.rb2
-rw-r--r--spec/serializers/fork_namespace_entity_spec.rb9
-rw-r--r--spec/serializers/linked_project_issue_entity_spec.rb23
-rw-r--r--spec/services/issue_links/create_service_spec.rb176
-rw-r--r--spec/services/issue_links/destroy_service_spec.rb61
-rw-r--r--spec/services/issue_links/list_service_spec.rb194
-rw-r--r--spec/services/issues/duplicate_service_spec.rb11
-rw-r--r--spec/services/issues/move_service_spec.rb39
-rw-r--r--spec/services/notes/quick_actions_service_spec.rb36
-rw-r--r--spec/services/quick_actions/interpret_service_spec.rb97
-rw-r--r--spec/services/system_note_service_spec.rb34
-rw-r--r--spec/services/system_notes/issuables_service_spec.rb32
94 files changed, 1674 insertions, 408 deletions
diff --git a/.markdownlint.json b/.markdownlint.json
index 1c276dc42ba..88273682d3a 100644
--- a/.markdownlint.json
+++ b/.markdownlint.json
@@ -71,6 +71,7 @@
"Gzip",
"Helm",
"HipChat",
+ "ID",
"Ingress",
"jasmine-jquery",
"JavaScript",
diff --git a/app/assets/javascripts/snippets/components/edit.vue b/app/assets/javascripts/snippets/components/edit.vue
index 2c067a36f75..22cb0e1a718 100644
--- a/app/assets/javascripts/snippets/components/edit.vue
+++ b/app/assets/javascripts/snippets/components/edit.vue
@@ -204,7 +204,7 @@ export default {
v-if="isLoading"
:label="__('Loading snippet')"
size="lg"
- class="loading-animation prepend-top-20 append-bottom-20"
+ class="loading-animation prepend-top-20 gl-mb-6"
/>
<template v-else>
<title-field
diff --git a/app/assets/javascripts/snippets/components/show.vue b/app/assets/javascripts/snippets/components/show.vue
index ca41fd0a2b1..46954ab864c 100644
--- a/app/assets/javascripts/snippets/components/show.vue
+++ b/app/assets/javascripts/snippets/components/show.vue
@@ -40,7 +40,7 @@ export default {
v-if="isLoading"
:label="__('Loading snippet')"
size="lg"
- class="loading-animation prepend-top-20 append-bottom-20"
+ class="loading-animation prepend-top-20 gl-mb-6"
/>
<template v-else>
<snippet-header :snippet="snippet" />
diff --git a/app/assets/javascripts/snippets/components/snippet_blob_edit.vue b/app/assets/javascripts/snippets/components/snippet_blob_edit.vue
index ff03432f942..74c6b633ef7 100644
--- a/app/assets/javascripts/snippets/components/snippet_blob_edit.vue
+++ b/app/assets/javascripts/snippets/components/snippet_blob_edit.vue
@@ -80,7 +80,7 @@ export default {
v-if="!blob.isLoaded"
:label="__('Loading snippet')"
size="lg"
- class="loading-animation prepend-top-20 append-bottom-20"
+ class="loading-animation prepend-top-20 gl-mb-6"
/>
<blob-content-edit
v-else
diff --git a/app/assets/javascripts/vue_merge_request_widget/components/states/ready_to_merge.vue b/app/assets/javascripts/vue_merge_request_widget/components/states/ready_to_merge.vue
index 930a2b68d8e..1b858354db7 100644
--- a/app/assets/javascripts/vue_merge_request_widget/components/states/ready_to_merge.vue
+++ b/app/assets/javascripts/vue_merge_request_widget/components/states/ready_to_merge.vue
@@ -1,6 +1,6 @@
<script>
import { isEmpty } from 'lodash';
-import { GlIcon, GlDeprecatedButton, GlSprintf, GlLink } from '@gitlab/ui';
+import { GlIcon, GlButton, GlSprintf, GlLink } from '@gitlab/ui';
import successSvg from 'icons/_icon_status_success.svg';
import warningSvg from 'icons/_icon_status_warning.svg';
import readyToMergeMixin from 'ee_else_ce/vue_merge_request_widget/mixins/ready_to_merge';
@@ -37,7 +37,7 @@ export default {
GlIcon,
GlSprintf,
GlLink,
- GlDeprecatedButton,
+ GlButton,
MergeTrainHelperText: () =>
import('ee_component/vue_merge_request_widget/components/merge_train_helper_text.vue'),
MergeImmediatelyConfirmationDialog: () =>
@@ -297,16 +297,16 @@ export default {
<div class="media-body">
<div class="mr-widget-body-controls media space-children">
<span class="btn-group">
- <gl-deprecated-button
- size="sm"
+ <gl-button
+ size="medium"
+ category="primary"
class="qa-merge-button accept-merge-request"
:variant="mergeButtonVariant"
:disabled="isMergeButtonDisabled"
:loading="isMakingRequest"
@click="handleMergeButtonClick(isAutoMergeAvailable)"
+ >{{ mergeButtonText }}</gl-button
>
- {{ mergeButtonText }}
- </gl-deprecated-button>
<button
v-if="shouldShowMergeImmediatelyDropdown"
:disabled="isMergeButtonDisabled"
diff --git a/app/assets/stylesheets/framework/lists.scss b/app/assets/stylesheets/framework/lists.scss
index 738150dbd2e..9d67b175294 100644
--- a/app/assets/stylesheets/framework/lists.scss
+++ b/app/assets/stylesheets/framework/lists.scss
@@ -132,10 +132,10 @@ ul.content-list {
a {
color: $gl-text-color;
- }
- .member-group-link {
- color: $blue-600;
+ &.inline-link {
+ color: $blue-600;
+ }
}
.description {
diff --git a/app/assets/stylesheets/pages/members.scss b/app/assets/stylesheets/pages/members.scss
index 54bca80194f..2d9a9f3029f 100644
--- a/app/assets/stylesheets/pages/members.scss
+++ b/app/assets/stylesheets/pages/members.scss
@@ -180,10 +180,6 @@
word-break: break-all;
}
- .member-group-link {
- display: inline-block;
- }
-
.form-control {
width: inherit;
}
diff --git a/app/controllers/projects/forks_controller.rb b/app/controllers/projects/forks_controller.rb
index 41631aea620..c6b6b825bb7 100644
--- a/app/controllers/projects/forks_controller.rb
+++ b/app/controllers/projects/forks_controller.rb
@@ -43,9 +43,10 @@ class Projects::ForksController < Projects::ApplicationController
end
format.json do
- namespaces = fork_service.valid_fork_targets - [current_user.namespace, project.namespace]
+ namespaces = load_namespaces_with_associations - [project.namespace]
+
render json: {
- namespaces: ForkNamespaceSerializer.new.represent(namespaces, project: project, current_user: current_user)
+ namespaces: ForkNamespaceSerializer.new.represent(namespaces, project: project, current_user: current_user, memberships: memberships_hash)
}
end
end
@@ -100,6 +101,14 @@ class Projects::ForksController < Projects::ApplicationController
def whitelist_query_limiting
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/42335')
end
+
+ def load_namespaces_with_associations
+ @load_namespaces_with_associations ||= fork_service.valid_fork_targets(only_groups: true).preload(:route)
+ end
+
+ def memberships_hash
+ current_user.members.where(source: load_namespaces_with_associations).index_by(&:source_id)
+ end
end
Projects::ForksController.prepend_if_ee('EE::Projects::ForksController')
diff --git a/app/finders/fork_targets_finder.rb b/app/finders/fork_targets_finder.rb
index 7a08273fa0d..719c244a207 100644
--- a/app/finders/fork_targets_finder.rb
+++ b/app/finders/fork_targets_finder.rb
@@ -7,8 +7,10 @@ class ForkTargetsFinder
end
# rubocop: disable CodeReuse/ActiveRecord
- def execute
- ::Namespace.where(id: user.manageable_namespaces).sort_by_type
+ def execute(options = {})
+ return ::Namespace.where(id: user.manageable_namespaces).sort_by_type unless options[:only_groups]
+
+ ::Group.where(id: user.manageable_groups)
end
# rubocop: enable CodeReuse/ActiveRecord
diff --git a/app/graphql/gitlab_schema.rb b/app/graphql/gitlab_schema.rb
index d8967da9f57..2f5043f9ffa 100644
--- a/app/graphql/gitlab_schema.rb
+++ b/app/graphql/gitlab_schema.rb
@@ -116,11 +116,11 @@ class GitlabSchema < GraphQL::Schema
expected_type = ctx[:expected_type]
gid = GlobalID.parse(global_id)
- raise Gitlab::Graphql::Errors::ArgumentError, "#{global_id} is not a valid GitLab id." unless gid
+ raise Gitlab::Graphql::Errors::ArgumentError, "#{global_id} is not a valid GitLab ID." unless gid
if expected_type && !gid.model_class.ancestors.include?(expected_type)
vars = { global_id: global_id, expected_type: expected_type }
- msg = _('%{global_id} is not a valid id for %{expected_type}.') % vars
+ msg = _('%{global_id} is not a valid ID for %{expected_type}.') % vars
raise Gitlab::Graphql::Errors::ArgumentError, msg
end
diff --git a/app/graphql/mutations/metrics/dashboard/annotations/delete.rb b/app/graphql/mutations/metrics/dashboard/annotations/delete.rb
index fb828ba0e2f..6e183e78d9b 100644
--- a/app/graphql/mutations/metrics/dashboard/annotations/delete.rb
+++ b/app/graphql/mutations/metrics/dashboard/annotations/delete.rb
@@ -12,7 +12,7 @@ module Mutations
argument :id,
GraphQL::ID_TYPE,
required: true,
- description: 'The global id of the annotation to delete'
+ description: 'The global ID of the annotation to delete'
def resolve(id:)
annotation = authorized_find!(id: id)
diff --git a/app/graphql/types/jira_user_type.rb b/app/graphql/types/jira_user_type.rb
index 999526a920e..394820d23be 100644
--- a/app/graphql/types/jira_user_type.rb
+++ b/app/graphql/types/jira_user_type.rb
@@ -7,7 +7,7 @@ module Types
graphql_name 'JiraUser'
field :jira_account_id, GraphQL::STRING_TYPE, null: false,
- description: 'Account id of the Jira user'
+ description: 'Account ID of the Jira user'
field :jira_display_name, GraphQL::STRING_TYPE, null: false,
description: 'Display name of the Jira user'
field :jira_email, GraphQL::STRING_TYPE, null: true,
diff --git a/app/models/issue.rb b/app/models/issue.rb
index a0003df87e1..ba7c9c1e5c2 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -305,6 +305,24 @@ class Issue < ApplicationRecord
end
end
+ def related_issues(current_user, preload: nil)
+ related_issues = ::Issue
+ .select(['issues.*', 'issue_links.id AS issue_link_id',
+ 'issue_links.link_type as issue_link_type_value',
+ 'issue_links.target_id as issue_link_source_id'])
+ .joins("INNER JOIN issue_links ON
+ (issue_links.source_id = issues.id AND issue_links.target_id = #{id})
+ OR
+ (issue_links.target_id = issues.id AND issue_links.source_id = #{id})")
+ .preload(preload)
+ .reorder('issue_link_id')
+
+ cross_project_filter = -> (issues) { issues.where(project: project) }
+ Ability.issues_readable_by_user(related_issues,
+ current_user,
+ filters: { read_cross_project: cross_project_filter })
+ end
+
def can_be_worked_on?
!self.closed? && !self.project.forked?
end
@@ -378,6 +396,15 @@ class Issue < ApplicationRecord
author.id == User.support_bot.id
end
+ def issue_link_type
+ return unless respond_to?(:issue_link_type_value) && respond_to?(:issue_link_source_id)
+
+ type = IssueLink.link_types.key(issue_link_type_value) || IssueLink::TYPE_RELATES_TO
+ return type if issue_link_source_id == id
+
+ IssueLink.inverse_link_type(type)
+ end
+
private
def ensure_metrics
diff --git a/app/models/issue_link.rb b/app/models/issue_link.rb
new file mode 100644
index 00000000000..9740b009396
--- /dev/null
+++ b/app/models/issue_link.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+class IssueLink < ApplicationRecord
+ include FromUnion
+
+ belongs_to :source, class_name: 'Issue'
+ belongs_to :target, class_name: 'Issue'
+
+ validates :source, presence: true
+ validates :target, presence: true
+ validates :source, uniqueness: { scope: :target_id, message: 'is already related' }
+ validate :check_self_relation
+
+ scope :for_source_issue, ->(issue) { where(source_id: issue.id) }
+ scope :for_target_issue, ->(issue) { where(target_id: issue.id) }
+
+ TYPE_RELATES_TO = 'relates_to'
+ TYPE_BLOCKS = 'blocks'
+ TYPE_IS_BLOCKED_BY = 'is_blocked_by'
+
+ enum link_type: { TYPE_RELATES_TO => 0, TYPE_BLOCKS => 1, TYPE_IS_BLOCKED_BY => 2 }
+
+ def self.inverse_link_type(type)
+ type
+ end
+
+ private
+
+ def check_self_relation
+ return unless source && target
+
+ if source == target
+ errors.add(:source, 'cannot be related to itself')
+ end
+ end
+end
+
+IssueLink.prepend_if_ee('EE::IssueLink')
diff --git a/app/models/system_note_metadata.rb b/app/models/system_note_metadata.rb
index b6ba96c768e..f464939fa42 100644
--- a/app/models/system_note_metadata.rb
+++ b/app/models/system_note_metadata.rb
@@ -11,6 +11,7 @@ class SystemNoteMetadata < ApplicationRecord
close duplicate
moved merge
label milestone
+ relate unrelate
].freeze
ICON_TYPES = %w[
@@ -19,7 +20,7 @@ class SystemNoteMetadata < ApplicationRecord
title time_tracking branch milestone discussion task moved
opened closed merged duplicate locked unlocked outdated
tag due_date pinned_embed cherry_pick health_status approved unapproved
- status alert_issue_added
+ status alert_issue_added relate unrelate
].freeze
validates :note, presence: true
diff --git a/app/serializers/fork_namespace_entity.rb b/app/serializers/fork_namespace_entity.rb
index 068862e0951..abfaf4be811 100644
--- a/app/serializers/fork_namespace_entity.rb
+++ b/app/serializers/fork_namespace_entity.rb
@@ -19,7 +19,7 @@ class ForkNamespaceEntity < Grape::Entity
end
expose :permission do |namespace, options|
- membership(options[:current_user], namespace)&.human_access
+ membership(options[:current_user], namespace, options[:memberships])&.human_access
end
expose :relative_path do |namespace|
@@ -37,10 +37,10 @@ class ForkNamespaceEntity < Grape::Entity
private
# rubocop: disable CodeReuse/ActiveRecord
- def membership(user, object)
+ def membership(user, object, memberships)
return unless user
- @membership ||= user.members.find_by(source: object)
+ memberships[object.id]
end
# rubocop: enable CodeReuse/ActiveRecord
diff --git a/app/serializers/linked_issue_entity.rb b/app/serializers/linked_issue_entity.rb
new file mode 100644
index 00000000000..6ae3f4044db
--- /dev/null
+++ b/app/serializers/linked_issue_entity.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+class LinkedIssueEntity < Grape::Entity
+ include RequestAwareEntity
+
+ expose :id, :confidential, :title
+
+ expose :assignees, using: UserEntity
+
+ expose :state
+
+ expose :milestone, using: API::Entities::Milestone
+
+ expose :weight
+
+ expose :reference do |link|
+ link.to_reference(issuable.project)
+ end
+
+ expose :path do |link|
+ project_issue_path(link.project, link.iid)
+ end
+
+ expose :relation_path
+
+ expose :due_date, :created_at, :closed_at
+
+ private
+
+ def current_user
+ request.current_user
+ end
+
+ def issuable
+ request.issuable
+ end
+end
diff --git a/app/serializers/linked_project_issue_entity.rb b/app/serializers/linked_project_issue_entity.rb
new file mode 100644
index 00000000000..c95f68f58a3
--- /dev/null
+++ b/app/serializers/linked_project_issue_entity.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+class LinkedProjectIssueEntity < LinkedIssueEntity
+ include Gitlab::Utils::StrongMemoize
+
+ expose :relation_path, override: true do |issue|
+ # Make sure the user can admin both the current issue AND the
+ # referenced issue projects in order to return the removal link.
+ if can_admin_issue_link_on_current_project? && can_admin_issue_link?(issue.project)
+ project_issue_link_path(issuable.project, issuable.iid, issue.issue_link_id)
+ end
+ end
+
+ expose :link_type do |issue|
+ issue.issue_link_type
+ end
+
+ private
+
+ def can_admin_issue_link_on_current_project?
+ strong_memoize(:can_admin_on_current_project) do
+ can_admin_issue_link?(issuable.project)
+ end
+ end
+
+ def can_admin_issue_link?(project)
+ Ability.allowed?(current_user, :admin_issue_link, project)
+ end
+end
diff --git a/app/serializers/linked_project_issue_serializer.rb b/app/serializers/linked_project_issue_serializer.rb
new file mode 100644
index 00000000000..3015e593e34
--- /dev/null
+++ b/app/serializers/linked_project_issue_serializer.rb
@@ -0,0 +1,5 @@
+# frozen_string_literal: true
+
+class LinkedProjectIssueSerializer < BaseSerializer
+ entity LinkedProjectIssueEntity
+end
diff --git a/app/services/issuable_links/create_service.rb b/app/services/issuable_links/create_service.rb
new file mode 100644
index 00000000000..675d4e5fc88
--- /dev/null
+++ b/app/services/issuable_links/create_service.rb
@@ -0,0 +1,115 @@
+# frozen_string_literal: true
+
+module IssuableLinks
+ class CreateService < BaseService
+ attr_reader :issuable, :current_user, :params
+
+ def initialize(issuable, user, params)
+ @issuable, @current_user, @params = issuable, user, params.dup
+ end
+
+ def execute
+ # If ALL referenced issues are already assigned to the given epic it renders a conflict status,
+ # otherwise create issue links for the issues which
+ # are still not assigned and return success message.
+ if render_conflict_error?
+ return error(issuables_assigned_message, 409)
+ end
+
+ if render_not_found_error?
+ return error(issuables_not_found_message, 404)
+ end
+
+ @errors = []
+ create_links
+
+ if @errors.present?
+ return error(@errors.join('. '), 422)
+ end
+
+ success
+ end
+
+ private
+
+ def render_conflict_error?
+ referenced_issuables.present? && (referenced_issuables - previous_related_issuables).empty?
+ end
+
+ def render_not_found_error?
+ linkable_issuables(referenced_issuables).empty?
+ end
+
+ def create_links
+ objects = linkable_issuables(referenced_issuables)
+ link_issuables(objects)
+ end
+
+ def link_issuables(target_issuables)
+ target_issuables.each do |referenced_object|
+ link = relate_issuables(referenced_object)
+
+ unless link.valid?
+ @errors << _("%{ref} cannot be added: %{error}") % {
+ ref: referenced_object.to_reference,
+ error: link.errors.messages.values.flatten.to_sentence
+ }
+ end
+ end
+ end
+
+ def referenced_issuables
+ @referenced_issuables ||= begin
+ target_issuable = params[:target_issuable]
+
+ if params[:issuable_references].present?
+ extract_references
+ elsif target_issuable
+ [target_issuable]
+ else
+ []
+ end
+ end
+ end
+
+ def extract_references
+ issuable_references = params[:issuable_references]
+ text = issuable_references.join(' ')
+
+ extractor = Gitlab::ReferenceExtractor.new(issuable.project, current_user)
+ extractor.analyze(text, extractor_context)
+
+ references(extractor)
+ end
+
+ def references(extractor)
+ extractor.issues
+ end
+
+ def extractor_context
+ {}
+ end
+
+ def linkable_issuables(objects)
+ raise NotImplementedError
+ end
+
+ def previous_related_issuables
+ raise NotImplementedError
+ end
+
+ def relate_issuables(referenced_object)
+ raise NotImplementedError
+ end
+
+ def issuables_assigned_message
+ 'Issue(s) already assigned'
+ end
+
+ def issuables_not_found_message
+ 'No Issue found for given params'
+ end
+ end
+end
+
+IssuableLinks::CreateService.prepend_if_ee('EE::IssuableLinks::CreateService')
diff --git a/app/services/issuable_links/destroy_service.rb b/app/services/issuable_links/destroy_service.rb
new file mode 100644
index 00000000000..9761f743e87
--- /dev/null
+++ b/app/services/issuable_links/destroy_service.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+module IssuableLinks
+ class DestroyService < BaseService
+ attr_reader :link, :current_user
+
+ def initialize(link, user)
+ @link = link
+ @current_user = user
+ end
+
+ def execute
+ return error(not_found_message, 404) unless permission_to_remove_relation?
+
+ remove_relation
+ create_notes
+
+ success(message: 'Relation was removed')
+ end
+
+ private
+
+ def remove_relation
+ link.destroy!
+ end
+
+ def not_found_message
+ 'No Issue Link found'
+ end
+ end
+end
diff --git a/app/services/issuable_links/list_service.rb b/app/services/issuable_links/list_service.rb
new file mode 100644
index 00000000000..10a2da7eb03
--- /dev/null
+++ b/app/services/issuable_links/list_service.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+module IssuableLinks
+ class ListService
+ include Gitlab::Routing
+
+ attr_reader :issuable, :current_user
+
+ def initialize(issuable, user)
+ @issuable, @current_user = issuable, user
+ end
+
+ def execute
+ serializer.new(current_user: current_user, issuable: issuable).represent(child_issuables)
+ end
+
+ private
+
+ def serializer
+ raise NotImplementedError
+ end
+
+ def preload_for_collection
+ [{ project: :namespace }, :assignees]
+ end
+ end
+end
diff --git a/app/services/issue_links/create_service.rb b/app/services/issue_links/create_service.rb
new file mode 100644
index 00000000000..69fd13c2874
--- /dev/null
+++ b/app/services/issue_links/create_service.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+module IssueLinks
+ class CreateService < IssuableLinks::CreateService
+ # rubocop: disable CodeReuse/ActiveRecord
+ def relate_issuables(referenced_issue)
+ link = IssueLink.find_or_initialize_by(source: issuable, target: referenced_issue)
+
+ set_link_type(link)
+
+ if link.changed? && link.save
+ create_notes(referenced_issue)
+ end
+
+ link
+ end
+ # rubocop: enable CodeReuse/ActiveRecord
+
+ def linkable_issuables(issues)
+ @linkable_issuables ||= begin
+ issues.select { |issue| can?(current_user, :admin_issue_link, issue) }
+ end
+ end
+
+ def create_notes(referenced_issue)
+ SystemNoteService.relate_issue(issuable, referenced_issue, current_user)
+ SystemNoteService.relate_issue(referenced_issue, issuable, current_user)
+ end
+
+ def previous_related_issuables
+ @related_issues ||= issuable.related_issues(current_user).to_a
+ end
+
+ private
+
+ def set_link_type(_link)
+ # EE only
+ end
+ end
+end
+
+IssueLinks::CreateService.prepend_if_ee('EE::IssueLinks::CreateService')
diff --git a/app/services/issue_links/destroy_service.rb b/app/services/issue_links/destroy_service.rb
new file mode 100644
index 00000000000..3af4e33d7a0
--- /dev/null
+++ b/app/services/issue_links/destroy_service.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+module IssueLinks
+ class DestroyService < IssuableLinks::DestroyService
+ private
+
+ def source
+ @source ||= link.source
+ end
+
+ def target
+ @target ||= link.target
+ end
+
+ def permission_to_remove_relation?
+ can?(current_user, :admin_issue_link, source) && can?(current_user, :admin_issue_link, target)
+ end
+
+ def create_notes
+ SystemNoteService.unrelate_issue(source, target, current_user)
+ SystemNoteService.unrelate_issue(target, source, current_user)
+ end
+ end
+end
diff --git a/app/services/issue_links/list_service.rb b/app/services/issue_links/list_service.rb
new file mode 100644
index 00000000000..5ac731d3fbc
--- /dev/null
+++ b/app/services/issue_links/list_service.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+module IssueLinks
+ class ListService < IssuableLinks::ListService
+ extend ::Gitlab::Utils::Override
+
+ private
+
+ def child_issuables
+ issuable.related_issues(current_user, preload: preload_for_collection)
+ end
+
+ override :serializer
+ def serializer
+ LinkedProjectIssueSerializer
+ end
+ end
+end
diff --git a/app/services/issues/duplicate_service.rb b/app/services/issues/duplicate_service.rb
index c936d75e277..feb496542c8 100644
--- a/app/services/issues/duplicate_service.rb
+++ b/app/services/issues/duplicate_service.rb
@@ -12,6 +12,8 @@ module Issues
close_service.new(project, current_user, {}).execute(duplicate_issue)
duplicate_issue.update(duplicated_to: canonical_issue)
+
+ relate_two_issues(duplicate_issue, canonical_issue)
end
private
@@ -23,7 +25,10 @@ module Issues
def create_issue_canonical_note(canonical_issue, duplicate_issue)
SystemNoteService.mark_canonical_issue_of_duplicate(canonical_issue, canonical_issue.project, current_user, duplicate_issue)
end
+
+ def relate_two_issues(duplicate_issue, canonical_issue)
+ params = { target_issuable: canonical_issue }
+ IssueLinks::CreateService.new(duplicate_issue, current_user, params).execute
+ end
end
end
-
-Issues::DuplicateService.prepend_if_ee('EE::Issues::DuplicateService')
diff --git a/app/services/issues/move_service.rb b/app/services/issues/move_service.rb
index ce1466307e1..a0bc69e0c46 100644
--- a/app/services/issues/move_service.rb
+++ b/app/services/issues/move_service.rb
@@ -38,6 +38,7 @@ module Issues
def update_old_entity
super
+ rewrite_related_issues
mark_as_moved
end
@@ -58,6 +59,14 @@ module Issues
original_entity.update(moved_to: new_entity)
end
+ def rewrite_related_issues
+ source_issue_links = IssueLink.for_source_issue(original_entity)
+ source_issue_links.update_all(source_id: new_entity.id)
+
+ target_issue_links = IssueLink.for_target_issue(original_entity)
+ target_issue_links.update_all(target_id: new_entity.id)
+ end
+
def notify_participants
notification_service.async.issue_moved(original_entity, new_entity, @current_user)
end
diff --git a/app/services/projects/fork_service.rb b/app/services/projects/fork_service.rb
index bb660d47887..0b4963e356a 100644
--- a/app/services/projects/fork_service.rb
+++ b/app/services/projects/fork_service.rb
@@ -10,8 +10,8 @@ module Projects
forked_project
end
- def valid_fork_targets
- @valid_fork_targets ||= ForkTargetsFinder.new(@project, current_user).execute
+ def valid_fork_targets(options = {})
+ @valid_fork_targets ||= ForkTargetsFinder.new(@project, current_user).execute(options)
end
def valid_fork_target?(namespace = target_namespace)
diff --git a/app/services/quick_actions/interpret_service.rb b/app/services/quick_actions/interpret_service.rb
index a781eacc40e..de1cd7cd981 100644
--- a/app/services/quick_actions/interpret_service.rb
+++ b/app/services/quick_actions/interpret_service.rb
@@ -10,6 +10,7 @@ module QuickActions
include Gitlab::QuickActions::MergeRequestActions
include Gitlab::QuickActions::CommitActions
include Gitlab::QuickActions::CommonActions
+ include Gitlab::QuickActions::RelateActions
attr_reader :quick_action_target
diff --git a/app/services/system_note_service.rb b/app/services/system_note_service.rb
index 6702596f17c..7be94d8020e 100644
--- a/app/services/system_note_service.rb
+++ b/app/services/system_note_service.rb
@@ -45,6 +45,14 @@ module SystemNoteService
::SystemNotes::IssuablesService.new(noteable: noteable, project: project, author: author).change_milestone(milestone)
end
+ def relate_issue(noteable, noteable_ref, user)
+ ::SystemNotes::IssuablesService.new(noteable: noteable, project: noteable.project, author: user).relate_issue(noteable_ref)
+ end
+
+ def unrelate_issue(noteable, noteable_ref, user)
+ ::SystemNotes::IssuablesService.new(noteable: noteable, project: noteable.project, author: user).unrelate_issue(noteable_ref)
+ end
+
# Called when the due_date of a Noteable is changed
#
# noteable - Noteable object
diff --git a/app/services/system_notes/issuables_service.rb b/app/services/system_notes/issuables_service.rb
index 7535db54130..3c023459879 100644
--- a/app/services/system_notes/issuables_service.rb
+++ b/app/services/system_notes/issuables_service.rb
@@ -2,6 +2,34 @@
module SystemNotes
class IssuablesService < ::SystemNotes::BaseService
+ #
+ # noteable_ref - Referenced noteable object
+ #
+ # Example Note text:
+ #
+ # "marked this issue as related to gitlab-foss#9001"
+ #
+ # Returns the created Note object
+ def relate_issue(noteable_ref)
+ body = "marked this issue as related to #{noteable_ref.to_reference(noteable.project)}"
+
+ create_note(NoteSummary.new(noteable, project, author, body, action: 'relate'))
+ end
+
+ #
+ # noteable_ref - Referenced noteable object
+ #
+ # Example Note text:
+ #
+ # "removed the relation with gitlab-foss#9001"
+ #
+ # Returns the created Note object
+ def unrelate_issue(noteable_ref)
+ body = "removed the relation with #{noteable_ref.to_reference(noteable.project)}"
+
+ create_note(NoteSummary.new(noteable, project, author, body, action: 'unrelate'))
+ end
+
# Called when the assignee of a Noteable is changed or removed
#
# assignee - User being assigned, or nil
diff --git a/app/views/admin/dashboard/index.html.haml b/app/views/admin/dashboard/index.html.haml
index 271ab12037e..8c9e98765aa 100644
--- a/app/views/admin/dashboard/index.html.haml
+++ b/app/views/admin/dashboard/index.html.haml
@@ -7,8 +7,8 @@
dismissible: true.to_s } }
= notice[:message].html_safe
-- if show_license_breakdown?
- = render_if_exists 'admin/licenses/breakdown', license: @license
+- if @license.present? && show_license_breakdown?
+ = render_if_exists 'admin/licenses/breakdown'
.admin-dashboard.gl-mt-3
.row
diff --git a/app/views/shared/members/_member.html.haml b/app/views/shared/members/_member.html.haml
index 20473b47484..fa71f4dc9b9 100644
--- a/app/views/shared/members/_member.html.haml
+++ b/app/views/shared/members/_member.html.haml
@@ -33,7 +33,7 @@
- if source.instance_of?(Group) && source != @group
&middot;
- = link_to source.full_name, source, class: "member-group-link"
+ = link_to source.full_name, source, class: "gl-display-inline-block inline-link"
.cgray
- if member.request?
diff --git a/changelogs/unreleased/235912-fork-interface-with-prevent-forking-outside-a-group-is-extremely-s.yml b/changelogs/unreleased/235912-fork-interface-with-prevent-forking-outside-a-group-is-extremely-s.yml
new file mode 100644
index 00000000000..dc4963a7446
--- /dev/null
+++ b/changelogs/unreleased/235912-fork-interface-with-prevent-forking-outside-a-group-is-extremely-s.yml
@@ -0,0 +1,5 @@
+---
+title: Fix slow group loading on forking page
+merge_request: 39640
+author:
+type: performance
diff --git a/changelogs/unreleased/remove-upcoming-db-deprecation-warning.yml b/changelogs/unreleased/remove-upcoming-db-deprecation-warning.yml
new file mode 100644
index 00000000000..c8615f26b1e
--- /dev/null
+++ b/changelogs/unreleased/remove-upcoming-db-deprecation-warning.yml
@@ -0,0 +1,5 @@
+---
+title: Display upcoming database deprecation warning only if current database version minimum is not met
+merge_request: 38225
+author:
+type: removed
diff --git a/config/routes/issues.rb b/config/routes/issues.rb
index eae1cacfcf7..cc4399693ed 100644
--- a/config/routes/issues.rb
+++ b/config/routes/issues.rb
@@ -22,4 +22,6 @@ resources :issues, concerns: :awardable, constraints: { id: /\d+/ } do
post :import_csv
post :export_csv
end
+
+ resources :issue_links, only: [:index, :create, :destroy], as: 'links', path: 'links'
end
diff --git a/doc/administration/auth/cognito.md b/doc/administration/auth/cognito.md
index b4df6446835..e777acd0d32 100644
--- a/doc/administration/auth/cognito.md
+++ b/doc/administration/auth/cognito.md
@@ -37,7 +37,7 @@ The following steps enable AWS Cognito as an authentication provider:
1. Save changes for the app client settings.
1. Under **Domain name** include the AWS domain name for your AWS Cognito application.
-1. Under **App Clients**, find your **App client id** and **App client secret**. These values correspond to the OAuth2 Client ID and Client Secret. Save these values.
+1. Under **App Clients**, find your app client ID and app client secret. These values correspond to the OAuth2 Client ID and Client Secret. Save these values.
## Configure GitLab
diff --git a/doc/administration/gitaly/index.md b/doc/administration/gitaly/index.md
index 9558488c89e..70e3f0c38c7 100644
--- a/doc/administration/gitaly/index.md
+++ b/doc/administration/gitaly/index.md
@@ -1072,6 +1072,24 @@ You can run a gRPC trace with:
sudo GRPC_TRACE=all GRPC_VERBOSITY=DEBUG gitlab-rake gitlab:gitaly:check
```
+### Correlating Git processes with RPCs
+
+Sometimes you need to find out which Gitaly RPC created a particular Git process.
+
+One method for doing this is via `DEBUG` logging. However, this needs to be enabled
+ahead of time and the logs produced are quite verbose.
+
+A lightweight method for doing this correlation is by inspecting the environment
+of the Git process (using its `PID`) and looking at the `CORRELATION_ID` variable:
+
+```shell
+PID=<Git process ID>
+sudo cat /proc/$PID/environ | tr '\0' '\n' | grep ^CORRELATION_ID=
+```
+
+Please note that this method is not reliable for `git cat-file` processes because Gitaly
+internally pools and re-uses those across RPCs.
+
### Observing `gitaly-ruby` traffic
[`gitaly-ruby`](#gitaly-ruby) is an internal implementation detail of Gitaly,
diff --git a/doc/administration/troubleshooting/tracing_correlation_id.md b/doc/administration/troubleshooting/tracing_correlation_id.md
index 31f537beae5..f716e74f36a 100644
--- a/doc/administration/troubleshooting/tracing_correlation_id.md
+++ b/doc/administration/troubleshooting/tracing_correlation_id.md
@@ -38,7 +38,7 @@ value that was randomly generated by GitLab for the request.
See the following example:
-![Firefox's network monitor showing an request id header](img/network_monitor_xid.png)
+![Firefox's network monitor showing an request ID header](img/network_monitor_xid.png)
### Getting the correlation ID from your logs
diff --git a/doc/api/feature_flags.md b/doc/api/feature_flags.md
index 479f82914a9..1088154b599 100644
--- a/doc/api/feature_flags.md
+++ b/doc/api/feature_flags.md
@@ -212,11 +212,11 @@ PUT /projects/:id/feature_flags/:feature_flag_name
| `active` | boolean | no | The active state of the flag. [Supported](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/38350) in GitLab 13.3 and later. |
| `name` | string | no | The new name of the feature flag. [Supported](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/38350) in GitLab 13.3 and later. |
| `strategies` | JSON | no | The feature flag [strategies](../operations/feature_flags.md#feature-flag-strategies). |
-| `strategies:id` | JSON | no | The feature flag strategy id. |
+| `strategies:id` | JSON | no | The feature flag strategy ID. |
| `strategies:name` | JSON | no | The strategy name. |
| `strategies:parameters` | JSON | no | The strategy parameters. |
| `strategies:scopes` | JSON | no | The scopes for the strategy. |
-| `strategies:scopes:id` | JSON | no | The scopes id. |
+| `strategies:scopes:id` | JSON | no | The scopes ID. |
| `strategies:scopes:environment_scope` | string | no | The environment spec for the scope. |
```shell
diff --git a/doc/api/graphql/getting_started.md b/doc/api/graphql/getting_started.md
index 12665f68f25..c2220403461 100644
--- a/doc/api/graphql/getting_started.md
+++ b/doc/api/graphql/getting_started.md
@@ -192,7 +192,7 @@ When you see the result `id` of the note you created - take a note of it. Now le
```graphql
mutation {
- updateNote(input: { id: "gid://gitlab/Note/<note id>",
+ updateNote(input: { id: "gid://gitlab/Note/<note ID>",
body: "*SIPS TEA*"
}) {
note {
@@ -210,7 +210,7 @@ Let's delete the comment, since our tea is all gone.
```graphql
mutation {
- destroyNote(input: { id: "gid://gitlab/Note/<note id>" }) {
+ destroyNote(input: { id: "gid://gitlab/Note/<note ID>" }) {
note {
id
body
diff --git a/doc/api/graphql/reference/gitlab_schema.graphql b/doc/api/graphql/reference/gitlab_schema.graphql
index 1d920894eec..f1bc1f49353 100644
--- a/doc/api/graphql/reference/gitlab_schema.graphql
+++ b/doc/api/graphql/reference/gitlab_schema.graphql
@@ -3131,7 +3131,7 @@ input DeleteAnnotationInput {
clientMutationId: String
"""
- The global id of the annotation to delete
+ The global ID of the annotation to delete
"""
id: ID!
}
@@ -8176,7 +8176,7 @@ type JiraUser {
gitlabUsername: String
"""
- Account id of the Jira user
+ Account ID of the Jira user
"""
jiraAccountId: String!
diff --git a/doc/api/graphql/reference/gitlab_schema.json b/doc/api/graphql/reference/gitlab_schema.json
index 7ee37fb4d43..91b7eef7816 100644
--- a/doc/api/graphql/reference/gitlab_schema.json
+++ b/doc/api/graphql/reference/gitlab_schema.json
@@ -8464,7 +8464,7 @@
"inputFields": [
{
"name": "id",
- "description": "The global id of the annotation to delete",
+ "description": "The global ID of the annotation to delete",
"type": {
"kind": "NON_NULL",
"name": null,
@@ -22659,7 +22659,7 @@
},
{
"name": "jiraAccountId",
- "description": "Account id of the Jira user",
+ "description": "Account ID of the Jira user",
"args": [
],
diff --git a/doc/api/graphql/reference/index.md b/doc/api/graphql/reference/index.md
index 8ba1862b009..c33ee00a959 100644
--- a/doc/api/graphql/reference/index.md
+++ b/doc/api/graphql/reference/index.md
@@ -1254,7 +1254,7 @@ Autogenerated return type of JiraImportUsers
| `gitlabId` | Int | ID of the matched GitLab user |
| `gitlabName` | String | Name of the matched GitLab user |
| `gitlabUsername` | String | Username of the matched GitLab user |
-| `jiraAccountId` | String! | Account id of the Jira user |
+| `jiraAccountId` | String! | Account ID of the Jira user |
| `jiraDisplayName` | String! | Display name of the Jira user |
| `jiraEmail` | String | Email of the Jira user, returned only for users with public emails |
diff --git a/doc/api/services.md b/doc/api/services.md
index 25ad025027a..405047a433d 100644
--- a/doc/api/services.md
+++ b/doc/api/services.md
@@ -807,7 +807,7 @@ Parameters:
| `username` | string | yes | The username of the user created to be used with GitLab/Jira. |
| `password` | string | yes | The password of the user created to be used with GitLab/Jira. |
| `active` | boolean | no | Activates or deactivates the service. Defaults to false (deactivated). |
-| `jira_issue_transition_id` | string | no | The ID of a transition that moves issues to a closed state. You can find this number under the Jira workflow administration (**Administration > Issues > Workflows**) by selecting **View** under **Operations** of the desired workflow of your project. The ID of each state can be found inside the parenthesis of each transition name under the **Transitions (id)** column. By default, this ID is set to `2`. |
+| `jira_issue_transition_id` | string | no | The ID of a transition that moves issues to a closed state. You can find this number under the Jira workflow administration (**Administration > Issues > Workflows**) by selecting **View** under **Operations** of the desired workflow of your project. The ID of each state can be found inside the parenthesis of each transition name under the transitions ID column. By default, this ID is set to `2`. |
| `commit_events` | boolean | false | Enable notifications for commit events |
| `merge_requests_events` | boolean | false | Enable notifications for merge request events |
| `comment_on_event_enabled` | boolean | false | Enable comments inside Jira issues on each GitLab event (commit / merge request) |
diff --git a/doc/ci/directed_acyclic_graph/index.md b/doc/ci/directed_acyclic_graph/index.md
index 8fc58df51fe..ed1528bf6ca 100644
--- a/doc/ci/directed_acyclic_graph/index.md
+++ b/doc/ci/directed_acyclic_graph/index.md
@@ -106,5 +106,5 @@ can opt to disable it for your instance:
# Instance-wide
Feature.disable(:dag_pipeline_tab)
# or by project
-Feature.disable(:dag_pipeline_tab, Project.find(<project id>))
+Feature.disable(:dag_pipeline_tab, Project.find(<project ID>))
```
diff --git a/doc/ci/multi_project_pipelines.md b/doc/ci/multi_project_pipelines.md
index 3df2db8539e..1dee933c126 100644
--- a/doc/ci/multi_project_pipelines.md
+++ b/doc/ci/multi_project_pipelines.md
@@ -272,7 +272,8 @@ You can trigger a pipeline in your project whenever a pipeline finishes for a ne
tag in a different project:
1. Go to the project's **Settings > CI / CD** page, and expand the **Pipeline subscriptions** section.
-1. Enter the path to the project you want to subscribe to.
+1. Enter the project you want to subscribe to, in the format `<namespace>/<project>`.
+ For example, if the project is `https://gitlab.com/gitlab-org/gitlab`, use `gitlab-org/gitlab`.
1. Click subscribe.
Any pipelines that complete successfully for new tags in the subscribed project
diff --git a/doc/development/documentation/feature_flags.md b/doc/development/documentation/feature_flags.md
index e2fbf25eb8a..8ad7ef64587 100644
--- a/doc/development/documentation/feature_flags.md
+++ b/doc/development/documentation/feature_flags.md
@@ -75,7 +75,7 @@ To enable it:
# Instance-wide
Feature.enable(:<feature flag>)
# or by project
-Feature.enable(:<feature flag>, Project.find(<project id>))
+Feature.enable(:<feature flag>, Project.find(<project ID>))
```
To disable it:
@@ -84,7 +84,7 @@ To disable it:
# Instance-wide
Feature.disable(:<feature flag>)
# or by project
-Feature.disable(:<feature flag>, Project.find(<project id>))
+Feature.disable(:<feature flag>, Project.find(<project ID>))
```
````
diff --git a/doc/development/elasticsearch.md b/doc/development/elasticsearch.md
index 2f01692e944..614b2579ec3 100644
--- a/doc/development/elasticsearch.md
+++ b/doc/development/elasticsearch.md
@@ -229,7 +229,7 @@ be used both locally in development and on any deployed GitLab instance to
diagnose poor search performance. This will show the exact queries being made,
which is useful to diagnose why a search might be slow.
-### Correlation ID and X-Opaque-Id
+### Correlation ID and `X-Opaque-Id`
Our [correlation
ID](./distributed_tracing.md#developer-guidelines-for-working-with-correlation-ids)
diff --git a/doc/development/geo/framework.md b/doc/development/geo/framework.md
index 64c9030e3dd..fc8a1c56d67 100644
--- a/doc/development/geo/framework.md
+++ b/doc/development/geo/framework.md
@@ -128,7 +128,7 @@ When this is set in place, it's easy to access the replicator through
the model:
```ruby
-package_file = Packages::PackageFile.find(4) # just a random id as example
+package_file = Packages::PackageFile.find(4) # just a random ID as example
replicator = package_file.replicator
```
diff --git a/doc/development/telemetry/snowplow.md b/doc/development/telemetry/snowplow.md
index 547ba36464b..f01c2ec95c3 100644
--- a/doc/development/telemetry/snowplow.md
+++ b/doc/development/telemetry/snowplow.md
@@ -393,7 +393,7 @@ Snowplow Micro is a Docker-based solution for testing frontend and backend event
1. Send a test Snowplow event from the Rails console:
```ruby
- Gitlab::Tracking.self_describing_event('iglu:com.gitlab/pageview_context/jsonschema/1-0-0', { page_type: ‘MY_TYPE' }, context: nil )
+ Gitlab::Tracking.self_describing_event('iglu:com.gitlab/pageview_context/jsonschema/1-0-0', { page_type: 'MY_TYPE' }, context: nil )
```
### Snowplow Mini
diff --git a/doc/development/telemetry/usage_ping.md b/doc/development/telemetry/usage_ping.md
index be599898214..383fb4a126b 100644
--- a/doc/development/telemetry/usage_ping.md
+++ b/doc/development/telemetry/usage_ping.md
@@ -222,38 +222,77 @@ Examples of implementation:
#### Redis HLL Counters
-With `Gitlab::Redis::HLL` we have available data structures used to count unique values.
+With `Gitlab::UsageDataCounters::HLLRedisCounter` we have available data structures used to count unique values.
Implemented using Redis methods [PFADD](https://redis.io/commands/pfadd) and [PFCOUNT](https://redis.io/commands/pfcount).
-Recommendations:
+##### Adding new events
-- Key should expire in 29 days.
-- If possible, data granularity should be a week. For example a key could be composed from the metric's name and week of the year, `2020-33-{metric_name}`.
-- Use a [feature flag](../../operations/feature_flags.md) in order to have a control over the impact when adding new metrics.
-- If possible, data granularity should be week, for example a key could be composed from metric name and week of the year, 2020-33-{metric_name}
-- Use a [feature flag](../../operations/feature_flags.md) in order to have a control over the impact when adding new metrics
+1. Define events in [`known_events.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/usage_data_counters/known_events.yml).
-Examples of implementation:
+ Example event:
-- [`Gitlab::UsageDataCounters::TrackUniqueEvents`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/usage_data_counters/track_unique_actions.rb)
-- [`Gitlab::Analytics::UniqueVisits`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/analytics/unique_visits.rb)
+ ```yaml
+ - name: i_compliance_credential_inventory
+ category: compliance
+ redis_slot: compliance
+ expiry: 42 # 6 weeks
+ aggregation: weekly
+ ```
-Example of usage:
+ Keys:
+
+ - `name`: unique event name.
+ - `category`: event category. Used for getting total counts for events in a category, for easier
+ access to a group of events.
+ - `redis_slot`: optional Redis slot; default value: event name. Used if needed to calculate totals
+ for a group of metrics. Ensure keys are in the same slot. For example:
+ `i_compliance_credential_inventory` with `redis_slot: 'compliance'` will build Redis key
+ `i_{compliance}_credential_inventory-2020-34`. If `redis_slot` is not defined the Redis key will
+ be `{i_compliance_credential_inventory}-2020-34`.
+ - `expiry`: expiry time in days. Default: 29 days for daily aggregation and 6 weeks for weekly
+ aggregation.
+ - `aggregation`: aggregation `:daily` or `:weekly`. The argument defines how we build the Redis
+ keys for data storage. For `daily` we keep a key for metric per day of the year, for `weekly` we
+ keep a key for metric per week of the year.
+
+1. Track event using `Gitlab::UsageDataCounters::HLLRedisCounter.track_event(entity_id, event_name)`.
+
+ Arguments:
+
+ - `entity_id`: value we count. For example: user_id, visitor_id.
+ - `event_name`: event name.
+
+1. Get event data using `Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names:, start_date:, end_date)`.
+
+ Arguments:
+
+ - `event_names`: the list of event names.
+ - `start_date`: start date of the period for which we want to get event data.
+ - `end_date`: end date of the period for which we want to get event data.
+
+Recommendations:
+
+- Key should expire in 29 days for daily and 42 days for weekly.
+- If possible, data granularity should be a week. For example a key could be composed from the
+ metric's name and week of the year, `2020-33-{metric_name}`.
+- Use a [feature flag](../../operations/feature_flags.md) to have a control over the impact when
+ adding new metrics.
+
+Example usage:
```ruby
# Redis Counters
redis_usage_data(Gitlab::UsageDataCounters::WikiPageCounter)
redis_usage_data { ::Gitlab::UsageCounters::PodLogs.usage_totals[:total] }
-# Redis HLL counter
-counter = Gitlab::UsageDataCounters::TrackUniqueEvents
-redis_usage_data do
- counter.count_unique_events(
- event_action: Gitlab::UsageDataCounters::TrackUniqueEvents::PUSH_ACTION,
- date_from: time_period[:created_at].first,
- date_to: time_period[:created_at].last
- )
+# Define events in known_events.yml https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/usage_data_counters/known_events.yml
+
+# Tracking events
+Gitlab::UsageDataCounters::HLLRedisCounter.track_event(visitor_id, 'expand_vulnerabilities')
+
+# Get unique events for metric
+redis_usage_data { Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: 'expand_vulnerabilities', start_date: 28.days.ago, end_date: Date.current) }
```
### Alternative Counters
diff --git a/doc/integration/salesforce.md b/doc/integration/salesforce.md
index 64eac2f9e66..7e0b2518e76 100644
--- a/doc/integration/salesforce.md
+++ b/doc/integration/salesforce.md
@@ -21,7 +21,7 @@ To get the credentials (a pair of Client ID and Client Secret), you must [create
1. Select **API (Enable OAuth Settings)** and click on **Enable OAuth Settings**.
1. Fill in the application details into the following fields:
- **Callback URL**: The callback URL of your GitLab installation. For example, `https://gitlab.example.com/users/auth/salesforce/callback`.
- - **Selected OAuth Scopes**: Move **Access your basic information (id, profile, email, address, phone)** and **Allow access to your unique identifier (OpenID)** to the right column.
+ - **Selected OAuth Scopes**: Move `Access your basic information (id, profile, email, address, phone)` and `Allow access to your unique identifier (openid)` to the right column.
![Salesforce OAuth App Details](img/salesforce_oauth_app_details.png)
diff --git a/doc/operations/feature_flags.md b/doc/operations/feature_flags.md
index 46a57e72484..8c79079f595 100644
--- a/doc/operations/feature_flags.md
+++ b/doc/operations/feature_flags.md
@@ -332,8 +332,8 @@ unleash = Unleash::Client.new({
})
unleash_context = Unleash::Context.new
-# Replace "123" with the id of an authenticated user.
-# Note that the context's user id must be a string:
+# Replace "123" with the ID of an authenticated user.
+# Note that the context's user ID must be a string:
# https://unleash.github.io/docs/unleash_context
unleash_context.user_id = "123"
diff --git a/doc/operations/incident_management/alerts.md b/doc/operations/incident_management/alerts.md
index 5a5fc59d5e3..04077905af2 100644
--- a/doc/operations/incident_management/alerts.md
+++ b/doc/operations/incident_management/alerts.md
@@ -14,7 +14,7 @@ but you can change the sort order by clicking the headers in the Alert Managemen
The alert list displays the following information:
-![Alert List](../../user/project/operations/img/alert_list_v13_1.png)
+![Alert List](img/alert_list_v13_1.png)
- **Search** - The alert list supports a simple free text search on the title,
description, monitoring tool, and service fields.
@@ -67,11 +67,11 @@ To populate the alerts with data, read
GitLab provides the Generic Alerts endpoint so you can accept alerts from a third-party
alerts service. Read the
-[instructions for toggling generic alerts](../../user/project/integrations/generic_alerts.md#setting-up-generic-alerts)
+[instructions for toggling generic alerts](generic_alerts.md#setting-up-generic-alerts)
to add this option. After configuring the endpoint, the
[Alerts list](alerts.md) is enabled.
-To populate the alerts with data, read [Customizing the payload](../../user/project/integrations/generic_alerts.md#customizing-the-payload) for requests to the alerts endpoint.
+To populate the alerts with data, read [Customizing the payload](generic_alerts.md#customizing-the-payload) for requests to the alerts endpoint.
### Opsgenie integration **(PREMIUM)**
@@ -82,7 +82,7 @@ A new way of monitoring Alerts via a GitLab integration is with
NOTE: **Note:**
If you enable the Opsgenie integration, you can't have other GitLab alert services,
-such as [Generic Alerts](../../user/project/integrations/generic_alerts.md) or
+such as [Generic Alerts](generic_alerts.md) or
Prometheus alerts, active at the same time.
To enable Opsgenie integration:
diff --git a/doc/operations/incident_management/generic_alerts.md b/doc/operations/incident_management/generic_alerts.md
new file mode 100644
index 00000000000..56a2715ab04
--- /dev/null
+++ b/doc/operations/incident_management/generic_alerts.md
@@ -0,0 +1,125 @@
+---
+stage: Monitor
+group: Health
+info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#designated-technical-writers
+---
+
+# Generic alerts integration
+
+> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/13203) in [GitLab Ultimate](https://about.gitlab.com/pricing/) 12.4.
+> - [Moved](https://gitlab.com/gitlab-org/gitlab/-/issues/42640) to [GitLab Core](https://about.gitlab.com/pricing/) in 12.8.
+
+GitLab can accept alerts from any source via a generic webhook receiver.
+When you set up the generic alerts integration, a unique endpoint will
+be created which can receive a payload in JSON format, and will in turn
+create an issue with the payload in the body of the issue. You can always
+[customize the payload](#customizing-the-payload) to your liking.
+
+The entire payload will be posted in the issue discussion as a comment
+authored by the GitLab Alert Bot.
+
+NOTE: **Note:**
+In GitLab versions 13.1 and greater, you can configure
+[External Prometheus instances](../metrics/alerts.md#external-prometheus-instances)
+to use this endpoint.
+
+## Setting up generic alerts
+
+To obtain credentials for setting up a generic alerts integration:
+
+- Sign in to GitLab as a user with maintainer [permissions](../../user/permissions.md) for a project.
+- Navigate to the **Operations** page for your project, depending on your installed version of GitLab:
+ - *In GitLab versions 13.1 and greater,* navigate to **Settings > Operations** in your project.
+ - *In GitLab versions prior to 13.1,* navigate to **Settings > Integrations** in your project. GitLab will display a banner encouraging you to enable the Alerts endpoint in **Settings > Operations** instead.
+- Click **Alerts endpoint**.
+- Toggle the **Active** alert setting to display the **URL** and **Authorization Key** for the webhook configuration.
+
+## Customizing the payload
+
+You can customize the payload by sending the following parameters. All fields other than `title` are optional:
+
+| Property | Type | Description |
+| -------- | ---- | ----------- |
+| `title` | String | The title of the incident. Required. |
+| `description` | String | A high-level summary of the problem. |
+| `start_time` | DateTime | The time of the incident. If none is provided, a timestamp of the issue will be used. |
+| `service` | String | The affected service. |
+| `monitoring_tool` | String | The name of the associated monitoring tool. |
+| `hosts` | String or Array | One or more hosts, as to where this incident occurred. |
+| `severity` | String | The severity of the alert. Must be one of `critical`, `high`, `medium`, `low`, `info`, `unknown`. Default is `critical`. |
+| `fingerprint` | String or Array | The unique identifier of the alert. This can be used to group occurrences of the same alert. |
+| `gitlab_environment_name` | String | The name of the associated GitLab [environment](../../ci/environments/index.md). This can be used to associate your alert to your environment. |
+
+You can also add custom fields to the alert's payload. The values of extra parameters
+are not limited to primitive types, such as strings or numbers, but can be a nested
+JSON object. For example:
+
+```json
+{ "foo": { "bar": { "baz": 42 } } }
+```
+
+TIP: **Payload size:**
+Ensure your requests are smaller than the [payload application limits](../../administration/instance_limits.md#generic-alert-json-payloads).
+
+Example request:
+
+```shell
+curl --request POST \
+ --data '{"title": "Incident title"}' \
+ --header "Authorization: Bearer <authorization_key>" \
+ --header "Content-Type: application/json" \
+ <url>
+```
+
+The `<authorization_key>` and `<url>` values can be found when [setting up generic alerts](#setting-up-generic-alerts).
+
+Example payload:
+
+```json
+{
+ "title": "Incident title",
+ "description": "Short description of the incident",
+ "start_time": "2019-09-12T06:00:55Z",
+ "service": "service affected",
+ "monitoring_tool": "value",
+ "hosts": "value",
+ "severity": "high",
+ "fingerprint": "d19381d4e8ebca87b55cda6e8eee7385",
+ "foo": {
+ "bar": {
+ "baz": 42
+ }
+ }
+}
+```
+
+## Triggering test alerts
+
+> [Introduced](https://gitlab.com/groups/gitlab-org/-/epics/3066) in GitLab Core in 13.2.
+
+After a [project maintainer or owner](#setting-up-generic-alerts)
+[configures generic alerts](#setting-up-generic-alerts), you can trigger a
+test alert to confirm your integration works properly.
+
+1. Sign in as a user with Developer or greater [permissions](../../user/permissions.md).
+1. Navigate to **Settings > Operations** in your project.
+1. Click **Alerts endpoint** to expand the section.
+1. Enter a sample payload in **Alert test payload** (valid JSON is required).
+1. Click **Test alert payload**.
+
+GitLab displays an error or success message, depending on the outcome of your test.
+
+## Automatic grouping of identical alerts **(PREMIUM)**
+
+> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/214557) in [GitLab Premium](https://about.gitlab.com/pricing/) 13.2.
+
+In GitLab versions 13.2 and greater, GitLab groups alerts based on their payload.
+When an incoming alert contains the same payload as another alert (excluding the
+`start_time` and `hosts` attributes), GitLab groups these alerts together and
+displays a counter on the
+[Alert Management List](incidents.md)
+and details pages.
+
+If the existing alert is already `resolved`, then a new alert will be created instead.
+
+![Alert Management List](img/alert_list_v13_1.png)
diff --git a/doc/user/project/operations/img/alert_list_v13_1.png b/doc/operations/incident_management/img/alert_list_v13_1.png
index 7a1a5f5191e..7a1a5f5191e 100644
--- a/doc/user/project/operations/img/alert_list_v13_1.png
+++ b/doc/operations/incident_management/img/alert_list_v13_1.png
Binary files differ
diff --git a/doc/operations/incident_management/index.md b/doc/operations/incident_management/index.md
index 53a6b47ec4b..6c70d1d9927 100644
--- a/doc/operations/incident_management/index.md
+++ b/doc/operations/incident_management/index.md
@@ -50,7 +50,7 @@ user, but it does not count toward your license limit.
## Configure external generic alerts
GitLab can accept alerts from any source through a generic webhook receiver. When
-[configuring the generic alerts integration](../../user/project/integrations/generic_alerts.md),
+[configuring the generic alerts integration](generic_alerts.md),
GitLab creates a unique endpoint which receives a JSON-formatted, customizable payload.
## Integrate incidents with Slack
diff --git a/doc/operations/metrics/alerts.md b/doc/operations/metrics/alerts.md
index 2ed8de9396a..90cc70c8e53 100644
--- a/doc/operations/metrics/alerts.md
+++ b/doc/operations/metrics/alerts.md
@@ -78,7 +78,7 @@ Prometheus. The value of this should match the name of your environment in GitLa
NOTE: **Note:**
In GitLab versions 13.1 and greater, you can configure your manually configured
Prometheus server to use the
-[Generic alerts integration](../../user/project/integrations/generic_alerts.md).
+[Generic alerts integration](../incident_management/generic_alerts.md).
## Trigger actions from alerts **(ULTIMATE)**
diff --git a/doc/operations/product_analytics.md b/doc/operations/product_analytics.md
index 96f1a45167b..8f660a16b47 100644
--- a/doc/operations/product_analytics.md
+++ b/doc/operations/product_analytics.md
@@ -33,7 +33,7 @@ To enable it:
# Instance-wide
Feature.enable(:product_analytics)
# or by project
-Feature.enable(:product_analytics, Project.find(<project id>))
+Feature.enable(:product_analytics, Project.find(<project ID>))
```
To disable it:
@@ -42,7 +42,7 @@ To disable it:
# Instance-wide
Feature.disable(:product_analytics)
# or by project
-Feature.disable(:product_analytics, Project.find(<project id>))
+Feature.disable(:product_analytics, Project.find(<project ID>))
```
## Access Product Analytics
diff --git a/doc/user/application_security/dast/index.md b/doc/user/application_security/dast/index.md
index b2020d48d38..3d5180854b5 100644
--- a/doc/user/application_security/dast/index.md
+++ b/doc/user/application_security/dast/index.md
@@ -678,7 +678,7 @@ To enable On-demand Scans:
# Instance-wide
Feature.enable(:security_on_demand_scans_feature_flag)
# or by project
-Feature.enable(:security_on_demand_scans_feature_flag, Project.find(<project id>))
+Feature.enable(:security_on_demand_scans_feature_flag, Project.find(<project ID>))
```
#### Enable or disable site profiles
@@ -703,7 +703,7 @@ To enable Site Profiles:
# Instance-wide
Feature.enable(:security_on_demand_scans_site_profiles_feature_flag)
# or by project
-Feature.enable(:security_on_demand_scans_site_profiles_feature_flag, Project.find(<project id>))
+Feature.enable(:security_on_demand_scans_site_profiles_feature_flag, Project.find(<project ID>))
```
## Reports
diff --git a/doc/user/group/iterations/index.md b/doc/user/group/iterations/index.md
index f04472a29bb..43041456060 100644
--- a/doc/user/group/iterations/index.md
+++ b/doc/user/group/iterations/index.md
@@ -76,7 +76,7 @@ To enable it:
# Instance-wide
Feature.enable(:group_iterations)
# or by group
-Feature.enable(:group_iterations, Group.find(<group id>))
+Feature.enable(:group_iterations, Group.find(<group ID>))
```
To disable it:
@@ -85,7 +85,7 @@ To disable it:
# Instance-wide
Feature.disable(:group_iterations)
# or by group
-Feature.disable(:group_iterations, Group.find(<group id>))
+Feature.disable(:group_iterations, Group.find(<group ID>))
```
<!-- ## Troubleshooting
diff --git a/doc/user/group/saml_sso/group_managed_accounts.md b/doc/user/group/saml_sso/group_managed_accounts.md
index 126970ebbb6..2cf27e7c103 100644
--- a/doc/user/group/saml_sso/group_managed_accounts.md
+++ b/doc/user/group/saml_sso/group_managed_accounts.md
@@ -76,7 +76,8 @@ This restriction also applies to projects forked from or to those groups.
Groups with group-managed accounts can disallow forking of projects to destinations outside the group.
To do so, enable the "Prohibit outer forks" option in **Settings > SAML SSO**.
-When enabled, projects within the group can only be forked to other destinations within the group (including its subgroups).
+When enabled **at the parent group level**, projects within the group can be forked
+only to other destinations within the group (including its subgroups).
## Credentials inventory for Group-managed accounts **(ULTIMATE)**
diff --git a/doc/user/project/integrations/generic_alerts.md b/doc/user/project/integrations/generic_alerts.md
index 42f33e8d670..0e8e082859b 100644
--- a/doc/user/project/integrations/generic_alerts.md
+++ b/doc/user/project/integrations/generic_alerts.md
@@ -1,125 +1,5 @@
---
-stage: Monitor
-group: Health
-info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#designated-technical-writers
+redirect_to: '../../../operations/incident_management/generic_alerts.md'
---
-# Generic alerts integration
-
-> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/13203) in [GitLab Ultimate](https://about.gitlab.com/pricing/) 12.4.
-> - [Moved](https://gitlab.com/gitlab-org/gitlab/-/issues/42640) to [GitLab Core](https://about.gitlab.com/pricing/) in 12.8.
-
-GitLab can accept alerts from any source via a generic webhook receiver.
-When you set up the generic alerts integration, a unique endpoint will
-be created which can receive a payload in JSON format, and will in turn
-create an issue with the payload in the body of the issue. You can always
-[customize the payload](#customizing-the-payload) to your liking.
-
-The entire payload will be posted in the issue discussion as a comment
-authored by the GitLab Alert Bot.
-
-NOTE: **Note:**
-In GitLab versions 13.1 and greater, you can configure
-[External Prometheus instances](../../../operations/metrics/alerts.md#external-prometheus-instances)
-to use this endpoint.
-
-## Setting up generic alerts
-
-To obtain credentials for setting up a generic alerts integration:
-
-- Sign in to GitLab as a user with maintainer [permissions](../../permissions.md) for a project.
-- Navigate to the **Operations** page for your project, depending on your installed version of GitLab:
- - *In GitLab versions 13.1 and greater,* navigate to **Settings > Operations** in your project.
- - *In GitLab versions prior to 13.1,* navigate to **Settings > Integrations** in your project. GitLab will display a banner encouraging you to enable the Alerts endpoint in **Settings > Operations** instead.
-- Click **Alerts endpoint**.
-- Toggle the **Active** alert setting to display the **URL** and **Authorization Key** for the webhook configuration.
-
-## Customizing the payload
-
-You can customize the payload by sending the following parameters. All fields other than `title` are optional:
-
-| Property | Type | Description |
-| -------- | ---- | ----------- |
-| `title` | String | The title of the incident. Required. |
-| `description` | String | A high-level summary of the problem. |
-| `start_time` | DateTime | The time of the incident. If none is provided, a timestamp of the issue will be used. |
-| `service` | String | The affected service. |
-| `monitoring_tool` | String | The name of the associated monitoring tool. |
-| `hosts` | String or Array | One or more hosts, as to where this incident occurred. |
-| `severity` | String | The severity of the alert. Must be one of `critical`, `high`, `medium`, `low`, `info`, `unknown`. Default is `critical`. |
-| `fingerprint` | String or Array | The unique identifier of the alert. This can be used to group occurrences of the same alert. |
-| `gitlab_environment_name` | String | The name of the associated GitLab [environment](../../../ci/environments/index.md). This can be used to associate your alert to your environment. |
-
-You can also add custom fields to the alert's payload. The values of extra parameters
-are not limited to primitive types, such as strings or numbers, but can be a nested
-JSON object. For example:
-
-```json
-{ "foo": { "bar": { "baz": 42 } } }
-```
-
-TIP: **Payload size:**
-Ensure your requests are smaller than the [payload application limits](../../../administration/instance_limits.md#generic-alert-json-payloads).
-
-Example request:
-
-```shell
-curl --request POST \
- --data '{"title": "Incident title"}' \
- --header "Authorization: Bearer <authorization_key>" \
- --header "Content-Type: application/json" \
- <url>
-```
-
-The `<authorization_key>` and `<url>` values can be found when [setting up generic alerts](#setting-up-generic-alerts).
-
-Example payload:
-
-```json
-{
- "title": "Incident title",
- "description": "Short description of the incident",
- "start_time": "2019-09-12T06:00:55Z",
- "service": "service affected",
- "monitoring_tool": "value",
- "hosts": "value",
- "severity": "high",
- "fingerprint": "d19381d4e8ebca87b55cda6e8eee7385",
- "foo": {
- "bar": {
- "baz": 42
- }
- }
-}
-```
-
-## Triggering test alerts
-
-> [Introduced](https://gitlab.com/groups/gitlab-org/-/epics/3066) in GitLab Core in 13.2.
-
-After a [project maintainer or owner](#setting-up-generic-alerts)
-[configures generic alerts](#setting-up-generic-alerts), you can trigger a
-test alert to confirm your integration works properly.
-
-1. Sign in as a user with Developer or greater [permissions](../../../user/permissions.md).
-1. Navigate to **Settings > Operations** in your project.
-1. Click **Alerts endpoint** to expand the section.
-1. Enter a sample payload in **Alert test payload** (valid JSON is required).
-1. Click **Test alert payload**.
-
-GitLab displays an error or success message, depending on the outcome of your test.
-
-## Automatic grouping of identical alerts **(PREMIUM)**
-
-> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/214557) in [GitLab Premium](https://about.gitlab.com/pricing/) 13.2.
-
-In GitLab versions 13.2 and greater, GitLab groups alerts based on their payload.
-When an incoming alert contains the same payload as another alert (excluding the
-`start_time` and `hosts` attributes), GitLab groups these alerts together and
-displays a counter on the
-[Alert Management List](../../../operations/incident_management/incidents.md)
-and details pages.
-
-If the existing alert is already `resolved`, then a new alert will be created instead.
-
-![Alert Management List](../operations/img/alert_list_v13_1.png)
+This document was moved to [another location](../../../operations/incident_management/generic_alerts.md).
diff --git a/doc/user/project/integrations/overview.md b/doc/user/project/integrations/overview.md
index f179cd6b98e..ffa1167d5a4 100644
--- a/doc/user/project/integrations/overview.md
+++ b/doc/user/project/integrations/overview.md
@@ -39,7 +39,7 @@ Click on the service links to see further configuration instructions and details
| [Emails on push](emails_on_push.md) | Email the commits and diff of each push to a list of recipients | No |
| External Wiki | Replaces the link to the internal wiki with a link to an external wiki | No |
| Flowdock | Flowdock is a collaboration web app for technical teams | No |
-| [Generic alerts](generic_alerts.md) **(ULTIMATE)** | Receive alerts on GitLab from any source | No |
+| [Generic alerts](../../../operations/incident_management/generic_alerts.md) **(ULTIMATE)** | Receive alerts on GitLab from any source | No |
| [GitHub](github.md) **(PREMIUM)** | Sends pipeline notifications to GitHub | No |
| [Hangouts Chat](hangouts_chat.md) | Receive events notifications in Google Hangouts Chat | No |
| [HipChat](hipchat.md) | Private group chat and IM | No |
diff --git a/doc/user/project/integrations/servicenow.md b/doc/user/project/integrations/servicenow.md
new file mode 100644
index 00000000000..d549921b9d9
--- /dev/null
+++ b/doc/user/project/integrations/servicenow.md
@@ -0,0 +1,41 @@
+---
+stage: Create
+group: Ecosystem
+info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#designated-technical-writers
+---
+
+# ServiceNow integration
+
+ServiceNow offers several integrations to help centralize and automate your
+management of GitLab workflows.
+
+## GitLab spoke
+
+With the GitLab spoke in ServiceNow, you can automate actions for GitLab
+projects, groups, users, issues, merge requests, branches, and repositories.
+
+For a full list of features, see the
+[GitLab spoke documentation](https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/administer/integrationhub-store-spokes/concept/gitlab-spoke.html).
+
+You must [configure GitLab as an OAuth2 authentication service provider](../../../integration/oauth_provider.md),
+which involves creating an application and then providing the Application ID
+and Secret in ServiceNow.
+
+## GitLab SCM and Continuous Integration for DevOps
+
+In ServiceNow DevOps, you can integrate with GitLab repositories and GitLab CI/CD
+to centralize your view of GitLab activity and your change management processes.
+You can:
+
+- Track information about activity in GitLab repositories and CI/CD pipelines in
+ ServiceNow.
+- Integrate with GitLab CI/CD pipelines, by automating the creation of change
+ tickets and determining criteria for changes to auto-approve.
+
+For more information, refer to the following ServiceNow resources:
+
+- [ServiceNow DevOps home page](https://www.servicenow.com/products/devops.html)
+- [Install DevOps](https://docs.servicenow.com/bundle/paris-devops/page/product/enterprise-dev-ops/task/activate-dev-ops.html)
+- [Install DevOps Integrations](https://docs.servicenow.com/bundle/paris-devops/page/product/enterprise-dev-ops/task/activate-dev-ops-integrations.html)
+- [GitLab SCM and Continuous Integration for DevOps](https://store.servicenow.com/sn_appstore_store.do#!/store/application/54dc4eacdbc2dcd02805320b7c96191e/)
+- [Model a GitLab CI pipeline in DevOps](https://docs.servicenow.com/bundle/paris-devops/page/product/enterprise-dev-ops/task/model-gitlab-pipeline-dev-ops.html).
diff --git a/doc/user/project/merge_requests/squash_and_merge.md b/doc/user/project/merge_requests/squash_and_merge.md
index 7f752b2cc39..bea3faf9af5 100644
--- a/doc/user/project/merge_requests/squash_and_merge.md
+++ b/doc/user/project/merge_requests/squash_and_merge.md
@@ -133,7 +133,7 @@ To enable it:
# Instance-wide
Feature.enable(:squash_options)
# or by project
-Feature.enable(:squash_options, Project.find(<project id>))
+Feature.enable(:squash_options, Project.find(<project ID>))
```
To disable it:
@@ -142,7 +142,7 @@ To disable it:
# Instance-wide
Feature.disable(:squash_options)
# or by project
-Feature.disable(:squash_options, Project.find(<project id>))
+Feature.disable(:squash_options, Project.find(<project ID>))
```
<!-- ## Troubleshooting
diff --git a/lib/gitlab/config_checker/external_database_checker.rb b/lib/gitlab/config_checker/external_database_checker.rb
index dfcdbdf39e0..606d45e0f0f 100644
--- a/lib/gitlab/config_checker/external_database_checker.rb
+++ b/lib/gitlab/config_checker/external_database_checker.rb
@@ -6,48 +6,21 @@ module Gitlab
extend self
def check
- notices = []
-
- unless Gitlab::Database.postgresql_minimum_supported_version?
- string_args = {
- pg_version_current: Gitlab::Database.version,
- pg_version_minimum: Gitlab::Database::MINIMUM_POSTGRES_VERSION,
- pg_requirements_url_open: '<a href="https://docs.gitlab.com/ee/install/requirements.html#database">'.html_safe,
- pg_requirements_url_close: '</a>'.html_safe
+ return [] if Gitlab::Database.postgresql_minimum_supported_version?
+
+ [
+ {
+ type: 'warning',
+ message: _('You are using PostgreSQL %{pg_version_current}, but PostgreSQL ' \
+ '%{pg_version_minimum} is required for this version of GitLab. ' \
+ 'Please upgrade your environment to a supported PostgreSQL version, ' \
+ 'see %{pg_requirements_url} for details.') % {
+ pg_version_current: Gitlab::Database.version,
+ pg_version_minimum: Gitlab::Database::MINIMUM_POSTGRES_VERSION,
+ pg_requirements_url: '<a href="https://docs.gitlab.com/ee/install/requirements.html#database">database requirements</a>'
+ }
}
-
- notices <<
- {
- type: 'warning',
- message: html_escape(_('You are using PostgreSQL %{pg_version_current}, but PostgreSQL ' \
- '%{pg_version_minimum} is required for this version of GitLab. ' \
- 'Please upgrade your environment to a supported PostgreSQL version, ' \
- 'see %{pg_requirements_url_open}database requirements%{pg_requirements_url_close} for details.')) % string_args
- }
- end
-
- if Gitlab::Database.postgresql_upcoming_deprecation? && Gitlab::Database.within_deprecation_notice_window?
- upcoming_deprecation = Gitlab::Database::UPCOMING_POSTGRES_VERSION_DETAILS
-
- string_args = {
- pg_version_upcoming: upcoming_deprecation[:pg_version_minimum],
- gl_version_upcoming: upcoming_deprecation[:gl_version],
- gl_version_upcoming_date: upcoming_deprecation[:gl_version_date],
- pg_version_upcoming_url_open: "<a href=\"#{upcoming_deprecation[:url]}\">".html_safe,
- pg_version_upcoming_url_close: '</a>'.html_safe
- }
-
- notices <<
- {
- type: 'warning',
- message: html_escape(_('Note that PostgreSQL %{pg_version_upcoming} will become the minimum required ' \
- 'version in GitLab %{gl_version_upcoming} (%{gl_version_upcoming_date}). Please ' \
- 'consider upgrading your environment to a supported PostgreSQL version soon, ' \
- 'see %{pg_version_upcoming_url_open}the related epic%{pg_version_upcoming_url_close} for details.')) % string_args
- }
- end
-
- notices
+ ]
end
end
end
diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb
index e7df9fd27f0..990c940d200 100644
--- a/lib/gitlab/database.rb
+++ b/lib/gitlab/database.rb
@@ -6,20 +6,6 @@ module Gitlab
# https://docs.gitlab.com/ee/install/requirements.html#postgresql-requirements
MINIMUM_POSTGRES_VERSION = 11
- # Upcoming PostgreSQL version requirements
- # Allows a soft warning about an upcoming minimum version requirement
- # so administrators can prepare to upgrade
- UPCOMING_POSTGRES_VERSION_DETAILS = {
- gl_version: '13.6.0',
- gl_version_date: 'November 22, 2020',
- pg_version_minimum: 12,
- url: 'https://gitlab.com/groups/gitlab-org/-/epics/2374'
- }.freeze
-
- # Specifies the maximum number of days in advance to display a notice
- # regarding an upcoming PostgreSQL version deprecation.
- DEPRECATION_WINDOW_DAYS = 90
-
# https://www.postgresql.org/docs/9.2/static/datatype-numeric.html
MAX_INT_VALUE = 2147483647
MIN_INT_VALUE = -2147483648
@@ -114,22 +100,6 @@ module Gitlab
version.to_f >= MINIMUM_POSTGRES_VERSION
end
- def self.postgresql_upcoming_deprecation?
- version.to_f < UPCOMING_POSTGRES_VERSION_DETAILS[:pg_version_minimum]
- end
-
- def self.days_until_deprecation
- (
- Date.parse(UPCOMING_POSTGRES_VERSION_DETAILS[:gl_version_date]) -
- Date.today
- ).to_i
- end
- private_class_method :days_until_deprecation
-
- def self.within_deprecation_notice_window?
- days_until_deprecation <= DEPRECATION_WINDOW_DAYS
- end
-
def self.check_postgres_version_and_print_warning
return if Gitlab::Database.postgresql_minimum_supported_version?
return if Gitlab::Runtime.rails_runner?
diff --git a/lib/gitlab/quick_actions/relate_actions.rb b/lib/gitlab/quick_actions/relate_actions.rb
new file mode 100644
index 00000000000..95f71214667
--- /dev/null
+++ b/lib/gitlab/quick_actions/relate_actions.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module QuickActions
+ module RelateActions
+ extend ActiveSupport::Concern
+ include ::Gitlab::QuickActions::Dsl
+
+ included do
+ desc _('Mark this issue as related to another issue')
+ explanation do |related_reference|
+ _('Marks this issue as related to %{issue_ref}.') % { issue_ref: related_reference }
+ end
+ execution_message do |related_reference|
+ _('Marked this issue as related to %{issue_ref}.') % { issue_ref: related_reference }
+ end
+ params '#issue'
+ types Issue
+ condition do
+ quick_action_target.persisted? &&
+ current_user.can?(:"update_#{quick_action_target.to_ability_name}", quick_action_target)
+ end
+ command :relate do |related_param|
+ IssueLinks::CreateService.new(quick_action_target, current_user, { issuable_references: [related_param] }).execute
+ end
+ end
+ end
+ end
+end
diff --git a/locale/gitlab.pot b/locale/gitlab.pot
index 12a7ecb6bb3..95578d047e7 100644
--- a/locale/gitlab.pot
+++ b/locale/gitlab.pot
@@ -422,7 +422,7 @@ msgstr ""
msgid "%{firstMilestoneName} + %{numberOfOtherMilestones} more"
msgstr ""
-msgid "%{global_id} is not a valid id for %{expected_type}."
+msgid "%{global_id} is not a valid ID for %{expected_type}."
msgstr ""
msgid "%{group_docs_link_start}Groups%{group_docs_link_end} allow you to manage and collaborate across multiple projects. Members of a group have access to all of its projects."
@@ -12593,6 +12593,9 @@ msgstr ""
msgid "How many users will be evaluating the trial?"
msgstr ""
+msgid "How to upgrade"
+msgstr ""
+
msgid "However, you are already a member of this %{member_source}. Sign in using a different account to accept the invitation."
msgstr ""
@@ -16622,9 +16625,6 @@ msgstr ""
msgid "Note parameters are invalid: %{errors}"
msgstr ""
-msgid "Note that PostgreSQL %{pg_version_upcoming} will become the minimum required version in GitLab %{gl_version_upcoming} (%{gl_version_upcoming_date}). Please consider upgrading your environment to a supported PostgreSQL version soon, see %{pg_version_upcoming_url_open}the related epic%{pg_version_upcoming_url_close} for details."
-msgstr ""
-
msgid "Note that this invitation was sent to %{mail_to_invite_email}, but you are signed in as %{link_to_current_user} with email %{mail_to_current_user}."
msgstr ""
@@ -27933,7 +27933,7 @@ msgstr ""
msgid "You are trying to upload something other than an image. Please upload a .png, .jpg, .jpeg, .gif, .bmp, .tiff or .ico."
msgstr ""
-msgid "You are using PostgreSQL %{pg_version_current}, but PostgreSQL %{pg_version_minimum} is required for this version of GitLab. Please upgrade your environment to a supported PostgreSQL version, see %{pg_requirements_url_open}database requirements%{pg_requirements_url_close} for details."
+msgid "You are using PostgreSQL %{pg_version_current}, but PostgreSQL %{pg_version_minimum} is required for this version of GitLab. Please upgrade your environment to a supported PostgreSQL version, see %{pg_requirements_url} for details."
msgstr ""
msgid "You can %{linkStart}view the blob%{linkEnd} instead."
diff --git a/spec/factories/issue_links.rb b/spec/factories/issue_links.rb
new file mode 100644
index 00000000000..884e4dfac08
--- /dev/null
+++ b/spec/factories/issue_links.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :issue_link do
+ source factory: :issue
+ target factory: :issue
+ end
+end
diff --git a/spec/finders/fork_targets_finder_spec.rb b/spec/finders/fork_targets_finder_spec.rb
index 7208f46cfff..12f01227af8 100644
--- a/spec/finders/fork_targets_finder_spec.rb
+++ b/spec/finders/fork_targets_finder_spec.rb
@@ -35,5 +35,13 @@ RSpec.describe ForkTargetsFinder do
it 'returns all user manageable namespaces' do
expect(finder.execute).to match_array([user.namespace, maintained_group, owned_group, project.namespace])
end
+
+ it 'returns only groups when only_groups option is passed' do
+ expect(finder.execute(only_groups: true)).to match_array([maintained_group, owned_group, project.namespace])
+ end
+
+ it 'returns groups relation when only_groups option is passed' do
+ expect(finder.execute(only_groups: true)).to include(a_kind_of(Group))
+ end
end
end
diff --git a/spec/frontend/add_context_commits_modal/components/__snapshots__/add_context_commits_modal_spec.js.snap b/spec/frontend/add_context_commits_modal/components/__snapshots__/add_context_commits_modal_spec.js.snap
index 5fad0d07f97..30dc58f0f28 100644
--- a/spec/frontend/add_context_commits_modal/components/__snapshots__/add_context_commits_modal_spec.js.snap
+++ b/spec/frontend/add_context_commits_modal/components/__snapshots__/add_context_commits_modal_spec.js.snap
@@ -47,4 +47,4 @@ exports[`AddContextCommitsModal renders modal with 2 tabs 1`] = `
</gl-tab-stub>
</gl-tabs-stub>
</gl-modal-stub>
-`;
+`; \ No newline at end of file
diff --git a/spec/graphql/mutations/discussions/toggle_resolve_spec.rb b/spec/graphql/mutations/discussions/toggle_resolve_spec.rb
index 9ac4d6ab165..d779a2227c1 100644
--- a/spec/graphql/mutations/discussions/toggle_resolve_spec.rb
+++ b/spec/graphql/mutations/discussions/toggle_resolve_spec.rb
@@ -51,7 +51,7 @@ RSpec.describe Mutations::Discussions::ToggleResolve do
it 'raises an error' do
expect { subject }.to raise_error(
Gitlab::Graphql::Errors::ArgumentError,
- "#{discussion.to_global_id} is not a valid id for Discussion."
+ "#{discussion.to_global_id} is not a valid ID for Discussion."
)
end
end
diff --git a/spec/lib/gitlab/config_checker/external_database_checker_spec.rb b/spec/lib/gitlab/config_checker/external_database_checker_spec.rb
index 712903e020a..85bafc77553 100644
--- a/spec/lib/gitlab/config_checker/external_database_checker_spec.rb
+++ b/spec/lib/gitlab/config_checker/external_database_checker_spec.rb
@@ -6,84 +6,35 @@ RSpec.describe Gitlab::ConfigChecker::ExternalDatabaseChecker do
describe '#check' do
subject { described_class.check }
- let_it_be(:deprecation_warning) { "Please upgrade" }
- let_it_be(:upcoming_deprecation_warning) { "Please consider upgrading" }
-
- context 'when database meets minimum version and there is no upcoming deprecation' do
+ context 'when database meets minimum supported version' do
before do
allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(true)
- allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(false)
end
it { is_expected.to be_empty }
end
- context 'when database does not meet minimum version and there is no upcoming deprecation' do
+ context 'when database does not meet minimum supported version' do
before do
allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(false)
- allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(false)
- end
-
- it 'only returns notice about deprecated database version' do
- is_expected.to include(a_hash_including(message: include(deprecation_warning)))
- is_expected.not_to include(a_hash_including(message: include(upcoming_deprecation_warning)))
end
- end
- context 'when database meets minimum version and there is an upcoming deprecation' do
- before do
- allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(true)
- allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(true)
+ let(:notice_deprecated_database) do
+ {
+ type: 'warning',
+ message: _('You are using PostgreSQL %{pg_version_current}, but PostgreSQL ' \
+ '%{pg_version_minimum} is required for this version of GitLab. ' \
+ 'Please upgrade your environment to a supported PostgreSQL version, ' \
+ 'see %{pg_requirements_url} for details.') % {
+ pg_version_current: Gitlab::Database.version,
+ pg_version_minimum: Gitlab::Database::MINIMUM_POSTGRES_VERSION,
+ pg_requirements_url: '<a href="https://docs.gitlab.com/ee/install/requirements.html#database">database requirements</a>'
+ }
+ }
end
- context 'inside the deprecation notice window' do
- before do
- allow(Gitlab::Database).to receive(:within_deprecation_notice_window?).and_return(true)
- end
-
- it 'only returns notice about an upcoming deprecation' do
- is_expected.to include(a_hash_including(message: include(upcoming_deprecation_warning)))
- is_expected.not_to include(a_hash_including(message: include(deprecation_warning)))
- end
- end
-
- context 'outside the deprecation notice window' do
- before do
- allow(Gitlab::Database).to receive(:within_deprecation_notice_window?).and_return(false)
- end
-
- it { is_expected.to be_empty }
- end
- end
-
- context 'when database does not meet minimum version and there is an upcoming deprecation' do
- before do
- allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(false)
- allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(true)
- end
-
- context 'inside the deprecation notice window' do
- before do
- allow(Gitlab::Database).to receive(:within_deprecation_notice_window?).and_return(true)
- end
-
- it 'returns notice about deprecated database version and an upcoming deprecation' do
- is_expected.to include(
- a_hash_including(message: include(deprecation_warning)),
- a_hash_including(message: include(upcoming_deprecation_warning))
- )
- end
- end
-
- context 'outside the deprecation notice window' do
- before do
- allow(Gitlab::Database).to receive(:within_deprecation_notice_window?).and_return(false)
- end
-
- it 'only returns notice about deprecated database version' do
- is_expected.to include(a_hash_including(message: include(deprecation_warning)))
- is_expected.not_to include(a_hash_including(message: include(upcoming_deprecation_warning)))
- end
+ it 'reports deprecated database notice' do
+ is_expected.to contain_exactly(notice_deprecated_database)
end
end
end
diff --git a/spec/lib/gitlab/database_spec.rb b/spec/lib/gitlab/database_spec.rb
index 47d2cb05240..420aa0a8df6 100644
--- a/spec/lib/gitlab/database_spec.rb
+++ b/spec/lib/gitlab/database_spec.rb
@@ -109,46 +109,6 @@ RSpec.describe Gitlab::Database do
end
end
- describe '.postgresql_upcoming_deprecation?' do
- it 'returns true when database version is lower than the upcoming minimum' do
- allow(described_class).to receive(:version).and_return('11')
-
- expect(described_class.postgresql_upcoming_deprecation?).to eq(true)
- end
-
- it 'returns false when database version equals the upcoming minimum' do
- allow(described_class).to receive(:version).and_return('12')
-
- expect(described_class.postgresql_upcoming_deprecation?).to eq(false)
- end
-
- it 'returns false when database version is greater the upcoming minimum' do
- allow(described_class).to receive(:version).and_return('13')
-
- expect(described_class.postgresql_upcoming_deprecation?).to eq(false)
- end
- end
-
- describe '.within_deprecation_notice_window?' do
- using RSpec::Parameterized::TableSyntax
-
- where(:case_name, :days, :result) do
- 'outside window' | Gitlab::Database::DEPRECATION_WINDOW_DAYS + 1 | false
- 'equal to window' | Gitlab::Database::DEPRECATION_WINDOW_DAYS | true
- 'within window' | Gitlab::Database::DEPRECATION_WINDOW_DAYS - 1 | true
- end
-
- with_them do
- it "returns #{params[:result]} when #{params[:case_name]}" do
- allow(Date)
- .to receive(:today)
- .and_return Date.parse(Gitlab::Database::UPCOMING_POSTGRES_VERSION_DETAILS[:gl_version_date]) - days
-
- expect(described_class.within_deprecation_notice_window?).to eq(result)
- end
- end
- end
-
describe '.check_postgres_version_and_print_warning' do
subject { described_class.check_postgres_version_and_print_warning }
diff --git a/spec/models/issue_link_spec.rb b/spec/models/issue_link_spec.rb
new file mode 100644
index 00000000000..00791d4a48b
--- /dev/null
+++ b/spec/models/issue_link_spec.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe IssueLink do
+ describe 'Associations' do
+ it { is_expected.to belong_to(:source).class_name('Issue') }
+ it { is_expected.to belong_to(:target).class_name('Issue') }
+ end
+
+ describe 'link_type' do
+ it { is_expected.to define_enum_for(:link_type).with_values(relates_to: 0, blocks: 1, is_blocked_by: 2) }
+
+ it 'provides the "related" as default link_type' do
+ expect(create(:issue_link).link_type).to eq 'relates_to'
+ end
+ end
+
+ describe 'Validation' do
+ subject { create :issue_link }
+
+ it { is_expected.to validate_presence_of(:source) }
+ it { is_expected.to validate_presence_of(:target) }
+ it do
+ is_expected.to validate_uniqueness_of(:source)
+ .scoped_to(:target_id)
+ .with_message(/already related/)
+ end
+
+ context 'self relation' do
+ let(:issue) { create :issue }
+
+ context 'cannot be validated' do
+ it 'does not invalidate object with self relation error' do
+ issue_link = build :issue_link, source: issue, target: nil
+
+ issue_link.valid?
+
+ expect(issue_link.errors[:source]).to be_empty
+ end
+ end
+
+ context 'can be invalidated' do
+ it 'invalidates object' do
+ issue_link = build :issue_link, source: issue, target: issue
+
+ expect(issue_link).to be_invalid
+ expect(issue_link.errors[:source]).to include('cannot be related to itself')
+ end
+ end
+ end
+ end
+end
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index 59634524e74..af0348b972a 100644
--- a/spec/models/issue_spec.rb
+++ b/spec/models/issue_spec.rb
@@ -311,6 +311,50 @@ RSpec.describe Issue do
end
end
+ describe '#related_issues' do
+ let(:user) { create(:user) }
+ let(:authorized_project) { create(:project) }
+ let(:authorized_project2) { create(:project) }
+ let(:unauthorized_project) { create(:project) }
+
+ let(:authorized_issue_a) { create(:issue, project: authorized_project) }
+ let(:authorized_issue_b) { create(:issue, project: authorized_project) }
+ let(:authorized_issue_c) { create(:issue, project: authorized_project2) }
+
+ let(:unauthorized_issue) { create(:issue, project: unauthorized_project) }
+
+ let!(:issue_link_a) { create(:issue_link, source: authorized_issue_a, target: authorized_issue_b) }
+ let!(:issue_link_b) { create(:issue_link, source: authorized_issue_a, target: unauthorized_issue) }
+ let!(:issue_link_c) { create(:issue_link, source: authorized_issue_a, target: authorized_issue_c) }
+
+ before do
+ authorized_project.add_developer(user)
+ authorized_project2.add_developer(user)
+ end
+
+ it 'returns only authorized related issues for given user' do
+ expect(authorized_issue_a.related_issues(user))
+ .to contain_exactly(authorized_issue_b, authorized_issue_c)
+ end
+
+ it 'returns issues with valid issue_link_type' do
+ link_types = authorized_issue_a.related_issues(user).map(&:issue_link_type)
+
+ expect(link_types).not_to be_empty
+ expect(link_types).not_to include(nil)
+ end
+
+ describe 'when a user cannot read cross project' do
+ it 'only returns issues within the same project' do
+ expect(Ability).to receive(:allowed?).with(user, :read_all_resources, :global).at_least(:once).and_call_original
+ expect(Ability).to receive(:allowed?).with(user, :read_cross_project).and_return(false)
+
+ expect(authorized_issue_a.related_issues(user))
+ .to contain_exactly(authorized_issue_b)
+ end
+ end
+ end
+
describe '#can_move?' do
let(:issue) { create(:issue) }
diff --git a/spec/requests/api/graphql/mutations/metrics/dashboard/annotations/create_spec.rb b/spec/requests/api/graphql/mutations/metrics/dashboard/annotations/create_spec.rb
index 0e2da94f0f9..10ca2cf1cf8 100644
--- a/spec/requests/api/graphql/mutations/metrics/dashboard/annotations/create_spec.rb
+++ b/spec/requests/api/graphql/mutations/metrics/dashboard/annotations/create_spec.rb
@@ -101,7 +101,7 @@ RSpec.describe Mutations::Metrics::Dashboard::Annotations::Create do
graphql_mutation(:create_annotation, variables)
end
- it_behaves_like 'a mutation that returns top-level errors', errors: ['invalid_id is not a valid GitLab id.']
+ it_behaves_like 'a mutation that returns top-level errors', errors: ['invalid_id is not a valid GitLab ID.']
end
end
end
@@ -188,7 +188,7 @@ RSpec.describe Mutations::Metrics::Dashboard::Annotations::Create do
graphql_mutation(:create_annotation, variables)
end
- it_behaves_like 'a mutation that returns top-level errors', errors: ['invalid_id is not a valid GitLab id.']
+ it_behaves_like 'a mutation that returns top-level errors', errors: ['invalid_id is not a valid GitLab ID.']
end
end
diff --git a/spec/requests/api/graphql/mutations/metrics/dashboard/annotations/delete_spec.rb b/spec/requests/api/graphql/mutations/metrics/dashboard/annotations/delete_spec.rb
index 2459a6f3828..7357f3e1e35 100644
--- a/spec/requests/api/graphql/mutations/metrics/dashboard/annotations/delete_spec.rb
+++ b/spec/requests/api/graphql/mutations/metrics/dashboard/annotations/delete_spec.rb
@@ -45,7 +45,7 @@ RSpec.describe Mutations::Metrics::Dashboard::Annotations::Delete do
graphql_mutation(:delete_annotation, variables)
end
- it_behaves_like 'a mutation that returns top-level errors', errors: ['invalid_id is not a valid GitLab id.']
+ it_behaves_like 'a mutation that returns top-level errors', errors: ['invalid_id is not a valid GitLab ID.']
end
context 'when the delete fails' do
diff --git a/spec/requests/api/graphql/mutations/todos/mark_done_spec.rb b/spec/requests/api/graphql/mutations/todos/mark_done_spec.rb
index 9c4733f6769..c1232500d79 100644
--- a/spec/requests/api/graphql/mutations/todos/mark_done_spec.rb
+++ b/spec/requests/api/graphql/mutations/todos/mark_done_spec.rb
@@ -80,7 +80,7 @@ RSpec.describe 'Marking todos done' do
context 'when using an invalid gid' do
let(:input) { { id: 'invalid_gid' } }
- let(:invalid_gid_error) { 'invalid_gid is not a valid GitLab id.' }
+ let(:invalid_gid_error) { 'invalid_gid is not a valid GitLab ID.' }
it 'contains the expected error' do
post_graphql_mutation(mutation, current_user: current_user)
diff --git a/spec/requests/api/graphql/mutations/todos/restore_spec.rb b/spec/requests/api/graphql/mutations/todos/restore_spec.rb
index 6dedde56e13..0797961f65f 100644
--- a/spec/requests/api/graphql/mutations/todos/restore_spec.rb
+++ b/spec/requests/api/graphql/mutations/todos/restore_spec.rb
@@ -80,7 +80,7 @@ RSpec.describe 'Restoring Todos' do
context 'when using an invalid gid' do
let(:input) { { id: 'invalid_gid' } }
- let(:invalid_gid_error) { 'invalid_gid is not a valid GitLab id.' }
+ let(:invalid_gid_error) { 'invalid_gid is not a valid GitLab ID.' }
it 'contains the expected error' do
post_graphql_mutation(mutation, current_user: current_user)
diff --git a/spec/serializers/fork_namespace_entity_spec.rb b/spec/serializers/fork_namespace_entity_spec.rb
index 7ce6b77da44..7740ed77540 100644
--- a/spec/serializers/fork_namespace_entity_spec.rb
+++ b/spec/serializers/fork_namespace_entity_spec.rb
@@ -8,13 +8,17 @@ RSpec.describe ForkNamespaceEntity do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
+ let_it_be(:namespace) { create(:group, :with_avatar, description: 'test') }
+ let(:memberships) do
+ user.members.index_by(&:source_id)
+ end
- let(:namespace) { create(:group, :with_avatar, description: 'test') }
- let(:entity) { described_class.new(namespace, current_user: user, project: project) }
+ let(:entity) { described_class.new(namespace, current_user: user, project: project, memberships: memberships) }
subject(:json) { entity.as_json }
before do
+ namespace.add_developer(user)
project.add_maintainer(user)
end
@@ -52,7 +56,6 @@ RSpec.describe ForkNamespaceEntity do
end
it 'exposes human readable permission level' do
- namespace.add_developer(user)
expect(json[:permission]).to eql 'Developer'
end
diff --git a/spec/serializers/linked_project_issue_entity_spec.rb b/spec/serializers/linked_project_issue_entity_spec.rb
new file mode 100644
index 00000000000..864b5c45599
--- /dev/null
+++ b/spec/serializers/linked_project_issue_entity_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe LinkedProjectIssueEntity do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project) }
+ let_it_be(:issue_link) { create(:issue_link) }
+
+ let(:request) { double('request') }
+ let(:related_issue) { issue_link.source.related_issues(user).first }
+ let(:entity) { described_class.new(related_issue, request: request, current_user: user) }
+
+ before do
+ allow(request).to receive(:current_user).and_return(user)
+ allow(request).to receive(:issuable).and_return(issue_link.source)
+ issue_link.target.project.add_developer(user)
+ end
+
+ describe 'issue_link_type' do
+ it { expect(entity.as_json).to include(link_type: 'relates_to') }
+ end
+end
diff --git a/spec/services/issue_links/create_service_spec.rb b/spec/services/issue_links/create_service_spec.rb
new file mode 100644
index 00000000000..a60950e64cb
--- /dev/null
+++ b/spec/services/issue_links/create_service_spec.rb
@@ -0,0 +1,176 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe IssueLinks::CreateService do
+ describe '#execute' do
+ let(:namespace) { create :namespace }
+ let(:project) { create :project, namespace: namespace }
+ let(:issue) { create :issue, project: project }
+ let(:user) { create :user }
+ let(:params) do
+ {}
+ end
+
+ before do
+ project.add_developer(user)
+ end
+
+ subject { described_class.new(issue, user, params).execute }
+
+ context 'when the reference list is empty' do
+ let(:params) do
+ { issuable_references: [] }
+ end
+
+ it 'returns error' do
+ is_expected.to eq(message: 'No Issue found for given params', status: :error, http_status: 404)
+ end
+ end
+
+ context 'when Issue not found' do
+ let(:params) do
+ { issuable_references: ["##{non_existing_record_iid}"] }
+ end
+
+ it 'returns error' do
+ is_expected.to eq(message: 'No Issue found for given params', status: :error, http_status: 404)
+ end
+
+ it 'no relationship is created' do
+ expect { subject }.not_to change(IssueLink, :count)
+ end
+ end
+
+ context 'when user has no permission to target project Issue' do
+ let(:target_issuable) { create :issue }
+
+ let(:params) do
+ { issuable_references: [target_issuable.to_reference(project)] }
+ end
+
+ it 'returns error' do
+ target_issuable.project.add_guest(user)
+
+ is_expected.to eq(message: 'No Issue found for given params', status: :error, http_status: 404)
+ end
+
+ it 'no relationship is created' do
+ expect { subject }.not_to change(IssueLink, :count)
+ end
+ end
+
+ context 'source and target are the same issue' do
+ let(:params) do
+ { issuable_references: [issue.to_reference] }
+ end
+
+ it 'does not create notes' do
+ expect(SystemNoteService).not_to receive(:relate_issue)
+
+ subject
+ end
+
+ it 'no relationship is created' do
+ expect { subject }.not_to change(IssueLink, :count)
+ end
+ end
+
+ context 'when there is an issue to relate' do
+ let(:issue_a) { create :issue, project: project }
+ let(:another_project) { create :project, namespace: project.namespace }
+ let(:another_project_issue) { create :issue, project: another_project }
+
+ let(:issue_a_ref) { issue_a.to_reference }
+ let(:another_project_issue_ref) { another_project_issue.to_reference(project) }
+
+ let(:params) do
+ { issuable_references: [issue_a_ref, another_project_issue_ref] }
+ end
+
+ before do
+ another_project.add_developer(user)
+ end
+
+ it 'creates relationships' do
+ expect { subject }.to change(IssueLink, :count).from(0).to(2)
+
+ expect(IssueLink.find_by!(target: issue_a)).to have_attributes(source: issue, link_type: 'relates_to')
+ expect(IssueLink.find_by!(target: another_project_issue)).to have_attributes(source: issue, link_type: 'relates_to')
+ end
+
+ it 'returns success status' do
+ is_expected.to eq(status: :success)
+ end
+
+ it 'creates notes' do
+ # First two-way relation notes
+ expect(SystemNoteService).to receive(:relate_issue)
+ .with(issue, issue_a, user)
+ expect(SystemNoteService).to receive(:relate_issue)
+ .with(issue_a, issue, user)
+
+ # Second two-way relation notes
+ expect(SystemNoteService).to receive(:relate_issue)
+ .with(issue, another_project_issue, user)
+ expect(SystemNoteService).to receive(:relate_issue)
+ .with(another_project_issue, issue, user)
+
+ subject
+ end
+ end
+
+ context 'when reference of any already related issue is present' do
+ let(:issue_a) { create :issue, project: project }
+ let(:issue_b) { create :issue, project: project }
+ let(:issue_c) { create :issue, project: project }
+
+ before do
+ create :issue_link, source: issue, target: issue_b, link_type: IssueLink::TYPE_RELATES_TO
+ create :issue_link, source: issue, target: issue_c, link_type: IssueLink::TYPE_RELATES_TO
+ end
+
+ let(:params) do
+ {
+ issuable_references: [
+ issue_a.to_reference,
+ issue_b.to_reference,
+ issue_c.to_reference
+ ],
+ link_type: IssueLink::TYPE_RELATES_TO
+ }
+ end
+
+ it 'creates notes only for new relations' do
+ expect(SystemNoteService).to receive(:relate_issue).with(issue, issue_a, anything)
+ expect(SystemNoteService).to receive(:relate_issue).with(issue_a, issue, anything)
+ expect(SystemNoteService).not_to receive(:relate_issue).with(issue, issue_b, anything)
+ expect(SystemNoteService).not_to receive(:relate_issue).with(issue_b, issue, anything)
+ expect(SystemNoteService).not_to receive(:relate_issue).with(issue, issue_c, anything)
+ expect(SystemNoteService).not_to receive(:relate_issue).with(issue_c, issue, anything)
+
+ subject
+ end
+ end
+
+ context 'when there are invalid references' do
+ let(:issue_a) { create :issue, project: project }
+
+ let(:params) do
+ { issuable_references: [issue.to_reference, issue_a.to_reference] }
+ end
+
+ it 'creates links only for valid references' do
+ expect { subject }.to change { IssueLink.count }.by(1)
+ end
+
+ it 'returns error status' do
+ expect(subject).to eq(
+ status: :error,
+ http_status: 422,
+ message: "#{issue.to_reference} cannot be added: cannot be related to itself"
+ )
+ end
+ end
+ end
+end
diff --git a/spec/services/issue_links/destroy_service_spec.rb b/spec/services/issue_links/destroy_service_spec.rb
new file mode 100644
index 00000000000..3f5b7ccf9ba
--- /dev/null
+++ b/spec/services/issue_links/destroy_service_spec.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe IssueLinks::DestroyService do
+ describe '#execute' do
+ let(:project) { create(:project_empty_repo) }
+ let(:user) { create(:user) }
+
+ subject { described_class.new(issue_link, user).execute }
+
+ context 'when successfully removes an issue link' do
+ let(:issue_a) { create(:issue, project: project) }
+ let(:issue_b) { create(:issue, project: project) }
+
+ let!(:issue_link) { create(:issue_link, source: issue_a, target: issue_b) }
+
+ before do
+ project.add_reporter(user)
+ end
+
+ it 'removes related issue' do
+ expect { subject }.to change(IssueLink, :count).from(1).to(0)
+ end
+
+ it 'creates notes' do
+ # Two-way notes creation
+ expect(SystemNoteService).to receive(:unrelate_issue)
+ .with(issue_link.source, issue_link.target, user)
+ expect(SystemNoteService).to receive(:unrelate_issue)
+ .with(issue_link.target, issue_link.source, user)
+
+ subject
+ end
+
+ it 'returns success message' do
+ is_expected.to eq(message: 'Relation was removed', status: :success)
+ end
+ end
+
+ context 'when failing to remove an issue link' do
+ let(:unauthorized_project) { create(:project) }
+ let(:issue_a) { create(:issue, project: project) }
+ let(:issue_b) { create(:issue, project: unauthorized_project) }
+
+ let!(:issue_link) { create(:issue_link, source: issue_a, target: issue_b) }
+
+ it 'does not remove relation' do
+ expect { subject }.not_to change(IssueLink, :count).from(1)
+ end
+
+ it 'does not create notes' do
+ expect(SystemNoteService).not_to receive(:unrelate_issue)
+ end
+
+ it 'returns error message' do
+ is_expected.to eq(message: 'No Issue Link found', status: :error, http_status: 404)
+ end
+ end
+ end
+end
diff --git a/spec/services/issue_links/list_service_spec.rb b/spec/services/issue_links/list_service_spec.rb
new file mode 100644
index 00000000000..7a3ba845c7c
--- /dev/null
+++ b/spec/services/issue_links/list_service_spec.rb
@@ -0,0 +1,194 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe IssueLinks::ListService do
+ let(:user) { create :user }
+ let(:project) { create(:project_empty_repo, :private) }
+ let(:issue) { create :issue, project: project }
+ let(:user_role) { :developer }
+
+ before do
+ project.add_role(user, user_role)
+ end
+
+ describe '#execute' do
+ subject { described_class.new(issue, user).execute }
+
+ context 'user can see all issues' do
+ let(:issue_b) { create :issue, project: project }
+ let(:issue_c) { create :issue, project: project }
+ let(:issue_d) { create :issue, project: project }
+
+ let!(:issue_link_c) do
+ create(:issue_link, source: issue_d,
+ target: issue)
+ end
+
+ let!(:issue_link_b) do
+ create(:issue_link, source: issue,
+ target: issue_c)
+ end
+
+ let!(:issue_link_a) do
+ create(:issue_link, source: issue,
+ target: issue_b)
+ end
+
+ it 'ensures no N+1 queries are made' do
+ control_count = ActiveRecord::QueryRecorder.new { subject }.count
+
+ project = create :project, :public
+ milestone = create :milestone, project: project
+ issue_x = create :issue, project: project, milestone: milestone
+ issue_y = create :issue, project: project, assignees: [user]
+ issue_z = create :issue, project: project
+ create :issue_link, source: issue_x, target: issue_y
+ create :issue_link, source: issue_x, target: issue_z
+ create :issue_link, source: issue_y, target: issue_z
+
+ expect { subject }.not_to exceed_query_limit(control_count)
+ end
+
+ it 'returns related issues JSON' do
+ expect(subject.size).to eq(3)
+
+ expect(subject).to include(include(id: issue_b.id,
+ title: issue_b.title,
+ state: issue_b.state,
+ reference: issue_b.to_reference(project),
+ path: "/#{project.full_path}/-/issues/#{issue_b.iid}",
+ relation_path: "/#{project.full_path}/-/issues/#{issue.iid}/links/#{issue_link_a.id}"))
+
+ expect(subject).to include(include(id: issue_c.id,
+ title: issue_c.title,
+ state: issue_c.state,
+ reference: issue_c.to_reference(project),
+ path: "/#{project.full_path}/-/issues/#{issue_c.iid}",
+ relation_path: "/#{project.full_path}/-/issues/#{issue.iid}/links/#{issue_link_b.id}"))
+
+ expect(subject).to include(include(id: issue_d.id,
+ title: issue_d.title,
+ state: issue_d.state,
+ reference: issue_d.to_reference(project),
+ path: "/#{project.full_path}/-/issues/#{issue_d.iid}",
+ relation_path: "/#{project.full_path}/-/issues/#{issue.iid}/links/#{issue_link_c.id}"))
+ end
+ end
+
+ context 'referencing a public project issue' do
+ let(:public_project) { create :project, :public }
+ let(:issue_b) { create :issue, project: public_project }
+
+ let!(:issue_link) do
+ create(:issue_link, source: issue, target: issue_b)
+ end
+
+ it 'presents issue' do
+ expect(subject.size).to eq(1)
+ end
+ end
+
+ context 'referencing issue with removed relationships' do
+ context 'when referenced a deleted issue' do
+ let(:issue_b) { create :issue, project: project }
+ let!(:issue_link) do
+ create(:issue_link, source: issue, target: issue_b)
+ end
+
+ it 'ignores issue' do
+ issue_b.destroy!
+
+ is_expected.to eq([])
+ end
+ end
+
+ context 'when referenced an issue with deleted project' do
+ let(:issue_b) { create :issue, project: project }
+ let!(:issue_link) do
+ create(:issue_link, source: issue, target: issue_b)
+ end
+
+ it 'ignores issue' do
+ project.destroy!
+
+ is_expected.to eq([])
+ end
+ end
+
+ context 'when referenced an issue with deleted namespace' do
+ let(:issue_b) { create :issue, project: project }
+ let!(:issue_link) do
+ create(:issue_link, source: issue, target: issue_b)
+ end
+
+ it 'ignores issue' do
+ project.namespace.destroy!
+
+ is_expected.to eq([])
+ end
+ end
+ end
+
+ context 'user cannot see relations' do
+ context 'when user cannot see the referenced issue' do
+ let!(:issue_link) do
+ create(:issue_link, source: issue)
+ end
+
+ it 'returns an empty list' do
+ is_expected.to eq([])
+ end
+ end
+
+ context 'when user cannot see the issue that referenced' do
+ let!(:issue_link) do
+ create(:issue_link, target: issue)
+ end
+
+ it 'returns an empty list' do
+ is_expected.to eq([])
+ end
+ end
+ end
+
+ context 'remove relations' do
+ let!(:issue_link) do
+ create(:issue_link, source: issue, target: referenced_issue)
+ end
+
+ context 'user can admin related issues just on target project' do
+ let(:user_role) { :guest }
+ let(:target_project) { create :project }
+ let(:referenced_issue) { create :issue, project: target_project }
+
+ it 'returns no destroy relation path' do
+ target_project.add_developer(user)
+
+ expect(subject.first[:relation_path]).to be_nil
+ end
+ end
+
+ context 'user can admin related issues just on source project' do
+ let(:user_role) { :developer }
+ let(:target_project) { create :project }
+ let(:referenced_issue) { create :issue, project: target_project }
+
+ it 'returns no destroy relation path' do
+ target_project.add_guest(user)
+
+ expect(subject.first[:relation_path]).to be_nil
+ end
+ end
+
+ context 'when user can admin related issues on both projects' do
+ let(:referenced_issue) { create :issue, project: project }
+
+ it 'returns related issue destroy relation path' do
+ expect(subject.first[:relation_path])
+ .to eq("/#{project.full_path}/-/issues/#{issue.iid}/links/#{issue_link.id}")
+ end
+ end
+ end
+ end
+end
diff --git a/spec/services/issues/duplicate_service_spec.rb b/spec/services/issues/duplicate_service_spec.rb
index 78e030e6ac7..0b5bc3f32ef 100644
--- a/spec/services/issues/duplicate_service_spec.rb
+++ b/spec/services/issues/duplicate_service_spec.rb
@@ -83,6 +83,17 @@ RSpec.describe Issues::DuplicateService do
expect(duplicate_issue.reload.duplicated_to).to eq(canonical_issue)
end
+
+ it 'relates the duplicate issues' do
+ canonical_project.add_reporter(user)
+ duplicate_project.add_reporter(user)
+
+ subject.execute(duplicate_issue, canonical_issue)
+
+ issue_link = IssueLink.last
+ expect(issue_link.source).to eq(duplicate_issue)
+ expect(issue_link.target).to eq(canonical_issue)
+ end
end
end
end
diff --git a/spec/services/issues/move_service_spec.rb b/spec/services/issues/move_service_spec.rb
index 5f944d1213b..5d032b28399 100644
--- a/spec/services/issues/move_service_spec.rb
+++ b/spec/services/issues/move_service_spec.rb
@@ -223,6 +223,45 @@ RSpec.describe Issues::MoveService do
end
end
+ describe '#rewrite_related_issues' do
+ include_context 'user can move issue'
+
+ let(:admin) { create(:admin) }
+ let(:authorized_project) { create(:project) }
+ let(:authorized_project2) { create(:project) }
+ let(:unauthorized_project) { create(:project) }
+
+ let(:authorized_issue_b) { create(:issue, project: authorized_project) }
+ let(:authorized_issue_c) { create(:issue, project: authorized_project2) }
+ let(:authorized_issue_d) { create(:issue, project: authorized_project2) }
+ let(:unauthorized_issue) { create(:issue, project: unauthorized_project) }
+
+ let!(:issue_link_a) { create(:issue_link, source: old_issue, target: authorized_issue_b) }
+ let!(:issue_link_b) { create(:issue_link, source: old_issue, target: unauthorized_issue) }
+ let!(:issue_link_c) { create(:issue_link, source: old_issue, target: authorized_issue_c) }
+ let!(:issue_link_d) { create(:issue_link, source: authorized_issue_d, target: old_issue) }
+
+ before do
+ authorized_project.add_developer(user)
+ authorized_project2.add_developer(user)
+ end
+
+ context 'multiple related issues' do
+ it 'moves all related issues and retains permissions' do
+ new_issue = move_service.execute(old_issue, new_project)
+
+ expect(new_issue.related_issues(admin))
+ .to match_array([authorized_issue_b, authorized_issue_c, authorized_issue_d, unauthorized_issue])
+
+ expect(new_issue.related_issues(user))
+ .to match_array([authorized_issue_b, authorized_issue_c, authorized_issue_d])
+
+ expect(authorized_issue_d.related_issues(user))
+ .to match_array([new_issue])
+ end
+ end
+ end
+
context 'updating sent notifications' do
let!(:old_issue_notification_1) { create(:sent_notification, project: old_issue.project, noteable: old_issue) }
let!(:old_issue_notification_2) { create(:sent_notification, project: old_issue.project, noteable: old_issue) }
diff --git a/spec/services/notes/quick_actions_service_spec.rb b/spec/services/notes/quick_actions_service_spec.rb
index e9decd44730..794491fc50d 100644
--- a/spec/services/notes/quick_actions_service_spec.rb
+++ b/spec/services/notes/quick_actions_service_spec.rb
@@ -4,9 +4,9 @@ require 'spec_helper'
RSpec.describe Notes::QuickActionsService do
shared_context 'note on noteable' do
- let(:project) { create(:project, :repository) }
- let(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } }
- let(:assignee) { create(:user) }
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } }
+ let_it_be(:assignee) { create(:user) }
before do
project.add_maintainer(assignee)
@@ -41,6 +41,36 @@ RSpec.describe Notes::QuickActionsService do
end
end
+ context '/relate' do
+ let_it_be(:issue) { create(:issue, project: project) }
+ let_it_be(:other_issue) { create(:issue, project: project) }
+ let(:note_text) { "/relate #{other_issue.to_reference}" }
+ let(:note) { create(:note_on_issue, noteable: issue, project: project, note: note_text) }
+
+ context 'user cannot relate issues' do
+ before do
+ project.team.find_member(maintainer.id).destroy!
+ project.update!(visibility: Gitlab::VisibilityLevel::PUBLIC)
+ end
+
+ it 'does not create issue relation' do
+ expect do
+ _, update_params = service.execute(note)
+ service.apply_updates(update_params, note)
+ end.not_to change { IssueLink.count }
+ end
+ end
+
+ context 'user is allowed to relate issues' do
+ it 'creates issue relation' do
+ expect do
+ _, update_params = service.execute(note)
+ service.apply_updates(update_params, note)
+ end.to change { IssueLink.count }.by(1)
+ end
+ end
+ end
+
describe '/reopen' do
before do
note.noteable.close!
diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb
index 57e32b1aea9..b970a48051f 100644
--- a/spec/services/quick_actions/interpret_service_spec.rb
+++ b/spec/services/quick_actions/interpret_service_spec.rb
@@ -1644,6 +1644,103 @@ RSpec.describe QuickActions::InterpretService do
end
end
end
+
+ context 'relate command' do
+ let_it_be_with_refind(:group) { create(:group) }
+
+ shared_examples 'relate command' do
+ it 'relates issues' do
+ service.execute(content, issue)
+
+ expect(IssueLink.where(source: issue).map(&:target)).to match_array(issues_related)
+ end
+ end
+
+ context 'user is member of group' do
+ before do
+ group.add_developer(developer)
+ end
+
+ context 'relate a single issue' do
+ let(:other_issue) { create(:issue, project: project) }
+ let(:issues_related) { [other_issue] }
+ let(:content) { "/relate #{other_issue.to_reference}" }
+
+ it_behaves_like 'relate command'
+ end
+
+ context 'relate multiple issues at once' do
+ let(:second_issue) { create(:issue, project: project) }
+ let(:third_issue) { create(:issue, project: project) }
+ let(:issues_related) { [second_issue, third_issue] }
+ let(:content) { "/relate #{second_issue.to_reference} #{third_issue.to_reference}" }
+
+ it_behaves_like 'relate command'
+ end
+
+ context 'empty relate command' do
+ let(:issues_related) { [] }
+ let(:content) { '/relate' }
+
+ it_behaves_like 'relate command'
+ end
+
+ context 'already having related issues' do
+ let(:second_issue) { create(:issue, project: project) }
+ let(:third_issue) { create(:issue, project: project) }
+ let(:issues_related) { [second_issue, third_issue] }
+ let(:content) { "/relate #{third_issue.to_reference(project)}" }
+
+ before do
+ create(:issue_link, source: issue, target: second_issue)
+ end
+
+ it_behaves_like 'relate command'
+ end
+
+ context 'cross project' do
+ let(:another_group) { create(:group, :public) }
+ let(:other_project) { create(:project, group: another_group) }
+
+ before do
+ another_group.add_developer(developer)
+ end
+
+ context 'relate a cross project issue' do
+ let(:other_issue) { create(:issue, project: other_project) }
+ let(:issues_related) { [other_issue] }
+ let(:content) { "/relate #{other_issue.to_reference(project)}" }
+
+ it_behaves_like 'relate command'
+ end
+
+ context 'relate multiple cross projects issues at once' do
+ let(:second_issue) { create(:issue, project: other_project) }
+ let(:third_issue) { create(:issue, project: other_project) }
+ let(:issues_related) { [second_issue, third_issue] }
+ let(:content) { "/relate #{second_issue.to_reference(project)} #{third_issue.to_reference(project)}" }
+
+ it_behaves_like 'relate command'
+ end
+
+ context 'relate a non-existing issue' do
+ let(:issues_related) { [] }
+ let(:content) { "/relate imaginary##{non_existing_record_iid}" }
+
+ it_behaves_like 'relate command'
+ end
+
+ context 'relate a private issue' do
+ let(:private_project) { create(:project, :private) }
+ let(:other_issue) { create(:issue, project: private_project) }
+ let(:issues_related) { [] }
+ let(:content) { "/relate #{other_issue.to_reference(project)}" }
+
+ it_behaves_like 'relate command'
+ end
+ end
+ end
+ end
end
describe '#explain' do
diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb
index 969e5955609..0f5558738ac 100644
--- a/spec/services/system_note_service_spec.rb
+++ b/spec/services/system_note_service_spec.rb
@@ -86,6 +86,40 @@ RSpec.describe SystemNoteService do
end
end
+ describe '.relate_issue' do
+ let(:noteable_ref) { double }
+ let(:noteable) { double }
+
+ before do
+ allow(noteable).to receive(:project).and_return(double)
+ end
+
+ it 'calls IssuableService' do
+ expect_next_instance_of(::SystemNotes::IssuablesService) do |service|
+ expect(service).to receive(:relate_issue).with(noteable_ref)
+ end
+
+ described_class.relate_issue(noteable, noteable_ref, double)
+ end
+ end
+
+ describe '.unrelate_issue' do
+ let(:noteable_ref) { double }
+ let(:noteable) { double }
+
+ before do
+ allow(noteable).to receive(:project).and_return(double)
+ end
+
+ it 'calls IssuableService' do
+ expect_next_instance_of(::SystemNotes::IssuablesService) do |service|
+ expect(service).to receive(:unrelate_issue).with(noteable_ref)
+ end
+
+ described_class.unrelate_issue(noteable, noteable_ref, double)
+ end
+ end
+
describe '.change_due_date' do
let(:due_date) { double }
diff --git a/spec/services/system_notes/issuables_service_spec.rb b/spec/services/system_notes/issuables_service_spec.rb
index 1b5b26d90da..536e9792534 100644
--- a/spec/services/system_notes/issuables_service_spec.rb
+++ b/spec/services/system_notes/issuables_service_spec.rb
@@ -13,6 +13,38 @@ RSpec.describe ::SystemNotes::IssuablesService do
let(:service) { described_class.new(noteable: noteable, project: project, author: author) }
+ describe '#relate_issue' do
+ let(:noteable_ref) { create(:issue) }
+
+ subject { service.relate_issue(noteable_ref) }
+
+ it_behaves_like 'a system note' do
+ let(:action) { 'relate' }
+ end
+
+ context 'when issue marks another as related' do
+ it 'sets the note text' do
+ expect(subject.note).to eq "marked this issue as related to #{noteable_ref.to_reference(project)}"
+ end
+ end
+ end
+
+ describe '#unrelate_issue' do
+ let(:noteable_ref) { create(:issue) }
+
+ subject { service.unrelate_issue(noteable_ref) }
+
+ it_behaves_like 'a system note' do
+ let(:action) { 'unrelate' }
+ end
+
+ context 'when issue relation is removed' do
+ it 'sets the note text' do
+ expect(subject.note).to eq "removed the relation with #{noteable_ref.to_reference(project)}"
+ end
+ end
+ end
+
describe '#change_assignee' do
subject { service.change_assignee(assignee) }