Commit 93e96b73 authored by Lee Tickett's avatar Lee Tickett Committed by Alex Kalderimis

Hide issue contacts and quick actions

This MR hides the issue contacts widget in the right sidebar
and the /add_contacts and /remove_contacts quick actions
when there are no contacts in the group or ancestors.

Changelog: added
parent c10e2bec
......@@ -17,7 +17,10 @@ module IssuableActions
def show
respond_to do |format|
format.html do
@show_crm_contacts = issuable.is_a?(Issue) && can?(current_user, :read_crm_contact, issuable.project.group) # rubocop:disable Gitlab/ModuleWithInstanceVariables
@show_crm_contacts = issuable.is_a?(Issue) && # rubocop:disable Gitlab/ModuleWithInstanceVariables
can?(current_user, :read_crm_contact, issuable.project.group) &&
CustomerRelations::Contact.exists_for_group?(issuable.project.group)
@issuable_sidebar = serializer.represent(issuable, serializer: 'sidebar') # rubocop:disable Gitlab/ModuleWithInstanceVariables
render 'show'
end
......
......@@ -33,6 +33,12 @@ class CustomerRelations::Contact < ApplicationRecord
.pluck(:id)
end
def self.exists_for_group?(group)
return false unless group
exists?(group_id: group.self_and_ancestor_ids)
end
private
def validate_email_format
......
......@@ -290,7 +290,8 @@ module Gitlab
params 'contact@example.com person@example.org'
types Issue
condition do
current_user.can?(:set_issue_crm_contacts, quick_action_target)
current_user.can?(:set_issue_crm_contacts, quick_action_target) &&
CustomerRelations::Contact.exists_for_group?(quick_action_target.project.group)
end
execution_message do
_('One or more contacts were successfully added.')
......@@ -304,7 +305,8 @@ module Gitlab
params 'contact@example.com person@example.org'
types Issue
condition do
current_user.can?(:set_issue_crm_contacts, quick_action_target)
current_user.can?(:set_issue_crm_contacts, quick_action_target) &&
CustomerRelations::Contact.exists_for_group?(quick_action_target.project.group)
end
execution_message do
_('One or more contacts were successfully removed.')
......
......@@ -98,4 +98,31 @@ RSpec.describe CustomerRelations::Contact, type: :model do
expect { described_class.find_ids_by_emails(group, Array(0..too_many_emails)) }.to raise_error(ArgumentError)
end
end
describe '#self.exists_for_group?' do
let(:group) { create(:group) }
let(:subgroup) { create(:group, parent: group) }
context 'with no contacts in group or parent' do
it 'returns false' do
expect(described_class.exists_for_group?(subgroup)).to be_falsey
end
end
context 'with contacts in group' do
it 'returns true' do
create(:contact, group: subgroup)
expect(described_class.exists_for_group?(subgroup)).to be_truthy
end
end
context 'with contacts in parent' do
it 'returns true' do
create(:contact, group: group)
expect(described_class.exists_for_group?(subgroup)).to be_truthy
end
end
end
end
......@@ -2598,6 +2598,45 @@ RSpec.describe QuickActions::InterpretService do
expect(service.commands_executed_count).to eq(3)
end
end
describe 'crm commands' do
let(:add_contacts) { '/add_contacts' }
let(:remove_contacts) { '/remove_contacts' }
before_all do
group.add_developer(developer)
end
context 'when group has no contacts' do
it '/add_contacts is not available' do
_, explanations = service.explain(add_contacts, issue)
expect(explanations).to be_empty
end
it '/remove_contacts is not available' do
_, explanations = service.explain(remove_contacts, issue)
expect(explanations).to be_empty
end
end
context 'when group has contacts' do
let!(:contact) { create(:contact, group: group) }
it '/add_contacts is available' do
_, explanations = service.explain(add_contacts, issue)
expect(explanations).to contain_exactly("Add customer relation contact(s).")
end
it '/remove_contacts is available' do
_, explanations = service.explain(remove_contacts, issue)
expect(explanations).to contain_exactly("Remove customer relation contact(s).")
end
end
end
end
describe '#available_commands' do
......
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