summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/assets/javascripts/notes/components/discussion_actions.vue31
-rw-r--r--app/assets/javascripts/notes/components/noteable_discussion.vue5
-rw-r--r--app/assets/javascripts/notes/stores/getters.js6
-rw-r--r--app/assets/javascripts/performance_bar/components/detailed_metric.vue4
-rw-r--r--app/assets/javascripts/performance_bar/components/performance_bar_app.vue14
-rw-r--r--app/assets/stylesheets/pages/notes.scss4
-rw-r--r--app/graphql/mutations/.keep0
-rw-r--r--app/graphql/mutations/award_emojis/add.rb25
-rw-r--r--app/graphql/mutations/award_emojis/base.rb41
-rw-r--r--app/graphql/mutations/award_emojis/remove.rb33
-rw-r--r--app/graphql/mutations/award_emojis/toggle.rb40
-rw-r--r--app/graphql/mutations/base_mutation.rb7
-rw-r--r--app/graphql/types/award_emojis/award_emoji_type.rb46
-rw-r--r--app/graphql/types/mutation_type.rb3
-rw-r--r--app/models/board.rb5
-rw-r--r--app/models/list.rb1
-rw-r--r--app/models/snippet.rb4
-rw-r--r--app/policies/award_emoji_policy.rb11
-rw-r--r--app/presenters/award_emoji_presenter.rb27
-rw-r--r--app/views/projects/_merge_request_settings_description_text.html.haml1
-rw-r--r--app/views/projects/edit.html.haml2
-rw-r--r--app/views/projects/environments/show.html.haml28
-rw-r--r--app/views/projects/tree/_tree_header.html.haml1
-rw-r--r--changelogs/unreleased/58689-regroup-jump-button-in-discussion.yml6
-rw-r--r--changelogs/unreleased/62826-graphql-emoji-mutations.yml5
-rw-r--r--changelogs/unreleased/62968-environment-details-header-border-misaligned.yml5
-rw-r--r--changelogs/unreleased/ce-11098-update-merge-request-settings-description-text.yml5
-rw-r--r--changelogs/unreleased/support-jsonb-default-value.yml5
-rw-r--r--doc/development/documentation/site_architecture/index.md42
-rw-r--r--doc/user/project/clusters/index.md18
-rw-r--r--lib/api/boards.rb2
-rw-r--r--lib/api/boards_responses.rb2
-rw-r--r--lib/api/entities.rb2
-rw-r--r--lib/api/group_boards.rb2
-rw-r--r--lib/gitlab/database/migration_helpers.rb3
-rw-r--r--lib/gitlab/graphql/copy_field_description.rb21
-rw-r--r--lib/gitlab/graphql/errors.rb1
-rw-r--r--locale/gitlab.pot21
-rw-r--r--spec/factories/award_emoji.rb2
-rw-r--r--spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb4
-rw-r--r--spec/graphql/types/award_emojis/award_emoji_type_spec.rb11
-rw-r--r--spec/javascripts/notes/stores/getters_spec.js20
-rw-r--r--spec/lib/gitlab/database/migration_helpers_spec.rb18
-rw-r--r--spec/lib/gitlab/graphql/authorize/authorize_resource_spec.rb2
-rw-r--r--spec/lib/gitlab/graphql/copy_field_description_spec.rb21
-rw-r--r--spec/policies/award_emoji_policy_spec.rb54
-rw-r--r--spec/presenters/award_emoji_presenter_spec.rb36
-rw-r--r--spec/requests/api/graphql/mutations/award_emojis/add_spec.rb100
-rw-r--r--spec/requests/api/graphql/mutations/award_emojis/remove_spec.rb80
-rw-r--r--spec/requests/api/graphql/mutations/award_emojis/toggle_spec.rb142
-rw-r--r--spec/support/api/boards_shared_examples.rb10
-rw-r--r--spec/support/helpers/graphql_helpers.rb5
-rw-r--r--spec/support/shared_examples/graphql/mutation_shared_examples.rb34
53 files changed, 943 insertions, 75 deletions
diff --git a/app/assets/javascripts/notes/components/discussion_actions.vue b/app/assets/javascripts/notes/components/discussion_actions.vue
index 22cca756ef6..1357a5268d6 100644
--- a/app/assets/javascripts/notes/components/discussion_actions.vue
+++ b/app/assets/javascripts/notes/components/discussion_actions.vue
@@ -39,20 +39,27 @@ export default {
</script>
<template>
- <div class="discussion-with-resolve-btn">
+ <div class="discussion-with-resolve-btn clearfix">
<reply-placeholder class="qa-discussion-reply" @onClick="$emit('showReplyForm')" />
- <resolve-discussion-button
- v-if="discussion.resolvable"
- :is-resolving="isResolving"
- :button-title="resolveButtonTitle"
- @onClick="$emit('resolve')"
- />
- <div v-if="discussion.resolvable" class="btn-group discussion-actions ml-sm-2" role="group">
- <resolve-with-issue-button v-if="resolveWithIssuePath" :url="resolveWithIssuePath" />
- <jump-to-next-discussion-button
- v-if="shouldShowJumpToNextDiscussion"
- @onClick="$emit('jumpToNextDiscussion')"
+
+ <div class="btn-group discussion-actions" role="group">
+ <resolve-discussion-button
+ v-if="discussion.resolvable"
+ :is-resolving="isResolving"
+ :button-title="resolveButtonTitle"
+ @onClick="$emit('resolve')"
+ />
+ <resolve-with-issue-button
+ v-if="discussion.resolvable && resolveWithIssuePath"
+ :url="resolveWithIssuePath"
/>
</div>
+
+ <div
+ v-if="discussion.resolvable && shouldShowJumpToNextDiscussion"
+ class="btn-group discussion-actions ml-sm-2"
+ >
+ <jump-to-next-discussion-button @onClick="$emit('jumpToNextDiscussion')" />
+ </div>
</div>
</template>
diff --git a/app/assets/javascripts/notes/components/noteable_discussion.vue b/app/assets/javascripts/notes/components/noteable_discussion.vue
index 10b15a9c38c..b8eaff32cce 100644
--- a/app/assets/javascripts/notes/components/noteable_discussion.vue
+++ b/app/assets/javascripts/notes/components/noteable_discussion.vue
@@ -126,10 +126,7 @@ export default {
return this.discussion.resolved_by_push ? __('Automatically resolved') : __('Resolved');
},
shouldShowJumpToNextDiscussion() {
- return this.showJumpToNextDiscussion(
- this.discussion.id,
- this.discussionsByDiffOrder ? 'diff' : 'discussion',
- );
+ return this.showJumpToNextDiscussion(this.discussionsByDiffOrder ? 'diff' : 'discussion');
},
shouldRenderDiffs() {
return this.discussion.diff_discussion && this.renderDiffFile;
diff --git a/app/assets/javascripts/notes/stores/getters.js b/app/assets/javascripts/notes/stores/getters.js
index d7982be3e4b..8aa8f5037b3 100644
--- a/app/assets/javascripts/notes/stores/getters.js
+++ b/app/assets/javascripts/notes/stores/getters.js
@@ -61,15 +61,13 @@ export const unresolvedDiscussionsCount = state => state.unresolvedDiscussionsCo
export const resolvableDiscussionsCount = state => state.resolvableDiscussionsCount;
export const hasUnresolvedDiscussions = state => state.hasUnresolvedDiscussions;
-export const showJumpToNextDiscussion = (state, getters) => (discussionId, mode = 'discussion') => {
+export const showJumpToNextDiscussion = (state, getters) => (mode = 'discussion') => {
const orderedDiffs =
mode !== 'discussion'
? getters.unresolvedDiscussionsIdsByDiff
: getters.unresolvedDiscussionsIdsByDate;
- const indexOf = orderedDiffs.indexOf(discussionId);
-
- return indexOf !== -1 && indexOf < orderedDiffs.length - 1;
+ return orderedDiffs.length > 1;
};
export const isDiscussionResolved = (state, getters) => discussionId =>
diff --git a/app/assets/javascripts/performance_bar/components/detailed_metric.vue b/app/assets/javascripts/performance_bar/components/detailed_metric.vue
index 8f3ba9779fb..d5f1cea8356 100644
--- a/app/assets/javascripts/performance_bar/components/detailed_metric.vue
+++ b/app/assets/javascripts/performance_bar/components/detailed_metric.vue
@@ -92,7 +92,9 @@ export default {
</template>
<template v-else>
<tr>
- <td>No {{ header.toLowerCase() }} for this request.</td>
+ <td>
+ {{ sprintf(__('No %{header} for this request.'), { header: header.toLowerCase() }) }}
+ </td>
</tr>
</template>
</table>
diff --git a/app/assets/javascripts/performance_bar/components/performance_bar_app.vue b/app/assets/javascripts/performance_bar/components/performance_bar_app.vue
index 48515cf785c..185003c306e 100644
--- a/app/assets/javascripts/performance_bar/components/performance_bar_app.vue
+++ b/app/assets/javascripts/performance_bar/components/performance_bar_app.vue
@@ -5,6 +5,7 @@ import { glEmojiTag } from '~/emoji';
import detailedMetric from './detailed_metric.vue';
import requestSelector from './request_selector.vue';
import simpleMetric from './simple_metric.vue';
+import { s__ } from '~/locale';
export default {
components: {
@@ -35,10 +36,10 @@ export default {
},
},
detailedMetrics: [
- { metric: 'pg', header: 'SQL queries', details: 'queries', keys: ['sql'] },
+ { metric: 'pg', header: s__('PerformanceBar|SQL queries'), details: 'queries', keys: ['sql'] },
{
metric: 'gitaly',
- header: 'Gitaly calls',
+ header: s__('PerformanceBar|Gitaly calls'),
details: 'details',
keys: ['feature', 'request'],
},
@@ -99,7 +100,8 @@ export default {
class="current-host"
:class="{ canary: currentRequest.details.host.canary }"
>
- <span v-html="birdEmoji"></span> {{ currentRequest.details.host.hostname }}
+ <span v-html="birdEmoji"></span>
+ {{ currentRequest.details.host.hostname }}
</span>
</div>
<detailed-metric
@@ -118,9 +120,9 @@ export default {
data-toggle="modal"
data-target="#modal-peek-line-profile"
>
- profile
+ {{ s__('PerformanceBar|profile') }}
</button>
- <a v-else :href="profileUrl"> profile </a>
+ <a v-else :href="profileUrl">{{ s__('PerformanceBar|profile') }}</a>
</div>
<simple-metric
v-for="metric in $options.simpleMetrics"
@@ -139,7 +141,7 @@ export default {
id="peek-view-trace"
class="view"
>
- <a :href="currentRequest.details.tracing.tracing_url"> trace </a>
+ <a :href="currentRequest.details.tracing.tracing_url">{{ s__('PerformanceBar|trace') }}</a>
</div>
<request-selector
v-if="currentRequest"
diff --git a/app/assets/stylesheets/pages/notes.scss b/app/assets/stylesheets/pages/notes.scss
index 824edb2869f..e880b941d67 100644
--- a/app/assets/stylesheets/pages/notes.scss
+++ b/app/assets/stylesheets/pages/notes.scss
@@ -657,6 +657,10 @@ $note-form-margin-left: 72px;
margin-left: -1px;
}
+ .btn-group > .discussion-create-issue-btn {
+ margin-left: -2px;
+ }
+
svg {
height: 15px;
}
diff --git a/app/graphql/mutations/.keep b/app/graphql/mutations/.keep
deleted file mode 100644
index e69de29bb2d..00000000000
--- a/app/graphql/mutations/.keep
+++ /dev/null
diff --git a/app/graphql/mutations/award_emojis/add.rb b/app/graphql/mutations/award_emojis/add.rb
new file mode 100644
index 00000000000..8e050dd6d29
--- /dev/null
+++ b/app/graphql/mutations/award_emojis/add.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+module Mutations
+ module AwardEmojis
+ class Add < Base
+ graphql_name 'AddAwardEmoji'
+
+ def resolve(args)
+ awardable = authorized_find!(id: args[:awardable_id])
+
+ check_object_is_awardable!(awardable)
+
+ # TODO this will be handled by AwardEmoji::AddService
+ # See https://gitlab.com/gitlab-org/gitlab-ce/issues/63372 and
+ # https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/29782
+ award = awardable.create_award_emoji(args[:name], current_user)
+
+ {
+ award_emoji: (award if award.persisted?),
+ errors: errors_on_object(award)
+ }
+ end
+ end
+ end
+end
diff --git a/app/graphql/mutations/award_emojis/base.rb b/app/graphql/mutations/award_emojis/base.rb
new file mode 100644
index 00000000000..d868db84f9d
--- /dev/null
+++ b/app/graphql/mutations/award_emojis/base.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+module Mutations
+ module AwardEmojis
+ class Base < BaseMutation
+ include Gitlab::Graphql::Authorize::AuthorizeResource
+
+ authorize :award_emoji
+
+ argument :awardable_id,
+ GraphQL::ID_TYPE,
+ required: true,
+ description: 'The global id of the awardable resource'
+
+ argument :name,
+ GraphQL::STRING_TYPE,
+ required: true,
+ description: copy_field_description(Types::AwardEmojis::AwardEmojiType, :name)
+
+ field :award_emoji,
+ Types::AwardEmojis::AwardEmojiType,
+ null: true,
+ description: 'The award emoji after mutation'
+
+ private
+
+ def find_object(id:)
+ GitlabSchema.object_from_id(id)
+ end
+
+ # Called by mutations methods after performing an authorization check
+ # of an awardable object.
+ def check_object_is_awardable!(object)
+ unless object.is_a?(Awardable) && object.emoji_awardable?
+ raise Gitlab::Graphql::Errors::ResourceNotAvailable,
+ 'Cannot award emoji to this resource'
+ end
+ end
+ end
+ end
+end
diff --git a/app/graphql/mutations/award_emojis/remove.rb b/app/graphql/mutations/award_emojis/remove.rb
new file mode 100644
index 00000000000..3ba85e445b8
--- /dev/null
+++ b/app/graphql/mutations/award_emojis/remove.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Mutations
+ module AwardEmojis
+ class Remove < Base
+ graphql_name 'RemoveAwardEmoji'
+
+ def resolve(args)
+ awardable = authorized_find!(id: args[:awardable_id])
+
+ check_object_is_awardable!(awardable)
+
+ # TODO this check can be removed once AwardEmoji services are available.
+ # See https://gitlab.com/gitlab-org/gitlab-ce/issues/63372 and
+ # https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/29782
+ unless awardable.awarded_emoji?(args[:name], current_user)
+ raise Gitlab::Graphql::Errors::ResourceNotAvailable,
+ 'You have not awarded emoji of type name to the awardable'
+ end
+
+ # TODO this will be handled by AwardEmoji::DestroyService
+ # See https://gitlab.com/gitlab-org/gitlab-ce/issues/63372 and
+ # https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/29782
+ awardable.remove_award_emoji(args[:name], current_user)
+
+ {
+ # Mutation response is always a `nil` award_emoji
+ errors: []
+ }
+ end
+ end
+ end
+end
diff --git a/app/graphql/mutations/award_emojis/toggle.rb b/app/graphql/mutations/award_emojis/toggle.rb
new file mode 100644
index 00000000000..c03902e8035
--- /dev/null
+++ b/app/graphql/mutations/award_emojis/toggle.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+module Mutations
+ module AwardEmojis
+ class Toggle < Base
+ graphql_name 'ToggleAwardEmoji'
+
+ field :toggledOn,
+ GraphQL::BOOLEAN_TYPE,
+ null: false,
+ description: 'True when the emoji was awarded, false when it was removed'
+
+ def resolve(args)
+ awardable = authorized_find!(id: args[:awardable_id])
+
+ check_object_is_awardable!(awardable)
+
+ # TODO this will be handled by AwardEmoji::ToggleService
+ # See https://gitlab.com/gitlab-org/gitlab-ce/issues/63372 and
+ # https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/29782
+ award = awardable.toggle_award_emoji(args[:name], current_user)
+
+ # Destroy returns a collection :(
+ award = award.first if award.is_a?(Array)
+
+ errors = errors_on_object(award)
+
+ toggled_on = awardable.awarded_emoji?(args[:name], current_user)
+
+ {
+ # For consistency with the AwardEmojis::Remove mutation, only return
+ # the AwardEmoji if it was created and not destroyed
+ award_emoji: (award if toggled_on),
+ errors: errors,
+ toggled_on: toggled_on
+ }
+ end
+ end
+ end
+end
diff --git a/app/graphql/mutations/base_mutation.rb b/app/graphql/mutations/base_mutation.rb
index eb03dfe1624..08d2a1f18a3 100644
--- a/app/graphql/mutations/base_mutation.rb
+++ b/app/graphql/mutations/base_mutation.rb
@@ -2,6 +2,8 @@
module Mutations
class BaseMutation < GraphQL::Schema::RelayClassicMutation
+ prepend Gitlab::Graphql::CopyFieldDescription
+
field :errors, [GraphQL::STRING_TYPE],
null: false,
description: "Reasons why the mutation failed."
@@ -9,5 +11,10 @@ module Mutations
def current_user
context[:current_user]
end
+
+ # Returns Array of errors on an ActiveRecord object
+ def errors_on_object(record)
+ record.errors.full_messages
+ end
end
end
diff --git a/app/graphql/types/award_emojis/award_emoji_type.rb b/app/graphql/types/award_emojis/award_emoji_type.rb
new file mode 100644
index 00000000000..8daf699a112
--- /dev/null
+++ b/app/graphql/types/award_emojis/award_emoji_type.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+module Types
+ module AwardEmojis
+ class AwardEmojiType < BaseObject
+ graphql_name 'AwardEmoji'
+
+ authorize :read_emoji
+
+ present_using AwardEmojiPresenter
+
+ field :name,
+ GraphQL::STRING_TYPE,
+ null: false,
+ description: 'The emoji name'
+
+ field :description,
+ GraphQL::STRING_TYPE,
+ null: false,
+ description: 'The emoji description'
+
+ field :unicode,
+ GraphQL::STRING_TYPE,
+ null: false,
+ description: 'The emoji in unicode'
+
+ field :emoji,
+ GraphQL::STRING_TYPE,
+ null: false,
+ description: 'The emoji as an icon'
+
+ field :unicode_version,
+ GraphQL::STRING_TYPE,
+ null: false,
+ description: 'The unicode version for this emoji'
+
+ field :user,
+ Types::UserType,
+ null: false,
+ description: 'The user who awarded the emoji',
+ resolve: -> (award_emoji, _args, _context) {
+ Gitlab::Graphql::Loaders::BatchModelLoader.new(User, award_emoji.user_id).find
+ }
+ end
+ end
+end
diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb
index 2b4ef299296..6ef1d816b7c 100644
--- a/app/graphql/types/mutation_type.rb
+++ b/app/graphql/types/mutation_type.rb
@@ -6,6 +6,9 @@ module Types
graphql_name "Mutation"
+ mount_mutation Mutations::AwardEmojis::Add
+ mount_mutation Mutations::AwardEmojis::Remove
+ mount_mutation Mutations::AwardEmojis::Toggle
mount_mutation Mutations::MergeRequests::SetWip
end
end
diff --git a/app/models/board.rb b/app/models/board.rb
index e08db764f65..50b6ca9b70f 100644
--- a/app/models/board.rb
+++ b/app/models/board.rb
@@ -4,11 +4,14 @@ class Board < ApplicationRecord
belongs_to :group
belongs_to :project
- has_many :lists, -> { order(:list_type, :position) }, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
+ has_many :lists, -> { ordered }, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
+ has_many :destroyable_lists, -> { destroyable.ordered }, class_name: "List"
validates :project, presence: true, if: :project_needed?
validates :group, presence: true, unless: :project
+ scope :with_associations, -> { preload(:destroyable_lists) }
+
def project_needed?
!group
end
diff --git a/app/models/list.rb b/app/models/list.rb
index 17b1a8510cf..d28a9bda82d 100644
--- a/app/models/list.rb
+++ b/app/models/list.rb
@@ -16,6 +16,7 @@ class List < ApplicationRecord
scope :destroyable, -> { where(list_type: list_types.slice(*destroyable_types).values) }
scope :movable, -> { where(list_type: list_types.slice(*movable_types).values) }
scope :preload_associations, -> { preload(:board, :label) }
+ scope :ordered, -> { order(:list_type, :position) }
class << self
def destroyable_types
diff --git a/app/models/snippet.rb b/app/models/snippet.rb
index f4fdac2558c..00931457344 100644
--- a/app/models/snippet.rb
+++ b/app/models/snippet.rb
@@ -194,6 +194,10 @@ class Snippet < ApplicationRecord
'snippet'
end
+ def to_ability_name
+ model_name.singular
+ end
+
class << self
# Searches for snippets with a matching title or file name.
#
diff --git a/app/policies/award_emoji_policy.rb b/app/policies/award_emoji_policy.rb
new file mode 100644
index 00000000000..21e382e24b3
--- /dev/null
+++ b/app/policies/award_emoji_policy.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class AwardEmojiPolicy < BasePolicy
+ delegate { @subject.awardable if DeclarativePolicy.has_policy?(@subject.awardable) }
+
+ condition(:can_read_awardable) do
+ can?(:"read_#{@subject.awardable.to_ability_name}")
+ end
+
+ rule { can_read_awardable }.enable :read_emoji
+end
diff --git a/app/presenters/award_emoji_presenter.rb b/app/presenters/award_emoji_presenter.rb
new file mode 100644
index 00000000000..98713855d35
--- /dev/null
+++ b/app/presenters/award_emoji_presenter.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class AwardEmojiPresenter < Gitlab::View::Presenter::Delegated
+ presents :award_emoji
+
+ def description
+ as_emoji['description']
+ end
+
+ def unicode
+ as_emoji['unicode']
+ end
+
+ def emoji
+ as_emoji['moji']
+ end
+
+ def unicode_version
+ Gitlab::Emoji.emoji_unicode_version(award_emoji.name)
+ end
+
+ private
+
+ def as_emoji
+ @emoji ||= Gitlab::Emoji.emojis[award_emoji.name] || {}
+ end
+end
diff --git a/app/views/projects/_merge_request_settings_description_text.html.haml b/app/views/projects/_merge_request_settings_description_text.html.haml
new file mode 100644
index 00000000000..42964c900b3
--- /dev/null
+++ b/app/views/projects/_merge_request_settings_description_text.html.haml
@@ -0,0 +1 @@
+%p= s_('ProjectSettings|Choose your merge method, merge options, and merge checks.')
diff --git a/app/views/projects/edit.html.haml b/app/views/projects/edit.html.haml
index c15b84d0aac..29b7c45201c 100644
--- a/app/views/projects/edit.html.haml
+++ b/app/views/projects/edit.html.haml
@@ -27,7 +27,7 @@
.settings-header
%h4.settings-title.js-settings-toggle.js-settings-toggle-trigger-only= _('Merge requests')
%button.btn.btn-default.js-settings-toggle{ type: 'button' }= expanded ? _('Collapse') : _('Expand')
- %p= _('Choose your merge method, options, checks, and set up a default merge request description template.')
+ = render_if_exists 'projects/merge_request_settings_description_text'
.settings-content
= render_if_exists 'shared/promotions/promote_mr_features'
diff --git a/app/views/projects/environments/show.html.haml b/app/views/projects/environments/show.html.haml
index d59b2d4fb01..c13a47b0b09 100644
--- a/app/views/projects/environments/show.html.haml
+++ b/app/views/projects/environments/show.html.haml
@@ -31,21 +31,19 @@
= button_to stop_project_environment_path(@project, @environment), class: 'btn btn-danger has-tooltip', method: :post do
= s_('Environments|Stop environment')
- .row.top-area.adjust
- .col-md-7
- %h3.page-title= @environment.name
- .col-md-5
- .nav-controls
- = render 'projects/environments/terminal_button', environment: @environment
- = render 'projects/environments/external_url', environment: @environment
- = render 'projects/environments/metrics_button', environment: @environment
- - if can?(current_user, :update_environment, @environment)
- = link_to _('Edit'), edit_project_environment_path(@project, @environment), class: 'btn'
- - if can?(current_user, :stop_environment, @environment)
- = button_tag class: 'btn btn-danger', type: 'button', data: { toggle: 'modal',
- target: '#stop-environment-modal' } do
- = sprite_icon('stop')
- = s_('Environments|Stop')
+ .top-area
+ %h3.page-title= @environment.name
+ .nav-controls.ml-auto.my-2
+ = render 'projects/environments/terminal_button', environment: @environment
+ = render 'projects/environments/external_url', environment: @environment
+ = render 'projects/environments/metrics_button', environment: @environment
+ - if can?(current_user, :update_environment, @environment)
+ = link_to _('Edit'), edit_project_environment_path(@project, @environment), class: 'btn'
+ - if can?(current_user, :stop_environment, @environment)
+ = button_tag class: 'btn btn-danger', type: 'button', data: { toggle: 'modal',
+ target: '#stop-environment-modal' } do
+ = sprite_icon('stop')
+ = s_('Environments|Stop')
.environments-container
- if @deployments.blank?
diff --git a/app/views/projects/tree/_tree_header.html.haml b/app/views/projects/tree/_tree_header.html.haml
index ea6349f2f57..1d0bc588c9c 100644
--- a/app/views/projects/tree/_tree_header.html.haml
+++ b/app/views/projects/tree/_tree_header.html.haml
@@ -76,6 +76,7 @@
#{ _('New tag') }
.tree-controls
+ = render_if_exists 'projects/tree/lock_link'
= link_to s_('Commits|History'), project_commits_path(@project, @id), class: 'btn'
= render 'projects/find_file_link'
diff --git a/changelogs/unreleased/58689-regroup-jump-button-in-discussion.yml b/changelogs/unreleased/58689-regroup-jump-button-in-discussion.yml
new file mode 100644
index 00000000000..bf6f314f0ce
--- /dev/null
+++ b/changelogs/unreleased/58689-regroup-jump-button-in-discussion.yml
@@ -0,0 +1,6 @@
+---
+title: Improve discussion reply buttons layout and how jump to next discussion button
+ appears
+merge_request: 29779
+author:
+type: changed
diff --git a/changelogs/unreleased/62826-graphql-emoji-mutations.yml b/changelogs/unreleased/62826-graphql-emoji-mutations.yml
new file mode 100644
index 00000000000..0c0aaedf844
--- /dev/null
+++ b/changelogs/unreleased/62826-graphql-emoji-mutations.yml
@@ -0,0 +1,5 @@
+---
+title: GraphQL mutations for add, remove and toggle emoji
+merge_request: 29919
+author:
+type: added
diff --git a/changelogs/unreleased/62968-environment-details-header-border-misaligned.yml b/changelogs/unreleased/62968-environment-details-header-border-misaligned.yml
new file mode 100644
index 00000000000..749fe6a9cb0
--- /dev/null
+++ b/changelogs/unreleased/62968-environment-details-header-border-misaligned.yml
@@ -0,0 +1,5 @@
+---
+title: Resolve Environment details header border misaligned
+merge_request: 30011
+author:
+type: fixed
diff --git a/changelogs/unreleased/ce-11098-update-merge-request-settings-description-text.yml b/changelogs/unreleased/ce-11098-update-merge-request-settings-description-text.yml
new file mode 100644
index 00000000000..9f6a2040095
--- /dev/null
+++ b/changelogs/unreleased/ce-11098-update-merge-request-settings-description-text.yml
@@ -0,0 +1,5 @@
+---
+title: Update merge requests section description text on project settings page
+merge_request: 27838
+author:
+type: changed \ No newline at end of file
diff --git a/changelogs/unreleased/support-jsonb-default-value.yml b/changelogs/unreleased/support-jsonb-default-value.yml
new file mode 100644
index 00000000000..d46156276f9
--- /dev/null
+++ b/changelogs/unreleased/support-jsonb-default-value.yml
@@ -0,0 +1,5 @@
+---
+title: Support jsonb default in add_column_with_default migration helper
+merge_request: 29871
+author:
+type: other
diff --git a/doc/development/documentation/site_architecture/index.md b/doc/development/documentation/site_architecture/index.md
index ee3a9caf9a0..6dd12b5efa7 100644
--- a/doc/development/documentation/site_architecture/index.md
+++ b/doc/development/documentation/site_architecture/index.md
@@ -11,8 +11,40 @@ and deploy it to <https://docs.gitlab.com>.
While the source of the documentation content is stored in GitLab's respective product
repositories, the source that is used to build the documentation site _from that content_
-is located at <https://gitlab.com/gitlab-com/gitlab-docs>. See the README there for
-detailed information.
+is located at <https://gitlab.com/gitlab-com/gitlab-docs>.
+
+The following diagram illustrates the relationship between the repositories
+from where content is sourced, the `gitlab-docs` project, and the published output.
+
+```mermaid
+ graph LR
+ A[gitlab-ce/doc]
+ B[gitlab-ee/doc]
+ C[gitlab-runner/docs]
+ D[omnibus-gitlab/doc]
+ E[charts/doc]
+ F[gitlab-docs]
+ A --> F
+ B --> F
+ C --> F
+ D --> F
+ E --> F
+ F -- Build pipeline --> G
+ G[docs.gitlab.com]
+ H[/ce/]
+ I[/ee/]
+ J[/runner/]
+ K[/omnibus/]
+ L[/charts/]
+ G --> H
+ G --> I
+ G --> J
+ G --> K
+ G --> L
+```
+
+See the [README there](https://gitlab.com/gitlab-com/gitlab-docs/blob/master/README.md)
+for detailed information.
## Assets
@@ -22,9 +54,9 @@ the GitLab Documentation website.
### Libraries
-- [Bootstrap 3.3 components](https://getbootstrap.com/docs/3.3/components/)
-- [Bootstrap 3.3 JS](https://getbootstrap.com/docs/3.3/javascript/)
-- [jQuery](https://jquery.com/) 3.2.1
+- [Bootstrap 4.3.1 components](https://getbootstrap.com/docs/4.3/components/)
+- [Bootstrap 4.3.1 JS](https://getbootstrap.com/docs/4.3/getting-started/javascript/)
+- [jQuery](https://jquery.com/) 3.3.1
- [Clipboard JS](https://clipboardjs.com/)
- [Font Awesome 4.7.0](https://fontawesome.com/v4.7.0/icons/)
diff --git a/doc/user/project/clusters/index.md b/doc/user/project/clusters/index.md
index 97d2dfc0f7e..c6ee168bad0 100644
--- a/doc/user/project/clusters/index.md
+++ b/doc/user/project/clusters/index.md
@@ -533,22 +533,20 @@ This job failed because the necessary resources were not successfully created.
To find the cause of this error when creating a namespace and service account, check the [logs](../../../administration/logs.md#kuberneteslog).
-NOTE: **NOTE:**
-As of GitLab 12.1 we require [`cluster-admin`](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#user-facing-roles)
-tokens for all project level clusters unless you unselect the
-[GitLab-managed cluster](#gitlab-managed-clusters) option. If you
-want to manage namespaces and service accounts yourself and don't
-want to provide a `cluster-admin` token to GitLab you must unselect this
-option or you will get the above error.
-
-Common reasons for failure include:
+Reasons for failure include:
-- The token you gave GitLab did not have [`cluster-admin`](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#user-facing-roles)
+- The token you gave GitLab does not have [`cluster-admin`](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#user-facing-roles)
privileges required by GitLab.
- Missing `KUBECONFIG` or `KUBE_TOKEN` variables. To be passed to your job, they must have a matching
[`environment:name`](../../../ci/environments.md#defining-environments). If your job has no
`environment:name` set, it will not be passed the Kubernetes credentials.
+NOTE: **NOTE:**
+Project-level clusters upgraded from GitLab 12.0 or older may be configured
+in a way that causes this error. Ensure you deselect the
+[GitLab-managed cluster](#gitlab-managed-clusters) option if you want to manage
+namespaces and service accounts yourself.
+
## Monitoring your Kubernetes cluster **[ULTIMATE]**
> [Introduced](https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/4701) in [GitLab Ultimate][ee] 10.6.
diff --git a/lib/api/boards.rb b/lib/api/boards.rb
index b7c77730afb..4e31f74f18a 100644
--- a/lib/api/boards.rb
+++ b/lib/api/boards.rb
@@ -27,7 +27,7 @@ module API
end
get '/' do
authorize!(:read_board, user_project)
- present paginate(board_parent.boards), with: Entities::Board
+ present paginate(board_parent.boards.with_associations), with: Entities::Board
end
desc 'Find a project board' do
diff --git a/lib/api/boards_responses.rb b/lib/api/boards_responses.rb
index 86d9b24802f..68497a08fb8 100644
--- a/lib/api/boards_responses.rb
+++ b/lib/api/boards_responses.rb
@@ -11,7 +11,7 @@ module API
end
def board_lists
- board.lists.destroyable
+ board.destroyable_lists
end
def create_list
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index ead01dc53f7..d783591c238 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -1101,7 +1101,7 @@ module API
expose :project, using: Entities::BasicProjectDetails
expose :lists, using: Entities::List do |board|
- board.lists.destroyable
+ board.destroyable_lists
end
end
diff --git a/lib/api/group_boards.rb b/lib/api/group_boards.rb
index 9a20ee8c8b9..feb2254963e 100644
--- a/lib/api/group_boards.rb
+++ b/lib/api/group_boards.rb
@@ -37,7 +37,7 @@ module API
use :pagination
end
get '/' do
- present paginate(board_parent.boards), with: Entities::Board
+ present paginate(board_parent.boards.with_associations), with: Entities::Board
end
end
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb
index 0b12e862ded..e2cbf91f281 100644
--- a/lib/gitlab/database/migration_helpers.rb
+++ b/lib/gitlab/database/migration_helpers.rb
@@ -434,7 +434,8 @@ module Gitlab
end
begin
- update_column_in_batches(table, column, default, &block)
+ default_after_type_cast = connection.type_cast(default, column_for(table, column))
+ update_column_in_batches(table, column, default_after_type_cast, &block)
change_column_null(table, column, false) unless allow_null
# We want to rescue _all_ exceptions here, even those that don't inherit
diff --git a/lib/gitlab/graphql/copy_field_description.rb b/lib/gitlab/graphql/copy_field_description.rb
new file mode 100644
index 00000000000..edd73083ff2
--- /dev/null
+++ b/lib/gitlab/graphql/copy_field_description.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Graphql
+ module CopyFieldDescription
+ extend ActiveSupport::Concern
+
+ class_methods do
+ # Returns the `description` for property of field `field_name` on type.
+ # This can be used to ensure, for example, that mutation argument descriptions
+ # are always identical to the corresponding query field descriptions.
+ #
+ # E.g.:
+ # argument :name, GraphQL::STRING_TYPE, description: copy_field_description(Types::UserType, :name)
+ def copy_field_description(type, field_name)
+ type.fields[field_name.to_s.camelize(:lower)].description
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/graphql/errors.rb b/lib/gitlab/graphql/errors.rb
index fe74549e322..40b90310e8b 100644
--- a/lib/gitlab/graphql/errors.rb
+++ b/lib/gitlab/graphql/errors.rb
@@ -6,6 +6,7 @@ module Gitlab
BaseError = Class.new(GraphQL::ExecutionError)
ArgumentError = Class.new(BaseError)
ResourceNotAvailable = Class.new(BaseError)
+ MutationError = Class.new(BaseError)
end
end
end
diff --git a/locale/gitlab.pot b/locale/gitlab.pot
index 9ea368816f9..b8ce2c20563 100644
--- a/locale/gitlab.pot
+++ b/locale/gitlab.pot
@@ -1991,9 +1991,6 @@ msgstr ""
msgid "Choose visibility level, enable/disable project features (issues, repository, wiki, snippets) and set permissions."
msgstr ""
-msgid "Choose your merge method, options, checks, and set up a default merge request description template."
-msgstr ""
-
msgid "CiStatusLabel|canceled"
msgstr ""
@@ -6652,6 +6649,9 @@ msgstr ""
msgid "No"
msgstr ""
+msgid "No %{header} for this request."
+msgstr ""
+
msgid "No %{providerTitle} repositories available to import"
msgstr ""
@@ -7137,6 +7137,18 @@ msgstr ""
msgid "Performance optimization"
msgstr ""
+msgid "PerformanceBar|Gitaly calls"
+msgstr ""
+
+msgid "PerformanceBar|SQL queries"
+msgstr ""
+
+msgid "PerformanceBar|profile"
+msgstr ""
+
+msgid "PerformanceBar|trace"
+msgstr ""
+
msgid "Permissions"
msgstr ""
@@ -8058,6 +8070,9 @@ msgstr ""
msgid "ProjectSettings|Badges"
msgstr ""
+msgid "ProjectSettings|Choose your merge method, merge options, and merge checks."
+msgstr ""
+
msgid "ProjectSettings|Customize your project badges."
msgstr ""
diff --git a/spec/factories/award_emoji.rb b/spec/factories/award_emoji.rb
index d37e2bf511e..43753fa650c 100644
--- a/spec/factories/award_emoji.rb
+++ b/spec/factories/award_emoji.rb
@@ -5,7 +5,7 @@ FactoryBot.define do
awardable factory: :issue
after(:create) do |award, evaluator|
- award.awardable.project.add_guest(evaluator.user)
+ award.awardable.project&.add_guest(evaluator.user)
end
trait :upvote
diff --git a/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb b/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb
index 08fa4a98feb..260eec7a9ed 100644
--- a/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb
+++ b/spec/features/merge_request/user_resolves_diff_notes_and_discussions_resolve_spec.rb
@@ -362,14 +362,14 @@ describe 'Merge request > User resolves diff notes and discussions', :js do
end
end
- it 'shows jump to next discussion button except on last discussion' do
+ it 'shows jump to next discussion button on all discussions' do
wait_for_requests
all_discussion_replies = page.all('.discussion-reply-holder')
expect(all_discussion_replies.count).to eq(2)
expect(all_discussion_replies.first.all('.discussion-next-btn').count).to eq(1)
- expect(all_discussion_replies.last.all('.discussion-next-btn').count).to eq(0)
+ expect(all_discussion_replies.last.all('.discussion-next-btn').count).to eq(1)
end
it 'displays next discussion even if hidden' do
diff --git a/spec/graphql/types/award_emojis/award_emoji_type_spec.rb b/spec/graphql/types/award_emojis/award_emoji_type_spec.rb
new file mode 100644
index 00000000000..5663a3d7195
--- /dev/null
+++ b/spec/graphql/types/award_emojis/award_emoji_type_spec.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe GitlabSchema.types['AwardEmoji'] do
+ it { expect(described_class.graphql_name).to eq('AwardEmoji') }
+
+ it { is_expected.to require_graphql_authorizations(:read_emoji) }
+
+ it { expect(described_class).to have_graphql_fields(:description, :unicode_version, :emoji, :name, :unicode, :user) }
+end
diff --git a/spec/javascripts/notes/stores/getters_spec.js b/spec/javascripts/notes/stores/getters_spec.js
index 8f3c493dd4c..c3ed079e33b 100644
--- a/spec/javascripts/notes/stores/getters_spec.js
+++ b/spec/javascripts/notes/stores/getters_spec.js
@@ -32,6 +32,26 @@ describe('Getters Notes Store', () => {
};
});
+ describe('showJumpToNextDiscussion', () => {
+ it('should return true if there are 2 or more unresolved discussions', () => {
+ const localGetters = {
+ unresolvedDiscussionsIdsByDate: ['123', '456'],
+ allResolvableDiscussions: [],
+ };
+
+ expect(getters.showJumpToNextDiscussion(state, localGetters)()).toBe(true);
+ });
+
+ it('should return false if there are 1 or less unresolved discussions', () => {
+ const localGetters = {
+ unresolvedDiscussionsIdsByDate: ['123'],
+ allResolvableDiscussions: [],
+ };
+
+ expect(getters.showJumpToNextDiscussion(state, localGetters)()).toBe(false);
+ });
+ });
+
describe('discussions', () => {
it('should return all discussions in the store', () => {
expect(getters.discussions(state)).toEqual([individualNote]);
diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb
index 3cf3d032bf4..7409572288c 100644
--- a/spec/lib/gitlab/database/migration_helpers_spec.rb
+++ b/spec/lib/gitlab/database/migration_helpers_spec.rb
@@ -583,6 +583,24 @@ describe Gitlab::Database::MigrationHelpers do
model.add_column_with_default(:projects, :foo, :integer, default: 10, limit: 8)
end
end
+
+ it 'adds a column with an array default value for a jsonb type' do
+ create(:project)
+ allow(model).to receive(:transaction_open?).and_return(false)
+ allow(model).to receive(:transaction).and_yield
+ expect(model).to receive(:update_column_in_batches).with(:projects, :foo, '[{"foo":"json"}]').and_call_original
+
+ model.add_column_with_default(:projects, :foo, :jsonb, default: [{ foo: "json" }])
+ end
+
+ it 'adds a column with an object default value for a jsonb type' do
+ create(:project)
+ allow(model).to receive(:transaction_open?).and_return(false)
+ allow(model).to receive(:transaction).and_yield
+ expect(model).to receive(:update_column_in_batches).with(:projects, :foo, '{"foo":"json"}').and_call_original
+
+ model.add_column_with_default(:projects, :foo, :jsonb, default: { foo: "json" })
+ end
end
context 'inside a transaction' do
diff --git a/spec/lib/gitlab/graphql/authorize/authorize_resource_spec.rb b/spec/lib/gitlab/graphql/authorize/authorize_resource_spec.rb
index 20842f55014..50138d272c4 100644
--- a/spec/lib/gitlab/graphql/authorize/authorize_resource_spec.rb
+++ b/spec/lib/gitlab/graphql/authorize/authorize_resource_spec.rb
@@ -67,7 +67,7 @@ describe Gitlab::Graphql::Authorize::AuthorizeResource do
end
describe '#authorize!' do
- it 'does not raise an error' do
+ it 'raises an error' do
expect { loading_resource.authorize!(project) }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
diff --git a/spec/lib/gitlab/graphql/copy_field_description_spec.rb b/spec/lib/gitlab/graphql/copy_field_description_spec.rb
new file mode 100644
index 00000000000..e7462c5b954
--- /dev/null
+++ b/spec/lib/gitlab/graphql/copy_field_description_spec.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::Graphql::CopyFieldDescription do
+ subject { Class.new.include(described_class) }
+
+ describe '.copy_field_description' do
+ let(:type) do
+ Class.new(Types::BaseObject) do
+ graphql_name "TestType"
+
+ field :field_name, GraphQL::STRING_TYPE, null: true, description: 'Foo'
+ end
+ end
+
+ it 'returns the correct description' do
+ expect(subject.copy_field_description(type, :field_name)).to eq('Foo')
+ end
+ end
+end
diff --git a/spec/policies/award_emoji_policy_spec.rb b/spec/policies/award_emoji_policy_spec.rb
new file mode 100644
index 00000000000..2e3693c58d7
--- /dev/null
+++ b/spec/policies/award_emoji_policy_spec.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe AwardEmojiPolicy do
+ let(:user) { create(:user) }
+ let(:award_emoji) { create(:award_emoji, awardable: awardable) }
+
+ subject { described_class.new(user, award_emoji) }
+
+ shared_examples 'when the user can read the awardable' do
+ context do
+ let(:project) { create(:project, :public) }
+
+ it { expect_allowed(:read_emoji) }
+ end
+ end
+
+ shared_examples 'when the user cannot read the awardable' do
+ context do
+ let(:project) { create(:project, :private) }
+
+ it { expect_disallowed(:read_emoji) }
+ end
+ end
+
+ context 'when the awardable is an issue' do
+ let(:awardable) { create(:issue, project: project) }
+
+ include_examples 'when the user can read the awardable'
+ include_examples 'when the user cannot read the awardable'
+ end
+
+ context 'when the awardable is a merge request' do
+ let(:awardable) { create(:merge_request, source_project: project) }
+
+ include_examples 'when the user can read the awardable'
+ include_examples 'when the user cannot read the awardable'
+ end
+
+ context 'when the awardable is a note' do
+ let(:awardable) { create(:note_on_merge_request, project: project) }
+
+ include_examples 'when the user can read the awardable'
+ include_examples 'when the user cannot read the awardable'
+ end
+
+ context 'when the awardable is a snippet' do
+ let(:awardable) { create(:project_snippet, :public, project: project) }
+
+ include_examples 'when the user can read the awardable'
+ include_examples 'when the user cannot read the awardable'
+ end
+end
diff --git a/spec/presenters/award_emoji_presenter_spec.rb b/spec/presenters/award_emoji_presenter_spec.rb
new file mode 100644
index 00000000000..e2ada2a3c93
--- /dev/null
+++ b/spec/presenters/award_emoji_presenter_spec.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe AwardEmojiPresenter do
+ let(:emoji_name) { 'thumbsup' }
+ let(:award_emoji) { build(:award_emoji, name: emoji_name) }
+ let(:presenter) { described_class.new(award_emoji) }
+
+ describe '#description' do
+ it { expect(presenter.description).to eq Gitlab::Emoji.emojis[emoji_name]['description'] }
+ end
+
+ describe '#unicode' do
+ it { expect(presenter.unicode).to eq Gitlab::Emoji.emojis[emoji_name]['unicode'] }
+ end
+
+ describe '#unicode_version' do
+ it { expect(presenter.unicode_version).to eq Gitlab::Emoji.emoji_unicode_version(emoji_name) }
+ end
+
+ describe '#emoji' do
+ it { expect(presenter.emoji).to eq Gitlab::Emoji.emojis[emoji_name]['moji'] }
+ end
+
+ describe 'when presenting an award emoji with an invalid name' do
+ let(:emoji_name) { 'invalid-name' }
+
+ it 'returns nil for all properties' do
+ expect(presenter.description).to be_nil
+ expect(presenter.emoji).to be_nil
+ expect(presenter.unicode).to be_nil
+ expect(presenter.unicode_version).to be_nil
+ end
+ end
+end
diff --git a/spec/requests/api/graphql/mutations/award_emojis/add_spec.rb b/spec/requests/api/graphql/mutations/award_emojis/add_spec.rb
new file mode 100644
index 00000000000..3982125a38a
--- /dev/null
+++ b/spec/requests/api/graphql/mutations/award_emojis/add_spec.rb
@@ -0,0 +1,100 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'Adding an AwardEmoji' do
+ include GraphqlHelpers
+
+ let(:current_user) { create(:user) }
+ let(:awardable) { create(:note) }
+ let(:project) { awardable.project }
+ let(:emoji_name) { 'thumbsup' }
+ let(:mutation) do
+ variables = {
+ awardable_id: GitlabSchema.id_from_object(awardable).to_s,
+ name: emoji_name
+ }
+
+ graphql_mutation(:add_award_emoji, variables)
+ end
+
+ def mutation_response
+ graphql_mutation_response(:add_award_emoji)
+ end
+
+ shared_examples 'a mutation that does not create an AwardEmoji' do
+ it do
+ expect do
+ post_graphql_mutation(mutation, current_user: current_user)
+ end.not_to change { AwardEmoji.count }
+ end
+ end
+
+ context 'when the user does not have permission' do
+ it_behaves_like 'a mutation that does not create an AwardEmoji'
+
+ it_behaves_like 'a mutation that returns top-level errors',
+ errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action']
+ end
+
+ context 'when the user has permission' do
+ before do
+ project.add_developer(current_user)
+ end
+
+ context 'when the given awardable is not an Awardable' do
+ let(:awardable) { create(:label) }
+
+ it_behaves_like 'a mutation that does not create an AwardEmoji'
+
+ it_behaves_like 'a mutation that returns top-level errors',
+ errors: ['Cannot award emoji to this resource']
+ end
+
+ context 'when the given awardable is an Awardable but still cannot be awarded an emoji' do
+ let(:awardable) { create(:system_note) }
+
+ it_behaves_like 'a mutation that does not create an AwardEmoji'
+
+ it_behaves_like 'a mutation that returns top-level errors',
+ errors: ['Cannot award emoji to this resource']
+ end
+
+ context 'when the given awardable an Awardable' do
+ it 'creates an emoji' do
+ expect do
+ post_graphql_mutation(mutation, current_user: current_user)
+ end.to change { AwardEmoji.count }.by(1)
+ end
+
+ it 'returns the emoji' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(mutation_response['awardEmoji']['name']).to eq(emoji_name)
+ end
+
+ context 'when there were active record validation errors' do
+ before do
+ expect_next_instance_of(AwardEmoji) do |award|
+ expect(award).to receive(:valid?).at_least(:once).and_return(false)
+ expect(award).to receive_message_chain(
+ :errors,
+ :full_messages
+ ).and_return(['Error 1', 'Error 2'])
+ end
+ end
+
+ it_behaves_like 'a mutation that does not create an AwardEmoji'
+
+ it_behaves_like 'a mutation that returns errors in the response', errors: ['Error 1', 'Error 2']
+
+ it 'returns an empty awardEmoji' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(mutation_response).to have_key('awardEmoji')
+ expect(mutation_response['awardEmoji']).to be_nil
+ end
+ end
+ end
+ end
+end
diff --git a/spec/requests/api/graphql/mutations/award_emojis/remove_spec.rb b/spec/requests/api/graphql/mutations/award_emojis/remove_spec.rb
new file mode 100644
index 00000000000..c78f0c7ca27
--- /dev/null
+++ b/spec/requests/api/graphql/mutations/award_emojis/remove_spec.rb
@@ -0,0 +1,80 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'Removing an AwardEmoji' do
+ include GraphqlHelpers
+
+ let(:current_user) { create(:user) }
+ let(:awardable) { create(:note) }
+ let(:project) { awardable.project }
+ let(:emoji_name) { 'thumbsup' }
+ let(:input) { { awardable_id: GitlabSchema.id_from_object(awardable).to_s, name: emoji_name } }
+
+ let(:mutation) do
+ graphql_mutation(:remove_award_emoji, input)
+ end
+
+ def mutation_response
+ graphql_mutation_response(:remove_award_emoji)
+ end
+
+ def create_award_emoji(user)
+ create(:award_emoji, name: emoji_name, awardable: awardable, user: user )
+ end
+
+ shared_examples 'a mutation that does not destroy an AwardEmoji' do
+ it do
+ expect do
+ post_graphql_mutation(mutation, current_user: current_user)
+ end.not_to change { AwardEmoji.count }
+ end
+ end
+
+ shared_examples 'a mutation that does not authorize the user' do
+ it_behaves_like 'a mutation that does not destroy an AwardEmoji'
+
+ it_behaves_like 'a mutation that returns top-level errors',
+ errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action']
+ end
+
+ context 'when the current_user does not own the award emoji' do
+ let!(:award_emoji) { create_award_emoji(create(:user)) }
+
+ it_behaves_like 'a mutation that does not authorize the user'
+ end
+
+ context 'when the current_user owns the award emoji' do
+ let!(:award_emoji) { create_award_emoji(current_user) }
+
+ context 'when the given awardable is not an Awardable' do
+ let(:awardable) { create(:label) }
+
+ it_behaves_like 'a mutation that does not destroy an AwardEmoji'
+
+ it_behaves_like 'a mutation that returns top-level errors',
+ errors: ['Cannot award emoji to this resource']
+ end
+
+ context 'when the given awardable is an Awardable' do
+ it 'removes the emoji' do
+ expect do
+ post_graphql_mutation(mutation, current_user: current_user)
+ end.to change { AwardEmoji.count }.by(-1)
+ end
+
+ it 'returns no errors' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(graphql_errors).to be_nil
+ end
+
+ it 'returns an empty awardEmoji' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(mutation_response).to have_key('awardEmoji')
+ expect(mutation_response['awardEmoji']).to be_nil
+ end
+ end
+ end
+end
diff --git a/spec/requests/api/graphql/mutations/award_emojis/toggle_spec.rb b/spec/requests/api/graphql/mutations/award_emojis/toggle_spec.rb
new file mode 100644
index 00000000000..31145730f10
--- /dev/null
+++ b/spec/requests/api/graphql/mutations/award_emojis/toggle_spec.rb
@@ -0,0 +1,142 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'Toggling an AwardEmoji' do
+ include GraphqlHelpers
+
+ let(:current_user) { create(:user) }
+ let(:awardable) { create(:note) }
+ let(:project) { awardable.project }
+ let(:emoji_name) { 'thumbsup' }
+ let(:mutation) do
+ variables = {
+ awardable_id: GitlabSchema.id_from_object(awardable).to_s,
+ name: emoji_name
+ }
+
+ graphql_mutation(:toggle_award_emoji, variables)
+ end
+
+ def mutation_response
+ graphql_mutation_response(:toggle_award_emoji)
+ end
+
+ shared_examples 'a mutation that does not create or destroy an AwardEmoji' do
+ it do
+ expect do
+ post_graphql_mutation(mutation, current_user: current_user)
+ end.not_to change { AwardEmoji.count }
+ end
+ end
+
+ def create_award_emoji(user)
+ create(:award_emoji, name: emoji_name, awardable: awardable, user: user )
+ end
+
+ context 'when the user has permission' do
+ before do
+ project.add_developer(current_user)
+ end
+
+ context 'when the given awardable is not an Awardable' do
+ let(:awardable) { create(:label) }
+
+ it_behaves_like 'a mutation that does not create or destroy an AwardEmoji'
+
+ it_behaves_like 'a mutation that returns top-level errors',
+ errors: ['Cannot award emoji to this resource']
+ end
+
+ context 'when the given awardable is an Awardable but still cannot be awarded an emoji' do
+ let(:awardable) { create(:system_note) }
+
+ it_behaves_like 'a mutation that does not create or destroy an AwardEmoji'
+
+ it_behaves_like 'a mutation that returns top-level errors',
+ errors: ['Cannot award emoji to this resource']
+ end
+
+ context 'when the given awardable is an Awardable' do
+ context 'when no emoji has been awarded by the current_user yet' do
+ # Create an award emoji for another user. This therefore tests that
+ # toggling is correctly scoped to the user's emoji only.
+ let!(:award_emoji) { create_award_emoji(create(:user)) }
+
+ it 'creates an emoji' do
+ expect do
+ post_graphql_mutation(mutation, current_user: current_user)
+ end.to change { AwardEmoji.count }.by(1)
+ end
+
+ it 'returns the emoji' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(mutation_response['awardEmoji']['name']).to eq(emoji_name)
+ end
+
+ it 'returns toggledOn as true' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(mutation_response['toggledOn']).to eq(true)
+ end
+
+ context 'when there were active record validation errors' do
+ before do
+ expect_next_instance_of(AwardEmoji) do |award|
+ expect(award).to receive(:valid?).at_least(:once).and_return(false)
+ expect(award).to receive_message_chain(:errors, :full_messages).and_return(['Error 1', 'Error 2'])
+ end
+ end
+
+ it_behaves_like 'a mutation that does not create or destroy an AwardEmoji'
+
+ it_behaves_like 'a mutation that returns errors in the response', errors: ['Error 1', 'Error 2']
+
+ it 'returns an empty awardEmoji' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(mutation_response).to have_key('awardEmoji')
+ expect(mutation_response['awardEmoji']).to be_nil
+ end
+ end
+ end
+
+ context 'when an emoji has been awarded by the current_user' do
+ let!(:award_emoji) { create_award_emoji(current_user) }
+
+ it 'removes the emoji' do
+ expect do
+ post_graphql_mutation(mutation, current_user: current_user)
+ end.to change { AwardEmoji.count }.by(-1)
+ end
+
+ it 'returns no errors' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(graphql_errors).to be_nil
+ end
+
+ it 'returns an empty awardEmoji' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(mutation_response).to have_key('awardEmoji')
+ expect(mutation_response['awardEmoji']).to be_nil
+ end
+
+ it 'returns toggledOn as false' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(mutation_response['toggledOn']).to eq(false)
+ end
+ end
+ end
+ end
+
+ context 'when the user does not have permission' do
+ it_behaves_like 'a mutation that does not create or destroy an AwardEmoji'
+
+ it_behaves_like 'a mutation that returns top-level errors',
+ errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action']
+ end
+end
diff --git a/spec/support/api/boards_shared_examples.rb b/spec/support/api/boards_shared_examples.rb
index 592962ebf7c..3abb5096a7a 100644
--- a/spec/support/api/boards_shared_examples.rb
+++ b/spec/support/api/boards_shared_examples.rb
@@ -14,6 +14,16 @@ shared_examples_for 'group and project boards' do |route_definition, ee = false|
end
end
+ it 'avoids N+1 queries' do
+ pat = create(:personal_access_token, user: user)
+ control = ActiveRecord::QueryRecorder.new { get api(root_url, personal_access_token: pat) }
+
+ create(:milestone, "#{board_parent.class.name.underscore}": board_parent)
+ create(:board, "#{board_parent.class.name.underscore}": board_parent)
+
+ expect { get api(root_url, personal_access_token: pat) }.not_to exceed_query_limit(control)
+ end
+
describe "GET #{route_definition}" do
context "when unauthenticated" do
it "returns authentication error" do
diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb
index bcf6669f37d..1a09d48f4cd 100644
--- a/spec/support/helpers/graphql_helpers.rb
+++ b/spec/support/helpers/graphql_helpers.rb
@@ -4,10 +4,7 @@ module GraphqlHelpers
# makes an underscored string look like a fieldname
# "merge_request" => "mergeRequest"
def self.fieldnamerize(underscored_field_name)
- graphql_field_name = underscored_field_name.to_s.camelize
- graphql_field_name[0] = graphql_field_name[0].downcase
-
- graphql_field_name
+ underscored_field_name.to_s.camelize(:lower)
end
# Run a loader's named resolver
diff --git a/spec/support/shared_examples/graphql/mutation_shared_examples.rb b/spec/support/shared_examples/graphql/mutation_shared_examples.rb
new file mode 100644
index 00000000000..022d41c0bdd
--- /dev/null
+++ b/spec/support/shared_examples/graphql/mutation_shared_examples.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+# Shared example for expecting top-level errors.
+# See https://graphql-ruby.org/mutations/mutation_errors#raising-errors
+#
+# { errors: [] }
+#
+# There must be a method or let called `mutation` defined that executes
+# the mutation.
+RSpec.shared_examples 'a mutation that returns top-level errors' do |errors:|
+ it do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ error_messages = graphql_errors.map { |e| e['message'] }
+
+ expect(error_messages).to eq(errors)
+ end
+end
+
+# Shared example for expecting schema-level errors.
+# See https://graphql-ruby.org/mutations/mutation_errors#errors-as-data
+#
+# { data: { mutationName: { errors: [] } } }
+#
+# There must be:
+# - a method or let called `mutation` defined that executes the mutation
+# - a `mutation_response` method defined that returns the data of the mutation response.
+RSpec.shared_examples 'a mutation that returns errors in the response' do |errors:|
+ it do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(mutation_response['errors']).to eq(errors)
+ end
+end