debian-mirror-gitlab/lib/sidebars/projects/menus/settings_menu.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

173 lines
5.3 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
module Sidebars
module Projects
module Menus
class SettingsMenu < ::Sidebars::Menu
override :configure_menu_items
def configure_menu_items
return false unless can?(context.current_user, :admin_project, context.project)
add_item(general_menu_item)
add_item(integrations_menu_item)
add_item(webhooks_menu_item)
add_item(access_tokens_menu_item)
add_item(repository_menu_item)
2022-10-11 01:57:18 +05:30
add_item(merge_requests_menu_item)
2021-06-08 01:23:25 +05:30
add_item(ci_cd_menu_item)
add_item(packages_and_registries_menu_item)
2023-03-17 16:20:25 +05:30
if Feature.disabled?(:show_pages_in_deployments_menu, context.current_user, type: :experiment)
add_item(pages_menu_item)
end
2022-07-16 23:28:13 +05:30
add_item(monitor_menu_item)
2021-11-11 11:23:49 +05:30
add_item(usage_quotas_menu_item)
2021-06-08 01:23:25 +05:30
true
end
override :title
def title
_('Settings')
end
override :title_html_options
def title_html_options
{
id: 'js-onboarding-settings-link'
}
end
override :sprite_icon
def sprite_icon
'settings'
end
private
def general_menu_item
::Sidebars::MenuItem.new(
title: _('General'),
link: edit_project_path(context.project),
active_routes: { path: 'projects#edit' },
item_id: :general
)
end
def integrations_menu_item
::Sidebars::MenuItem.new(
title: _('Integrations'),
link: project_settings_integrations_path(context.project),
2022-07-23 23:45:48 +05:30
active_routes: { path: %w[integrations#index integrations#edit] },
2021-06-08 01:23:25 +05:30
item_id: :integrations
)
end
def webhooks_menu_item
::Sidebars::MenuItem.new(
title: _('Webhooks'),
link: project_hooks_path(context.project),
active_routes: { path: %w[hooks#index hooks#edit hook_logs#show] },
item_id: :webhooks
)
end
def access_tokens_menu_item
unless can?(context.current_user, :read_resource_access_tokens, context.project)
return ::Sidebars::NilMenuItem.new(item_id: :access_tokens)
end
::Sidebars::MenuItem.new(
title: _('Access Tokens'),
link: project_settings_access_tokens_path(context.project),
active_routes: { path: 'access_tokens#index' },
item_id: :access_tokens
)
end
def repository_menu_item
::Sidebars::MenuItem.new(
title: _('Repository'),
link: project_settings_repository_path(context.project),
active_routes: { path: 'repository#show' },
item_id: :repository
)
end
def ci_cd_menu_item
if context.project.archived? || !context.project.feature_available?(:builds, context.current_user)
return ::Sidebars::NilMenuItem.new(item_id: :ci_cd)
end
::Sidebars::MenuItem.new(
title: _('CI/CD'),
link: project_settings_ci_cd_path(context.project),
active_routes: { path: 'ci_cd#show' },
item_id: :ci_cd
)
end
2022-07-16 23:28:13 +05:30
def packages_and_registries_menu_item
2022-07-23 23:45:48 +05:30
unless can?(context.current_user, :view_package_registry_project_settings, context.project)
2022-07-16 23:28:13 +05:30
return ::Sidebars::NilMenuItem.new(item_id: :packages_and_registries)
2021-06-08 01:23:25 +05:30
end
::Sidebars::MenuItem.new(
2022-10-11 01:57:18 +05:30
title: _('Packages and registries'),
2022-07-16 23:28:13 +05:30
link: project_settings_packages_and_registries_path(context.project),
2022-10-11 01:57:18 +05:30
active_routes: { controller: :packages_and_registries },
2022-07-16 23:28:13 +05:30
item_id: :packages_and_registries
2021-06-08 01:23:25 +05:30
)
end
def pages_menu_item
unless context.project.pages_available?
return ::Sidebars::NilMenuItem.new(item_id: :pages)
end
::Sidebars::MenuItem.new(
title: _('Pages'),
link: project_pages_path(context.project),
active_routes: { path: 'pages#show' },
item_id: :pages
)
end
2022-07-16 23:28:13 +05:30
def monitor_menu_item
if context.project.archived? || !can?(context.current_user, :admin_operations, context.project)
return ::Sidebars::NilMenuItem.new(item_id: :monitor)
2021-06-08 01:23:25 +05:30
end
::Sidebars::MenuItem.new(
2022-07-16 23:28:13 +05:30
title: _('Monitor'),
link: project_settings_operations_path(context.project),
active_routes: { path: 'operations#show' },
item_id: :monitor
2021-06-08 01:23:25 +05:30
)
end
2021-11-11 11:23:49 +05:30
def usage_quotas_menu_item
::Sidebars::MenuItem.new(
title: s_('UsageQuota|Usage Quotas'),
link: project_usage_quotas_path(context.project),
active_routes: { path: 'usage_quotas#index' },
item_id: :usage_quotas
)
end
2022-10-11 01:57:18 +05:30
def merge_requests_menu_item
return unless context.project.merge_requests_enabled?
::Sidebars::MenuItem.new(
title: _('Merge requests'),
link: project_settings_merge_requests_path(context.project),
active_routes: { path: 'projects/settings/merge_requests#show' },
item_id: :merge_requests
)
end
2021-06-08 01:23:25 +05:30
end
end
end
end