debian-mirror-gitlab/lib/sidebars/groups/menus/customer_relations_menu.rb

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

63 lines
1.5 KiB
Ruby
Raw Normal View History

2021-12-11 22:18:48 +05:30
# 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?
2022-05-07 20:08:51 +05:30
return false unless context.group.root?
2021-12-11 22:18:48 +05:30
can_read_contact? || can_read_organization?
end
private
def contacts_menu_item
::Sidebars::MenuItem.new(
title: _('Contacts'),
2022-01-26 12:08:38 +05:30
link: group_crm_contacts_path(context.group),
2022-07-23 23:45:48 +05:30
active_routes: { controller: 'groups/crm/contacts' },
2021-12-11 22:18:48 +05:30
item_id: :crm_contacts
)
end
def organizations_menu_item
::Sidebars::MenuItem.new(
title: _('Organizations'),
2022-01-26 12:08:38 +05:30
link: group_crm_organizations_path(context.group),
2022-07-23 23:45:48 +05:30
active_routes: { controller: 'groups/crm/organizations' },
2021-12-11 22:18:48 +05:30
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