Commit 62fadc74 authored by huzaifaiftikhar1's avatar huzaifaiftikhar1

Use policy to decide when deleted projects tab should be visible

Split the projects_submenu method into two so that it can be
easily extended for EE.
parent 730286e5
...@@ -103,7 +103,7 @@ module Nav ...@@ -103,7 +103,7 @@ module Nav
shortcut_href: dashboard_projects_path, shortcut_href: dashboard_projects_path,
**projects_menu_item_attrs **projects_menu_item_attrs
) )
builder.add_view(PROJECTS_VIEW, container_view_props(namespace: 'projects', current_item: current_item, submenu: projects_submenu(::Gitlab::Nav::TopNavMenuBuilder.new))) builder.add_view(PROJECTS_VIEW, container_view_props(namespace: 'projects', current_item: current_item, submenu: projects_submenu))
end end
if dashboard_nav_link?(:groups) if dashboard_nav_link?(:groups)
...@@ -252,14 +252,19 @@ module Nav ...@@ -252,14 +252,19 @@ module Nav
} }
end end
def projects_submenu(builder, should_build = true) def projects_submenu
builder = ::Gitlab::Nav::TopNavMenuBuilder.new
projects_submenu_items(builder: builder)
builder.build
end
def projects_submenu_items(builder:)
# These project links come from `app/views/layouts/nav/projects_dropdown/_show.html.haml` # These project links come from `app/views/layouts/nav/projects_dropdown/_show.html.haml`
builder.add_primary_menu_item(id: 'your', title: _('Your projects'), href: dashboard_projects_path) builder.add_primary_menu_item(id: 'your', title: _('Your projects'), href: dashboard_projects_path)
builder.add_primary_menu_item(id: 'starred', title: _('Starred projects'), href: starred_dashboard_projects_path) builder.add_primary_menu_item(id: 'starred', title: _('Starred projects'), href: starred_dashboard_projects_path)
builder.add_primary_menu_item(id: 'explore', title: _('Explore projects'), href: explore_root_path) builder.add_primary_menu_item(id: 'explore', title: _('Explore projects'), href: explore_root_path)
builder.add_primary_menu_item(id: 'topics', title: _('Explore topics'), href: topics_explore_projects_path) builder.add_primary_menu_item(id: 'topics', title: _('Explore topics'), href: topics_explore_projects_path)
builder.add_secondary_menu_item(id: 'create', title: _('Create new project'), href: new_project_path) builder.add_secondary_menu_item(id: 'create', title: _('Create new project'), href: new_project_path)
builder.build if should_build
end end
def groups_submenu def groups_submenu
......
...@@ -41,7 +41,7 @@ module EE ...@@ -41,7 +41,7 @@ module EE
end end
def check_adjourned_deletion_listing_availability def check_adjourned_deletion_listing_availability
return render_404 unless License.feature_available?(:adjourned_deletion_for_projects_and_groups) return render_404 unless can?(current_user, :list_removable_projects)
end end
def finder_params_for_removed def finder_params_for_removed
......
...@@ -51,15 +51,13 @@ module EE ...@@ -51,15 +51,13 @@ module EE
end end
end end
override :projects_submenu override :projects_submenu_items
def projects_submenu(builder, should_build = true) def projects_submenu_items(builder:)
super(builder, false) super
if License.feature_available?(:adjourned_deletion_for_projects_and_groups) if License.feature_available?(:adjourned_deletion_for_projects_and_groups)
builder.add_primary_menu_item(id: 'deleted', title: _('Deleted projects'), href: removed_dashboard_projects_path) builder.add_primary_menu_item(id: 'deleted', title: _('Deleted projects'), href: removed_dashboard_projects_path)
end end
builder.build if should_build
end end
end end
end end
......
...@@ -13,6 +13,10 @@ module EE ...@@ -13,6 +13,10 @@ module EE
License.feature_available?(:pages_size_limit) License.feature_available?(:pages_size_limit)
end end
condition(:adjourned_project_deletion_available) do
License.feature_available?(:adjourned_deletion_for_projects_and_groups)
end
condition(:export_user_permissions_available) do condition(:export_user_permissions_available) do
::License.feature_available?(:export_user_permissions) ::License.feature_available?(:export_user_permissions)
end end
...@@ -53,6 +57,10 @@ module EE ...@@ -53,6 +57,10 @@ module EE
prevent :create_group_with_default_branch_protection prevent :create_group_with_default_branch_protection
end end
rule { adjourned_project_deletion_available }.policy do
enable :list_removable_projects
end
rule { export_user_permissions_available & admin }.enable :export_user_permissions rule { export_user_permissions_available & admin }.enable :export_user_permissions
rule { can?(:create_group) }.enable :create_group_via_api rule { can?(:create_group) }.enable :create_group_via_api
......
- if License.feature_available?(:adjourned_deletion_for_projects_and_groups) - if can?(current_user, :list_removable_projects)
= gl_tab_link_to removed_dashboard_projects_path, { data: { placement: 'right' } } do = gl_tab_link_to removed_dashboard_projects_path, { data: { placement: 'right' } } do
= _("Pending deletion") = _("Pending deletion")
= gl_tab_counter_badge(limited_counter_with_delimiter(removed_projects_count)) = gl_tab_counter_badge(limited_counter_with_delimiter(removed_projects_count))
- if License.feature_available?(:adjourned_deletion_for_projects_and_groups) && scheduled_for_deletion?(project) - if can?(current_user, :list_removable_projects) && scheduled_for_deletion?(project)
.gl-display-flex.gl-align-items-center.gl-flex-wrap.project-title .gl-display-flex.gl-align-items-center.gl-flex-wrap.project-title
%span.small %span.small
= _("Marked For Deletion At - %{deletion_time}") % { deletion_time: project.marked_for_deletion_at.strftime(Date::DATE_FORMATS[:medium]) } = _("Marked For Deletion At - %{deletion_time}") % { deletion_time: project.marked_for_deletion_at.strftime(Date::DATE_FORMATS[:medium]) }
......
...@@ -199,6 +199,48 @@ RSpec.describe GlobalPolicy do ...@@ -199,6 +199,48 @@ RSpec.describe GlobalPolicy do
end end
end end
describe 'list_removable_projects' do
context 'when user is an admin', :enable_admin_mode do
let_it_be(:current_user) { admin }
before do
stub_licensed_features(adjourned_deletion_for_projects_and_groups: licensed?)
end
context 'when licensed feature is enabled' do
let(:licensed?) { true }
it { is_expected.to be_allowed(:list_removable_projects) }
end
context 'when licensed feature is not enabled' do
let(:licensed?) { false }
it { is_expected.to be_disallowed(:list_removable_projects) }
end
end
context 'when user is a normal user' do
let_it_be(:current_user) { create(:user) }
before do
stub_licensed_features(adjourned_deletion_for_projects_and_groups: licensed?)
end
context 'when licensed feature is enabled' do
let(:licensed?) { true }
it { is_expected.to be_allowed(:list_removable_projects) }
end
context 'when licensed feature is not enabled' do
let(:licensed?) { false }
it { is_expected.to be_disallowed(:list_removable_projects) }
end
end
end
describe ':export_user_permissions', :enable_admin_mode do describe ':export_user_permissions', :enable_admin_mode do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
......
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