Commit a6cbb088 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'refactor/put-zentao-menu-under-issues' into 'master'

Refactor/put zentao menu under issues

See merge request gitlab-org/gitlab!83367
parents 05b82686 132a3673
......@@ -9,12 +9,15 @@ module EE
override :configure_menu_items
def configure_menu_items
return false unless super || show_jira_menu_items?
return false unless super || show_jira_menu_items? \
|| show_zentao_menu_items?
add_item(iterations_menu_item)
add_item(requirements_menu_item)
add_item(jira_issue_list_menu_item)
add_item(jira_external_link_menu_item)
add_item(zentao_issue_list_menu_item)
add_item(zentao_external_link_menu_item)
true
end
......@@ -23,6 +26,11 @@ module EE
external_issue_tracker.is_a?(Integrations::Jira) && context.jira_issues_integration
end
def show_zentao_menu_items?
zentao_active? && \
::Integrations::Zentao.issues_license_available?(context.project)
end
private
def iterations_menu_item
......@@ -88,6 +96,41 @@ module EE
}
)
end
def zentao_active?
!!zentao_integration&.active?
end
def zentao_issue_list_menu_item
return ::Sidebars::NilMenuItem.new(item_id: :zentao_issue_list) unless show_zentao_menu_items?
::Sidebars::MenuItem.new(
title: s_('ZentaoIntegration|ZenTao issues'),
link: project_integrations_zentao_issues_path(context.project),
active_routes: { controller: 'projects/integrations/zentao/issues' },
item_id: :zentao_issue_list
)
end
def zentao_integration
@zentao_integration ||= context.project.zentao_integration
end
def zentao_external_link_menu_item
return ::Sidebars::NilMenuItem.new(item_id: :zentao_external_link) unless show_zentao_menu_items?
::Sidebars::MenuItem.new(
title: s_('ZentaoIntegration|Open ZenTao'),
link: zentao_integration.url,
active_routes: {},
item_id: :zentao_external_link,
sprite_icon: 'external-link',
container_html_options: {
target: '_blank',
rel: 'noopener noreferrer'
}
)
end
end
end
end
......
# frozen_string_literal: true
module EE
module Sidebars
module Projects
module Menus
module ZentaoMenu
extend ::Gitlab::Utils::Override
override :link
def link
return super unless feature_available?
project_integrations_zentao_issues_path(context.project)
end
override :add_items
def add_items
add_item(issue_list_menu_item) if feature_available?
super
end
private
def feature_available?
::Integrations::Zentao.issues_license_available?(context.project)
end
def issue_list_menu_item
::Sidebars::MenuItem.new(
title: s_('ZentaoIntegration|Issue list'),
link: project_integrations_zentao_issues_path(context.project),
active_routes: { controller: 'projects/integrations/zentao/issues' },
item_id: :issue_list
)
end
end
end
end
end
end
......@@ -16,6 +16,10 @@ module EE
if ::Sidebars::Projects::Menus::IssuesMenu.new(context).show_jira_menu_items?
remove_menu(::Sidebars::Projects::Menus::ExternalIssueTrackerMenu)
end
if ::Sidebars::Projects::Menus::IssuesMenu.new(context).show_zentao_menu_items?
remove_menu(::Sidebars::Projects::Menus::ZentaoMenu)
end
end
end
end
......
......@@ -138,4 +138,58 @@ RSpec.describe Sidebars::Projects::Menus::IssuesMenu do
end
end
end
describe 'Zentao issues' do
let(:project) { create(:project, has_external_issue_tracker: true) }
let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project) }
let(:zentao_integration) { create(:zentao_integration, project: project) }
subject { described_class.new(context) }
context 'when Zentao integration is enabled' do
before do
stub_licensed_features(zentao_issues_integration: true)
zentao_integration.update!(active: true)
end
context 'when Issues feature is enabled' do
before do
allow(project).to receive(:issues_enabled?).and_return(true)
end
it 'includes Zentao issues menu items' do
expect(subject.show_zentao_menu_items?).to eq(true)
expect(subject.renderable_items.any? { |e| e.item_id == :zentao_issue_list}).to eq(true)
end
end
context 'when Issues feature is disabled' do
before do
allow(project).to receive(:issues_enabled?).and_return(false)
end
it 'includes Zentao issues menu items' do
expect(subject.show_zentao_menu_items?).to eq(true)
expect(subject.renderable_items.any? { |e| e.item_id == :zentao_issue_list}).to eq(true)
end
end
end
context 'when Zentao integration is disabled' do
before do
stub_licensed_features(zentao_issues_integration: false)
end
context 'when Issues feature is disabled' do
before do
allow(project).to receive(:issues_enabled?).and_return(false)
end
it 'does not include Zentao issues menu items' do
expect(subject.show_zentao_menu_items?).to eq(false)
expect(subject.renderable_items.any? { |e| e.item_id == :zentao_issue_list}).to eq(false)
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::Projects::Menus::ZentaoMenu do
let(:project) { create(:project, has_external_issue_tracker: true) }
let(:user) { project.first_owner }
let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project) }
let(:zentao_integration) { create(:zentao_integration, project: project) }
subject { described_class.new(context) }
describe 'when feature is not licensed' do
before do
stub_licensed_features(zentao_issues_integration: false)
end
it_behaves_like 'ZenTao menu with CE version'
end
describe 'when feature is licensed' do
before do
stub_licensed_features(zentao_issues_integration: true)
end
context 'when issues integration is disabled' do
before do
zentao_integration.update!(active: false)
end
it 'returns false' do
expect(subject.render?).to eq false
end
end
context 'when issues integration is enabled' do
before do
zentao_integration.update!(active: true)
end
it 'returns true' do
expect(subject.render?).to eq true
end
it 'renders menu link' do
expect(subject.link).to include('/-/integrations/zentao/issues')
end
it 'contains issue list and open ZenTao menu items' do
expect(subject.renderable_items.map(&:item_id)).to match_array [:issue_list, :open_zentao]
end
end
end
end
......@@ -4,11 +4,6 @@ module Sidebars
module Projects
module Menus
class ZentaoMenu < ::Sidebars::Menu
override :configure_menu_items
def configure_menu_items
render?.tap { |render| add_items if render }
end
override :link
def link
zentao_integration.url
......@@ -16,7 +11,7 @@ module Sidebars
override :title
def title
s_('ZentaoIntegration|ZenTao issues')
s_('ZentaoIntegration|ZenTao')
end
override :title_html_options
......@@ -26,9 +21,9 @@ module Sidebars
}
end
override :image_path
def image_path
'logos/zentao.svg'
override :sprite_icon
def sprite_icon
'external-link'
end
# Hardcode sizes so image doesn't flash before CSS loads https://gitlab.com/gitlab-org/gitlab/-/issues/321022
......@@ -46,29 +41,11 @@ module Sidebars
zentao_integration.active?
end
def add_items
add_item(open_zentao_menu_item)
end
private
def zentao_integration
@zentao_integration ||= context.project.zentao_integration
end
def open_zentao_menu_item
::Sidebars::MenuItem.new(
title: s_('ZentaoIntegration|Open ZenTao'),
link: zentao_integration.url,
active_routes: {},
item_id: :open_zentao,
sprite_icon: 'external-link',
container_html_options: {
target: '_blank',
rel: 'noopener noreferrer'
}
)
end
end
end
end
......
......@@ -43842,15 +43842,15 @@ msgstr ""
msgid "ZentaoIntegration|If different from Web URL."
msgstr ""
msgid "ZentaoIntegration|Issue list"
msgstr ""
msgid "ZentaoIntegration|Open ZenTao"
msgstr ""
msgid "ZentaoIntegration|Use ZenTao as this project's issue tracker."
msgstr ""
msgid "ZentaoIntegration|ZenTao"
msgstr ""
msgid "ZentaoIntegration|ZenTao API URL (optional)"
msgstr ""
......
......@@ -34,8 +34,16 @@ RSpec.shared_examples 'ZenTao menu with CE version' do
expect(subject.link).to eq zentao_integration.url
end
it 'contains only open ZenTao item' do
expect(subject.renderable_items.map(&:item_id)).to match_array [:open_zentao]
it 'renders external-link icon' do
expect(subject.sprite_icon).to eq 'external-link'
end
it 'renders ZenTao menu' do
expect(subject.title).to eq s_('ZentaoIntegration|ZenTao')
end
it 'does not contain items' do
expect(subject.renderable_items.count).to eq 0
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