summaryrefslogtreecommitdiff
path: root/lib/sidebars/groups/menus
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sidebars/groups/menus')
-rw-r--r--lib/sidebars/groups/menus/customer_relations_menu.rb60
-rw-r--r--lib/sidebars/groups/menus/invite_team_members_menu.rb46
-rw-r--r--lib/sidebars/groups/menus/packages_registries_menu.rb2
3 files changed, 107 insertions, 1 deletions
diff --git a/lib/sidebars/groups/menus/customer_relations_menu.rb b/lib/sidebars/groups/menus/customer_relations_menu.rb
new file mode 100644
index 00000000000..fdbbd662ad6
--- /dev/null
+++ b/lib/sidebars/groups/menus/customer_relations_menu.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+module Sidebars
+ module Groups
+ module Menus
+ class CustomerRelationsMenu < ::Sidebars::Menu
+ override :configure_menu_items
+ def configure_menu_items
+ add_item(contacts_menu_item) if can_read_contact?
+ add_item(organizations_menu_item) if can_read_organization?
+
+ true
+ end
+
+ override :title
+ def title
+ _('Customer relations')
+ end
+
+ override :sprite_icon
+ def sprite_icon
+ 'users'
+ end
+
+ override :render?
+ def render?
+ can_read_contact? || can_read_organization?
+ end
+
+ private
+
+ def contacts_menu_item
+ ::Sidebars::MenuItem.new(
+ title: _('Contacts'),
+ link: contacts_group_crm_index_path(context.group),
+ active_routes: { path: 'groups/crm#contacts' },
+ item_id: :crm_contacts
+ )
+ end
+
+ def organizations_menu_item
+ ::Sidebars::MenuItem.new(
+ title: _('Organizations'),
+ link: organizations_group_crm_index_path(context.group),
+ active_routes: { path: 'groups/crm#organizations' },
+ item_id: :crm_organizations
+ )
+ end
+
+ def can_read_contact?
+ can?(context.current_user, :read_crm_contact, context.group)
+ end
+
+ def can_read_organization?
+ can?(context.current_user, :read_crm_organization, context.group)
+ end
+ end
+ end
+ end
+end
diff --git a/lib/sidebars/groups/menus/invite_team_members_menu.rb b/lib/sidebars/groups/menus/invite_team_members_menu.rb
new file mode 100644
index 00000000000..0779b696061
--- /dev/null
+++ b/lib/sidebars/groups/menus/invite_team_members_menu.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+module Sidebars
+ module Groups
+ module Menus
+ class InviteTeamMembersMenu < ::Sidebars::Menu
+ override :title
+ def title
+ s_('InviteMember|Invite members')
+ end
+
+ override :render?
+ def render?
+ can?(context.current_user, :admin_group_member, context.group) && all_valid_members.size <= 1
+ end
+
+ override :menu_partial
+ def menu_partial
+ 'groups/invite_members_side_nav_link'
+ end
+
+ override :menu_partial_options
+ def menu_partial_options
+ {
+ group: context.group,
+ title: title,
+ sidebar_menu: self
+ }
+ end
+
+ override :extra_nav_link_html_options
+ def extra_nav_link_html_options
+ {
+ 'data-test-id': 'side-nav-invite-members'
+ }
+ end
+
+ private
+
+ def all_valid_members
+ GroupMembersFinder.new(context.group, context.current_user).execute
+ end
+ end
+ end
+ end
+end
diff --git a/lib/sidebars/groups/menus/packages_registries_menu.rb b/lib/sidebars/groups/menus/packages_registries_menu.rb
index e81e9355e7e..46fcec9f7b8 100644
--- a/lib/sidebars/groups/menus/packages_registries_menu.rb
+++ b/lib/sidebars/groups/menus/packages_registries_menu.rb
@@ -52,7 +52,7 @@ module Sidebars
end
def dependency_proxy_menu_item
- unless context.group.dependency_proxy_feature_available?
+ unless can?(context.current_user, :read_dependency_proxy, context.group)
return ::Sidebars::NilMenuItem.new(item_id: :dependency_proxy)
end