Commit 9d6f4ecd authored by Arturo Herrero's avatar Arturo Herrero

Merge branch '326437-fj-add-confluence-wiki-external-wiki-menu' into 'master'

Add Confluence, External Wiki, and Wiki menus to sidebar refactor

See merge request gitlab-org/gitlab!60657
parents a961e951 f1bd6389
- if project_nav_tab?(:confluence)
- confluence_url = project_wikis_confluence_path(@project)
= nav_link do
= link_to confluence_url, class: 'shortcuts-confluence' do
.nav-icon-container
= image_tag 'confluence.svg', alt: _('Confluence')
%span.nav-item-name
= _('Confluence')
%ul.sidebar-sub-level-items.is-fly-out-only
= nav_link(html_options: { class: 'fly-out-top-item' } ) do
= link_to confluence_url, target: '_blank', rel: 'noopener noreferrer' do
%strong.fly-out-top-item-name
= _('Confluence')
- if project_nav_tab? :wiki
= render 'layouts/nav/sidebar/wiki_link', wiki_url: wiki_path(@project.wiki)
- if project_nav_tab?(:external_wiki)
- external_wiki_url = @project.external_wiki.external_wiki_url
= nav_link do
= link_to external_wiki_url, class: 'shortcuts-external_wiki' do
.nav-icon-container
= sprite_icon('external-link')
%span.nav-item-name
= s_('ExternalWikiService|External wiki')
%ul.sidebar-sub-level-items.is-fly-out-only
= nav_link(html_options: { class: "fly-out-top-item" } ) do
= link_to external_wiki_url do
%strong.fly-out-top-item-name
= s_('ExternalWikiService|External wiki')
- if project_nav_tab? :snippets - if project_nav_tab? :snippets
= nav_link(controller: :snippets) do = nav_link(controller: :snippets) do
= link_to project_snippets_path(@project), class: 'shortcuts-snippets', data: { qa_selector: 'snippets_link' } do = link_to project_snippets_path(@project), class: 'shortcuts-snippets', data: { qa_selector: 'snippets_link' } do
......
# frozen_string_literal: true
module Sidebars
module Projects
module Menus
class ConfluenceMenu < ::Sidebars::Menu
override :link
def link
project_wikis_confluence_path(context.project)
end
override :extra_container_html_options
def extra_container_html_options
{
class: 'shortcuts-confluence'
}
end
override :title
def title
_('Confluence')
end
override :image_path
def image_path
'confluence.svg'
end
override :image_html_options
def image_html_options
{
alt: title
}
end
override :render?
def render?
context.project.has_confluence?
end
end
end
end
end
# frozen_string_literal: true
module Sidebars
module Projects
module Menus
class ExternalWikiMenu < ::Sidebars::Menu
override :link
def link
external_wiki.external_wiki_url
end
override :extra_container_html_options
def extra_container_html_options
{
target: '_blank',
rel: 'noopener noreferrer',
class: 'shortcuts-external_wiki'
}
end
override :extra_collapsed_container_html_options
def extra_collapsed_container_html_options
{
target: '_blank',
rel: 'noopener noreferrer'
}
end
override :title
def title
s_('ExternalWikiService|External wiki')
end
override :sprite_icon
def sprite_icon
'external-link'
end
override :render?
def render?
external_wiki.present?
end
private
def external_wiki
@external_wiki ||= context.project.external_wiki
end
end
end
end
end
# frozen_string_literal: true
module Sidebars
module Projects
module Menus
class WikiMenu < ::Sidebars::Menu
override :link
def link
wiki_path(context.project.wiki)
end
override :extra_container_html_options
def extra_container_html_options
{
class: 'shortcuts-wiki'
}
end
override :title
def title
_('Wiki')
end
override :sprite_icon
def sprite_icon
'book'
end
override :render?
def render?
can?(context.current_user, :read_wiki, context.project)
end
override :active_routes
def active_routes
{ controller: :wikis }
end
end
end
end
end
...@@ -20,6 +20,8 @@ module Sidebars ...@@ -20,6 +20,8 @@ module Sidebars
add_menu(Sidebars::Projects::Menus::InfrastructureMenu.new(context)) add_menu(Sidebars::Projects::Menus::InfrastructureMenu.new(context))
add_menu(Sidebars::Projects::Menus::PackagesRegistriesMenu.new(context)) add_menu(Sidebars::Projects::Menus::PackagesRegistriesMenu.new(context))
add_menu(Sidebars::Projects::Menus::AnalyticsMenu.new(context)) add_menu(Sidebars::Projects::Menus::AnalyticsMenu.new(context))
add_menu(confluence_or_wiki_menu)
add_menu(Sidebars::Projects::Menus::ExternalWikiMenu.new(context))
end end
override :render_raw_menus_partial override :render_raw_menus_partial
...@@ -31,6 +33,14 @@ module Sidebars ...@@ -31,6 +33,14 @@ module Sidebars
def aria_label def aria_label
_('Project navigation') _('Project navigation')
end end
private
def confluence_or_wiki_menu
confluence_menu = ::Sidebars::Projects::Menus::ConfluenceMenu.new(context)
confluence_menu.render? ? confluence_menu : Sidebars::Projects::Menus::WikiMenu.new(context)
end
end end
end end
end end
......
...@@ -18,10 +18,6 @@ module QA ...@@ -18,10 +18,6 @@ module QA
element :members_link element :members_link
end end
view 'app/views/layouts/nav/sidebar/_wiki_link.html.haml' do
element :wiki_link
end
def click_merge_requests def click_merge_requests
within_sidebar do within_sidebar do
click_element(:sidebar_menu_link, menu_item: 'Merge requests') click_element(:sidebar_menu_link, menu_item: 'Merge requests')
...@@ -30,7 +26,7 @@ module QA ...@@ -30,7 +26,7 @@ module QA
def click_wiki def click_wiki
within_sidebar do within_sidebar do
click_element(:wiki_link) click_element(:sidebar_menu_link, menu_item: 'Wiki')
end end
end end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::Projects::Menus::ConfluenceMenu do
let_it_be_with_refind(:project) { create(:project, has_external_wiki: true) }
let(:user) { project.owner }
let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project) }
subject { described_class.new(context) }
describe 'render?' do
context 'when Confluence integration is not present' do
it 'returns false' do
expect(subject.render?).to eq false
end
end
context 'when Confluence integration is present' do
let!(:confluence) { create(:confluence_service, project: project, active: active) }
context 'when integration is disabled' do
let(:active) { false }
it 'returns false' do
expect(subject.render?).to eq false
end
end
context 'when issues integration is enabled' do
let(:active) { true }
it 'returns true' do
expect(subject.render?).to eq true
end
it 'does not contain any sub menu' do
expect(subject.items).to be_empty
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::Projects::Menus::ExternalWikiMenu do
let(:project) { build(:project) }
let(:user) { project.owner }
let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project) }
subject { described_class.new(context) }
it 'does not contain any sub menu' do
expect(subject.items).to be_empty
end
describe '#render?' do
before do
expect(subject).to receive(:external_wiki).and_return(external_wiki).at_least(1)
end
context 'when active external issue tracker' do
let(:external_wiki) { build(:external_wiki_service, project: project) }
context 'is present' do
it 'returns true' do
expect(subject.render?).to be_truthy
end
end
context 'is not present' do
let(:external_wiki) { nil }
it 'returns false' do
expect(subject.render?).to be_falsey
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::Projects::Menus::WikiMenu do
let(:project) { build(:project) }
let(:user) { project.owner }
let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project) }
subject { described_class.new(context) }
it 'does not contain any sub menu' do
expect(subject.items).to be_empty
end
describe '#render?' do
context 'when user can access project wiki' do
it 'returns true' do
expect(subject.render?).to be true
end
context 'when user cannot access project wiki' do
let(:user) { nil }
it 'returns false' do
expect(subject.render?).to be false
end
end
end
end
end
...@@ -11,4 +11,32 @@ RSpec.describe Sidebars::Projects::Panel do ...@@ -11,4 +11,32 @@ RSpec.describe Sidebars::Projects::Panel do
it 'has a scope menu' do it 'has a scope menu' do
expect(subject.scope_menu).to be_a(Sidebars::Projects::Menus::ScopeMenu) expect(subject.scope_menu).to be_a(Sidebars::Projects::Menus::ScopeMenu)
end end
context 'Confluence menu item' do
subject { described_class.new(context).instance_variable_get(:@menus) }
context 'when integration is present and active' do
let_it_be(:confluence) { create(:confluence_service, active: true) }
let(:project) { confluence.project }
it 'contains Confluence menu item' do
expect(subject.index { |i| i.is_a?(Sidebars::Projects::Menus::ConfluenceMenu) }).not_to be_nil
end
it 'does not contain Wiki menu item' do
expect(subject.index { |i| i.is_a?(Sidebars::Projects::Menus::WikiMenu) }).to be_nil
end
end
context 'when integration is not present' do
it 'does not contain Confluence menu item' do
expect(subject.index { |i| i.is_a?(Sidebars::Projects::Menus::ConfluenceMenu) }).to be_nil
end
it 'contains Wiki menu item' do
expect(subject.index { |i| i.is_a?(Sidebars::Projects::Menus::WikiMenu) }).not_to be_nil
end
end
end
end end
...@@ -783,13 +783,39 @@ RSpec.describe 'layouts/nav/sidebar/_project' do ...@@ -783,13 +783,39 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
end end
end end
describe 'wiki entry tab' do describe 'Confluence' do
let(:can_read_wiki) { true } let!(:service) { create(:confluence_service, project: project, active: active) }
before do before do
allow(view).to receive(:can?).with(user, :read_wiki, project).and_return(can_read_wiki) render
end
context 'when the Confluence integration is active' do
let(:active) { true }
it 'shows the Confluence link' do
expect(rendered).to have_link('Confluence', href: project_wikis_confluence_path(project))
end
it 'does not show the GitLab wiki link' do
expect(rendered).not_to have_link('Wiki')
end
end
context 'when it is disabled' do
let(:active) { false }
it 'does not show the Confluence link' do
expect(rendered).not_to have_link('Confluence')
end end
it 'shows the GitLab wiki link' do
expect(rendered).to have_link('Wiki', href: wiki_path(project.wiki))
end
end
end
describe 'Wiki' do
describe 'when wiki is enabled' do describe 'when wiki is enabled' do
it 'shows the wiki tab with the wiki internal link' do it 'shows the wiki tab with the wiki internal link' do
render render
...@@ -799,9 +825,9 @@ RSpec.describe 'layouts/nav/sidebar/_project' do ...@@ -799,9 +825,9 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
end end
describe 'when wiki is disabled' do describe 'when wiki is disabled' do
let(:can_read_wiki) { false } let(:user) { nil }
it 'does not show the wiki tab' do it 'does not show the wiki link' do
render render
expect(rendered).not_to have_link('Wiki') expect(rendered).not_to have_link('Wiki')
...@@ -809,7 +835,7 @@ RSpec.describe 'layouts/nav/sidebar/_project' do ...@@ -809,7 +835,7 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
end end
end end
describe 'external wiki entry tab' do describe 'External Wiki' do
let(:properties) { { 'external_wiki_url' => 'https://gitlab.com' } } let(:properties) { { 'external_wiki_url' => 'https://gitlab.com' } }
let(:service_status) { true } let(:service_status) { true }
...@@ -829,7 +855,7 @@ RSpec.describe 'layouts/nav/sidebar/_project' do ...@@ -829,7 +855,7 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
context 'when it is disabled' do context 'when it is disabled' do
let(:service_status) { false } let(:service_status) { false }
it 'does not show the external wiki tab' do it 'does not show the external wiki link' do
render render
expect(rendered).not_to have_link('External wiki') expect(rendered).not_to have_link('External wiki')
...@@ -837,38 +863,6 @@ RSpec.describe 'layouts/nav/sidebar/_project' do ...@@ -837,38 +863,6 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
end end
end end
describe 'confluence tab' do
let!(:service) { create(:confluence_service, project: project, active: active) }
before do
render
end
context 'when the Confluence integration is active' do
let(:active) { true }
it 'shows the Confluence tab' do
expect(rendered).to have_link('Confluence', href: project_wikis_confluence_path(project))
end
it 'does not show the GitLab wiki tab' do
expect(rendered).not_to have_link('Wiki')
end
end
context 'when it is disabled' do
let(:active) { false }
it 'does not show the Confluence tab' do
expect(rendered).not_to have_link('Confluence')
end
it 'shows the GitLab wiki tab' do
expect(rendered).to have_link('Wiki', href: wiki_path(project.wiki))
end
end
end
describe 'operations settings tab' do describe 'operations settings tab' do
describe 'archive projects' do describe 'archive projects' do
before do before 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