Commit e6cb9f66 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch '328510-fj-add-push_rules-menu' into 'master'

Refactor Push Rules menu for groups

See merge request gitlab-org/gitlab!66831
parents 3369d72c 5d4cd2d1
= render_if_exists "layouts/nav/ee/push_rules_link" # EE-specific
- if group_sidebar_link?(:runners)
= nav_link(path: 'groups/runners#index') do
= link_to group_runners_path(@group), title: _('CI/CD'), class: 'has-sub-items' do
......
- return unless can_modify_group_push_rules?(current_user, @group)
= nav_link(controller: :push_rules) do
= link_to edit_group_push_rules_path(@group), title: _('Push Rules') do
.nav-icon-container
= sprite_icon('push-rules')
%span.nav-item-name
= _('Push Rules')
%ul.sidebar-sub-level-items.is-fly-out-only
= nav_link(controller: :push_rules, html_options: { class: "fly-out-top-item" } ) do
= link_to edit_group_push_rules_path(@group), title: _('Push Rules') do
%strong.fly-out-top-item-name
= _('Push Rules')
......@@ -13,6 +13,7 @@ module EE
insert_menu_before(::Sidebars::Groups::Menus::GroupInformationMenu, ::Sidebars::Groups::Menus::TrialExperimentMenu.new(context))
insert_menu_after(::Sidebars::Groups::Menus::GroupInformationMenu, ::Sidebars::Groups::Menus::EpicsMenu.new(context))
insert_menu_after(::Sidebars::Groups::Menus::MergeRequestsMenu, ::Sidebars::Groups::Menus::SecurityComplianceMenu.new(context))
insert_menu_after(::Sidebars::Groups::Menus::SecurityComplianceMenu, ::Sidebars::Groups::Menus::PushRulesMenu.new(context))
end
end
end
......
# frozen_string_literal: true
module Sidebars
module Groups
module Menus
class PushRulesMenu < ::Sidebars::Menu
override :link
def link
edit_group_push_rules_path(context.group)
end
override :title
def title
_('Push Rules')
end
override :sprite_icon
def sprite_icon
'push-rules'
end
override :render?
def render?
can?(context.current_user, :change_push_rules, context.group)
end
override :active_routes
def active_routes
{ controller: :push_rules }
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::Groups::Menus::PushRulesMenu do
let_it_be(:owner) { create(:user) }
let_it_be(:group) do
build(:group, :private).tap do |g|
g.add_owner(owner)
end
end
let(:user) { owner }
let(:context) { Sidebars::Groups::Context.new(current_user: user, container: group) }
let(:menu) { described_class.new(context) }
describe '#render?' do
context 'when user can change push rules' do
it 'returns true' do
expect(menu.render?).to eq true
end
end
context 'when user cannot change push rules' do
let(:user) { nil }
it 'returns false' do
expect(menu.render?).to eq false
end
end
end
end
......@@ -312,6 +312,17 @@ RSpec.describe 'layouts/nav/sidebar/_group' do
end
end
describe 'Push Rules menu' do
it 'has a link to the push rules list path' do
group.add_owner(user)
allow(view).to receive(:current_user).and_return(user)
render
expect(rendered).to have_link('Push Rules', href: edit_group_push_rules_path(group))
end
end
describe 'DevOps adoption link' do
let!(:current_user) { create(:user) }
......
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