Commit ccd023c3 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch '211519-hide-default-reactions' into 'master'

Add option to hide the default "thumbs up" and "thumbs down" buttons on issues, merge requests, and snippets.

Closes #211519

See merge request gitlab-org/gitlab!27734
parents b9c745f0 16c883d9
<script>
import { GlSprintf, GlLink } from '@gitlab/ui';
import { GlSprintf, GlLink, GlFormCheckbox } from '@gitlab/ui';
import settingsMixin from 'ee_else_ce/pages/projects/shared/permissions/mixins/settings_pannel_mixin';
import { s__ } from '~/locale';
......@@ -24,6 +24,7 @@ export default {
projectSettingRow,
GlSprintf,
GlLink,
GlFormCheckbox,
},
mixins: [settingsMixin],
......@@ -519,5 +520,23 @@ export default {
)
}}</span>
</project-setting-row>
<project-setting-row class="mb-3">
<input
:value="showDefaultAwardEmojis"
type="hidden"
name="project[project_setting_attributes][show_default_award_emojis]"
/>
<gl-form-checkbox
v-model="showDefaultAwardEmojis"
name="project[project_setting_attributes][show_default_award_emojis]"
>
{{ s__('ProjectSettings|Show default award emojis') }}
<template #help>{{
s__(
'ProjectSettings|When enabled, issues, merge requests, and snippets will always show thumbs-up and thumbs-down award emoji buttons.',
)
}}</template>
</gl-form-checkbox>
</project-setting-row>
</div>
</template>
......@@ -400,6 +400,9 @@ class ProjectsController < Projects::ApplicationController
wiki_access_level
pages_access_level
metrics_dashboard_access_level
],
project_setting_attributes: %i[
show_default_award_emojis
]
]
end
......
......@@ -588,7 +588,8 @@ module ProjectsHelper
containerRegistryEnabled: !!project.container_registry_enabled,
lfsEnabled: !!project.lfs_enabled,
emailsDisabled: project.emails_disabled?,
metricsDashboardAccessLevel: feature.metrics_dashboard_access_level
metricsDashboardAccessLevel: feature.metrics_dashboard_access_level,
showDefaultAwardEmojis: project.show_default_award_emojis?
}
end
......
......@@ -74,7 +74,7 @@ module Awardable
# By default we always load award_emoji user association
awards = award_emoji.group_by(&:name)
if with_thumbs
if with_thumbs && (!project || project.show_default_award_emojis?)
awards[AwardEmoji::UPVOTE_NAME] ||= []
awards[AwardEmoji::DOWNVOTE_NAME] ||= []
end
......
......@@ -329,6 +329,7 @@ class Project < ApplicationRecord
accepts_nested_attributes_for :variables, allow_destroy: true
accepts_nested_attributes_for :project_feature, update_only: true
accepts_nested_attributes_for :project_setting, update_only: true
accepts_nested_attributes_for :import_data
accepts_nested_attributes_for :auto_devops, update_only: true
accepts_nested_attributes_for :ci_cd_settings, update_only: true
......@@ -352,6 +353,9 @@ class Project < ApplicationRecord
:wiki_access_level, :snippets_access_level, :builds_access_level,
:repository_access_level, :pages_access_level, :metrics_dashboard_access_level,
to: :project_feature, allow_nil: true
delegate :show_default_award_emojis, :show_default_award_emojis=,
:show_default_award_emojis?,
to: :project_setting, allow_nil: true
delegate :scheduled?, :started?, :in_progress?, :failed?, :finished?,
prefix: :import, to: :import_state, allow_nil: true
delegate :no_import?, to: :import_state, allow_nil: true
......
......@@ -196,6 +196,7 @@ class ProjectPolicy < BasePolicy
enable :set_issue_updated_at
enable :set_note_created_at
enable :set_emails_disabled
enable :set_show_default_award_emojis
end
rule { can?(:guest_access) }.policy do
......
---
title: Add option to hide the default "thumbs up" and "thumbs down" buttons on
issues, merge requests, and snippets.
merge_request: 27734
author: Steve Mokris
type: added
# frozen_string_literal: true
class AddProjectShowDefaultAwardEmojis < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
add_column :project_settings, :show_default_award_emojis, :boolean, default: true, null: false # rubocop: disable Migration/AddColumn
end
end
......@@ -5252,7 +5252,9 @@ CREATE TABLE public.project_settings (
project_id integer NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
push_rule_id bigint
push_rule_id bigint,
show_default_award_emojis boolean DEFAULT true,
CONSTRAINT check_bde223416c CHECK ((show_default_award_emojis IS NOT NULL))
);
CREATE TABLE public.project_statistics (
......@@ -13659,6 +13661,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200319203901
20200320112455
20200320123839
20200320212400
20200323011225
20200323011955
20200323071918
......
......@@ -1029,6 +1029,7 @@ POST /projects
| `snippets_access_level` | string | no | One of `disabled`, `private` or `enabled` |
| `pages_access_level` | string | no | One of `disabled`, `private`, `enabled` or `public` |
| `emails_disabled` | boolean | no | Disable email notifications |
| `show_default_award_emojis` | boolean | no | Show default award emojis |
| `resolve_outdated_diff_discussions` | boolean | no | Automatically resolve merge request diffs discussions on lines changed with a push |
| `container_registry_enabled` | boolean | no | Enable container registry for this project |
| `container_expiration_policy_attributes` | hash | no | Update the image expiration policy for this project. Accepts: `cadence` (string), `keep_n` (string), `older_than` (string), `name_regex` (string), `name_regex_delete` (string), `name_regex_keep` (string), `enabled` (boolean) |
......@@ -1098,6 +1099,7 @@ POST /projects/user/:user_id
| `snippets_access_level` | string | no | One of `disabled`, `private` or `enabled` |
| `pages_access_level` | string | no | One of `disabled`, `private`, `enabled` or `public` |
| `emails_disabled` | boolean | no | Disable email notifications |
| `show_default_award_emojis` | boolean | no | Show default award emojis |
| `resolve_outdated_diff_discussions` | boolean | no | Automatically resolve merge request diffs discussions on lines changed with a push |
| `container_registry_enabled` | boolean | no | Enable container registry for this project |
| `shared_runners_enabled` | boolean | no | Enable shared runners for this project |
......@@ -1166,6 +1168,7 @@ PUT /projects/:id
| `snippets_access_level` | string | no | One of `disabled`, `private` or `enabled` |
| `pages_access_level` | string | no | One of `disabled`, `private`, `enabled` or `public` |
| `emails_disabled` | boolean | no | Disable email notifications |
| `show_default_award_emojis` | boolean | no | Show default award emojis |
| `resolve_outdated_diff_discussions` | boolean | no | Automatically resolve merge request diffs discussions on lines changed with a push |
| `container_registry_enabled` | boolean | no | Enable container registry for this project |
| `container_expiration_policy_attributes` | hash | no | Update the image expiration policy for this project. Accepts: `cadence` (string), `keep_n` (string), `older_than` (string), `name_regex` (string), `name_regex_delete` (string), `name_regex_keep` (string), `enabled` (boolean) |
......
......@@ -31,6 +31,7 @@ module API
optional :pages_access_level, type: String, values: %w(disabled private enabled public), desc: 'Pages access level. One of `disabled`, `private`, `enabled` or `public`'
optional :emails_disabled, type: Boolean, desc: 'Disable email notifications'
optional :show_default_award_emojis, type: Boolean, desc: 'Show default award emojis'
optional :shared_runners_enabled, type: Boolean, desc: 'Flag indication if shared runners are enabled for that project'
optional :resolve_outdated_diff_discussions, type: Boolean, desc: 'Automatically resolve merge request diffs discussions on lines changed with a push'
optional :remove_source_branch_after_merge, type: Boolean, desc: 'Remove the source branch by default after merge'
......
......@@ -168,6 +168,7 @@ excluded_attributes:
- :marked_for_deletion_at
- :marked_for_deletion_by_user_id
- :compliance_framework_setting
- :show_default_award_emojis
namespaces:
- :runners_token
- :runners_token_encrypted
......
......@@ -16615,6 +16615,9 @@ msgstr ""
msgid "ProjectSettings|Share code pastes with others out of Git repository"
msgstr ""
msgid "ProjectSettings|Show default award emojis"
msgstr ""
msgid "ProjectSettings|Show link to create/view merge request when pushing from the command line"
msgstr ""
......@@ -16660,6 +16663,9 @@ msgstr ""
msgid "ProjectSettings|When conflicts arise the user is given the option to rebase"
msgstr ""
msgid "ProjectSettings|When enabled, issues, merge requests, and snippets will always show thumbs-up and thumbs-down award emoji buttons."
msgstr ""
msgid "ProjectSettings|Wiki"
msgstr ""
......
......@@ -54,6 +54,36 @@ describe 'Projects settings' do
end
end
context 'default award emojis', :js do
it 'shows award emojis by default' do
visit edit_project_path(project)
default_award_emojis_input = find('input[name="project[project_setting_attributes][show_default_award_emojis]"]', visible: :hidden)
expect(default_award_emojis_input.value).to eq('true')
end
it 'disables award emojis when the checkbox is toggled off' do
visit edit_project_path(project)
default_award_emojis_input = find('input[name="project[project_setting_attributes][show_default_award_emojis]"]', visible: :hidden)
default_award_emojis_checkbox = find('input[name="project[project_setting_attributes][show_default_award_emojis]"][type=checkbox]')
expect(default_award_emojis_input.value).to eq('true')
default_award_emojis_checkbox.click
expect(default_award_emojis_input.value).to eq('false')
page.within('.sharing-permissions') do
find('input[value="Save changes"]').click
end
wait_for_requests
expect(default_award_emojis_input.value).to eq('false')
end
end
def expect_toggle_state(state)
is_collapsed = state == :collapsed
......
......@@ -23,6 +23,7 @@ const defaultProps = {
lfsEnabled: true,
emailsDisabled: false,
packagesEnabled: true,
showDefaultAwardEmojis: true,
},
canDisableEmails: true,
canChangeVisibilityLevel: true,
......@@ -474,6 +475,18 @@ describe('Settings Panel', () => {
});
});
describe('Default award emojis', () => {
it('should show the "Show default award emojis" input', () => {
return wrapper.vm.$nextTick(() => {
expect(
wrapper
.find('input[name="project[project_setting_attributes][show_default_award_emojis]"]')
.exists(),
).toBe(true);
});
});
});
describe('Metrics dashboard', () => {
it('should show the metrics dashboard access toggle', () => {
return wrapper.vm.$nextTick(() => {
......
......@@ -91,4 +91,45 @@ describe Awardable do
expect(issue.award_emoji).to eq issue.award_emoji.sort_by(&:id)
end
end
describe "#grouped_awards" do
context 'default award emojis' do
let(:issue_without_downvote) { create(:issue) }
let(:issue_with_downvote) do
issue_with_downvote = create(:issue)
create(:award_emoji, :downvote, awardable: issue_with_downvote)
issue_with_downvote
end
it "includes unused thumbs buttons by default" do
expect(issue_without_downvote.grouped_awards.keys.sort).to eq %w(thumbsdown thumbsup)
end
it "doesn't include unused thumbs buttons when disabled in project" do
issue_without_downvote.project.show_default_award_emojis = false
expect(issue_without_downvote.grouped_awards.keys.sort).to eq []
end
it "includes unused thumbs buttons when enabled in project" do
issue_without_downvote.project.show_default_award_emojis = true
expect(issue_without_downvote.grouped_awards.keys.sort).to eq %w(thumbsdown thumbsup)
end
it "doesn't include unused thumbs buttons in summary" do
expect(issue_without_downvote.grouped_awards(with_thumbs: false).keys).to eq []
end
it "includes used thumbs buttons when disabled in project" do
issue_with_downvote.project.show_default_award_emojis = false
expect(issue_with_downvote.grouped_awards.keys).to eq %w(thumbsdown)
end
it "includes used thumbs buttons in summary" do
expect(issue_with_downvote.grouped_awards(with_thumbs: false).keys).to eq %w(thumbsdown)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment