Commit 19ecd0b7 authored by Arturo Herrero's avatar Arturo Herrero

Merge branch '326436-fj-add-snippets-and-members-menus' into 'master'

Add Snippets and Members menus to project sidebar refactor

See merge request gitlab-org/gitlab!60701
parents ac97d842 7e6631d1
- if project_nav_tab? :snippets
= nav_link(controller: :snippets) do
= link_to project_snippets_path(@project), class: 'shortcuts-snippets', data: { qa_selector: 'snippets_link' } do
.nav-icon-container
= sprite_icon('snippet')
%span.nav-item-name
= _('Snippets')
%ul.sidebar-sub-level-items.is-fly-out-only
= nav_link(controller: :snippets, html_options: { class: "fly-out-top-item" } ) do
= link_to project_snippets_path(@project) do
%strong.fly-out-top-item-name
= _('Snippets')
= nav_link(controller: :project_members) do
= link_to project_project_members_path(@project), title: _('Members'), class: 'qa-members-link', id: 'js-onboarding-members-link' do
.nav-icon-container
= sprite_icon('users')
%span.nav-item-name
= _('Members')
%ul.sidebar-sub-level-items.is-fly-out-only
= nav_link(path: %w[members#show], html_options: { class: "fly-out-top-item" } ) do
= link_to project_project_members_path(@project) do
%strong.fly-out-top-item-name
= _('Members')
- if project_nav_tab? :settings
= nav_link(path: sidebar_settings_paths) do
= link_to edit_project_path(@project) do
......
# frozen_string_literal: true
module Sidebars
module Projects
module Menus
class MembersMenu < ::Sidebars::Menu
override :link
def link
project_project_members_path(context.project)
end
override :extra_container_html_options
def extra_container_html_options
{
id: 'js-onboarding-members-link'
}
end
override :title
def title
_('Members')
end
override :sprite_icon
def sprite_icon
'users'
end
override :render?
def render?
can?(context.current_user, :read_project_member, context.project)
end
override :active_routes
def active_routes
{ controller: :project_members }
end
end
end
end
end
# frozen_string_literal: true
module Sidebars
module Projects
module Menus
class SnippetsMenu < ::Sidebars::Menu
override :link
def link
project_snippets_path(context.project)
end
override :extra_container_html_options
def extra_container_html_options
{
class: 'shortcuts-snippets'
}
end
override :title
def title
_('Snippets')
end
override :sprite_icon
def sprite_icon
'snippet'
end
override :render?
def render?
can?(context.current_user, :read_snippet, context.project)
end
override :active_routes
def active_routes
{ controller: :snippets }
end
end
end
end
end
......@@ -22,6 +22,8 @@ module Sidebars
add_menu(Sidebars::Projects::Menus::AnalyticsMenu.new(context))
add_menu(confluence_or_wiki_menu)
add_menu(Sidebars::Projects::Menus::ExternalWikiMenu.new(context))
add_menu(Sidebars::Projects::Menus::SnippetsMenu.new(context))
add_menu(Sidebars::Projects::Menus::MembersMenu.new(context))
end
override :render_raw_menus_partial
......
......@@ -13,11 +13,6 @@ module QA
include SubMenus::Settings
include SubMenus::Packages
view 'app/views/layouts/nav/sidebar/_project_menus.html.haml' do
element :snippets_link
element :members_link
end
def click_merge_requests
within_sidebar do
click_element(:sidebar_menu_link, menu_item: 'Merge requests')
......@@ -38,13 +33,13 @@ module QA
def click_snippets
within_sidebar do
click_element(:snippets_link)
click_element(:sidebar_menu_link, menu_item: 'Snippets')
end
end
def click_members
within_sidebar do
click_element(:members_link)
click_element(:sidebar_menu_link, menu_item: 'Members')
end
end
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::Projects::Menus::MembersMenu 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) }
describe '#render?' do
context 'when user cannot access members' do
let(:user) { nil }
it 'returns false' do
expect(subject.render?).to eq false
end
end
context 'when user can access members' do
it 'returns true' do
expect(subject.render?).to eq true
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::Projects::Menus::SnippetsMenu 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) }
describe '#render?' do
context 'when user cannot access snippets' do
let(:user) { nil }
it 'returns false' do
expect(subject.render?).to eq false
end
end
context 'when user can access snippets' do
it 'returns true' do
expect(subject.render?).to eq true
end
end
end
end
......@@ -863,6 +863,46 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
end
end
describe 'Snippets' do
before do
render
end
context 'when user can access snippets' do
it 'shows Snippets link' do
expect(rendered).to have_link('Snippets', href: project_snippets_path(project))
end
end
context 'when user cannot access snippets' do
let(:user) { nil }
it 'does not show Snippets link' do
expect(rendered).not_to have_link('Snippets')
end
end
end
describe 'Members' do
before do
render
end
context 'when user can access members' do
it 'show Members link' do
expect(rendered).to have_link('Members', href: project_project_members_path(project))
end
end
context 'when user cannot access members' do
let(:user) { nil }
it 'show Members link' do
expect(rendered).not_to have_link('Members')
end
end
end
describe 'operations settings tab' do
describe 'archive projects' 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