From c16120ba10012780d022d6c464322d1a07ad647a Mon Sep 17 00:00:00 2001 From: Nasser Zahrani Date: Mon, 18 Nov 2024 14:19:37 -0500 Subject: [PATCH] Add unlink quick item to work items widget Extends the quick actions for linked work items to include unlink action. --- app/models/work_items/widgets/linked_items.rb | 2 +- app/services/issue_links/destroy_service.rb | 5 +++ .../quick_actions/interpret_service_spec.rb | 34 +++++++++++++++++-- lib/gitlab/quick_actions/relate_actions.rb | 6 ++-- locale/gitlab.pot | 6 ++-- .../work_items/widgets/linked_items_spec.rb | 2 +- .../quick_actions/interpret_service_spec.rb | 4 +-- 7 files changed, 47 insertions(+), 12 deletions(-) diff --git a/app/models/work_items/widgets/linked_items.rb b/app/models/work_items/widgets/linked_items.rb index 8308c35fc3ad9f..ed9b35dc16e745 100644 --- a/app/models/work_items/widgets/linked_items.rb +++ b/app/models/work_items/widgets/linked_items.rb @@ -6,7 +6,7 @@ class LinkedItems < Base delegate :linked_work_items, to: :work_item def self.quick_action_commands - %i[blocks blocked_by relate] + %i[blocks blocked_by relate unlink] end end end diff --git a/app/services/issue_links/destroy_service.rb b/app/services/issue_links/destroy_service.rb index 9116e9fb703607..18fabda11fb053 100644 --- a/app/services/issue_links/destroy_service.rb +++ b/app/services/issue_links/destroy_service.rb @@ -4,6 +4,11 @@ module IssueLinks class DestroyService < IssuableLinks::DestroyService include IncidentManagement::UsageData + def success(...) + GraphqlTriggers.work_item_updated(@source) + super + end + private def permission_to_remove_relation? diff --git a/ee/spec/services/quick_actions/interpret_service_spec.rb b/ee/spec/services/quick_actions/interpret_service_spec.rb index 12fff60811a192..0f096793723e94 100644 --- a/ee/spec/services/quick_actions/interpret_service_spec.rb +++ b/ee/spec/services/quick_actions/interpret_service_spec.rb @@ -1394,7 +1394,7 @@ shared_examples 'command applied successfully' do it 'executes command successfully' do expect { unlink_issues }.to change { IssueLink.count }.by(-1) - expect(unlink_issues[2]).to eq("Removed link with #{other_issue.to_reference(issue)}.") + expect(unlink_issues[2]).to eq("Removed linked item #{other_issue.to_reference(issue)}.") expect(issue.notes.last.note).to eq("removed the relation with #{other_issue.to_reference}") expect(other_issue.notes.last.note).to eq("removed the relation with #{issue.to_reference}") end @@ -1541,7 +1541,7 @@ end end - describe 'blocking issues commands' do + describe 'linked items commands' do let_it_be(:guest) { create(:user) } let_it_be(:restricted_project) { create(:project) } let_it_be(:ref1) { create(:issue, project: project).to_reference } @@ -1642,6 +1642,36 @@ end end + context 'with /unlink' do + let(:unlink_command) { "/unlink #{ref1}" } + + context 'with sufficient permissions' do + before do + issue.project.add_guest(current_user) + end + + it '/unlink is available' do + _, explanations = service.explain(unlink_command, issue) + + expect(explanations) + .to contain_exactly("Removes linked item #{project.issues.second.to_reference(issue)}.") + end + + context 'when target is not an issue' do + let(:target) { create(:epic, group: group) } + + it_behaves_like 'quick action is unavailable', :unlink + end + end + + context 'with insufficient permissions' do + let_it_be(:target) { create(:issue, project: restricted_project) } + let(:current_user) { guest } + + it_behaves_like 'quick action is unavailable', :blocks + end + end + context 'with /blocked_by' do let(:blocked_by_command) { "/blocked_by #{ref1} #{ref2} #{ref3} #{ref4}" } diff --git a/lib/gitlab/quick_actions/relate_actions.rb b/lib/gitlab/quick_actions/relate_actions.rb index 0f9adda0f5f3e5..e44111024ff5ec 100644 --- a/lib/gitlab/quick_actions/relate_actions.rb +++ b/lib/gitlab/quick_actions/relate_actions.rb @@ -30,12 +30,12 @@ module RelateActions create_links(target_issues) end - desc { _("Remove link with another issue") } + desc { _("Remove linked item") } explanation do |issue| - _('Removes link with %{issue_ref}.') % { issue_ref: issue.to_reference(quick_action_target) } + _('Removes linked item %{issue_ref}.') % { issue_ref: issue.to_reference(quick_action_target) } end execution_message do |issue| - _('Removed link with %{issue_ref}.') % { issue_ref: issue.to_reference(quick_action_target) } + _('Removed linked item %{issue_ref}.') % { issue_ref: issue.to_reference(quick_action_target) } end params '<#issue | group/project#issue | issue URL>' types Issue diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 10a6e92d12401f..8bc88ae50508e0 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -46336,7 +46336,7 @@ msgstr "" msgid "Remove link" msgstr "" -msgid "Remove link with another issue" +msgid "Remove linked item" msgstr "" msgid "Remove list" @@ -46432,7 +46432,7 @@ msgstr "" msgid "Removed an issue from an epic." msgstr "" -msgid "Removed link with %{issue_ref}." +msgid "Removed linked item %{issue_ref}." msgstr "" msgid "Removed members no longer have access to this top-level group, its sub-groups, and their projects." @@ -46491,7 +46491,7 @@ msgstr "" msgid "Removes email participants." msgstr "" -msgid "Removes link with %{issue_ref}." +msgid "Removes linked item %{issue_ref}." msgstr "" msgid "Removes parent epic %{epic_ref}." diff --git a/spec/models/work_items/widgets/linked_items_spec.rb b/spec/models/work_items/widgets/linked_items_spec.rb index ca5b9bf31cedec..3a6ae20ded199a 100644 --- a/spec/models/work_items/widgets/linked_items_spec.rb +++ b/spec/models/work_items/widgets/linked_items_spec.rb @@ -16,7 +16,7 @@ describe '.quick_action_commands' do specify do expect(described_class.quick_action_commands) - .to contain_exactly(:blocks, :blocked_by, :relate) + .to contain_exactly(:blocks, :blocked_by, :relate, :unlink) end end diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb index 2ade277e00f5e9..a06c0e29f5e7ea 100644 --- a/spec/services/quick_actions/interpret_service_spec.rb +++ b/spec/services/quick_actions/interpret_service_spec.rb @@ -2489,7 +2489,7 @@ it 'executes command successfully' do expect { unlink_issues }.to change { IssueLink.count }.by(-1) - expect(unlink_issues[2]).to eq("Removed link with #{other_issue.to_reference(issue)}.") + expect(unlink_issues[2]).to eq("Removed linked item #{other_issue.to_reference(issue)}.") expect(issue.notes.last.note).to eq("removed the relation with #{other_issue.to_reference}") expect(other_issue.notes.last.note).to eq("removed the relation with #{issue.to_reference}") end @@ -3710,7 +3710,7 @@ it '/unlink command is available' do _, explanations = service.explain(unlink_content, issue) - translated_string = _("Removes link with %{issue}.") + translated_string = _("Removes linked item %{issue}.") formatted_message = format(translated_string, issue: other_issue.to_s) expect(explanations).to eq([formatted_message]) -- GitLab