BigW Consortium Gitlab

groups_helper.rb 1.18 KB
Newer Older
1
module GroupsHelper
2 3 4 5
  def can_change_group_visibility_level?(group)
    can?(current_user, :change_visibility_level, group)
  end

6 7 8 9 10
  def group_icon(group)
    if group.is_a?(String)
      group = Group.find_by(path: group)
    end

11
    if group && group.avatar.present?
12 13
      group.avatar.url
    else
14
      image_path('no_group_avatar.png')
15 16
    end
  end
17

18 19 20 21
  def group_title(group, name = nil, url = nil)
    full_title = link_to(simple_sanitize(group.name), group_path(group))
    full_title += ' · '.html_safe + link_to(simple_sanitize(name), url) if name

22
    content_tag :span do
23
      full_title
24 25
    end
  end
26

27 28 29 30 31 32 33
  def projects_lfs_status(group)
    lfs_status =
      if group.lfs_enabled?
        group.projects.select(&:lfs_enabled?).size
      else
        group.projects.reject(&:lfs_enabled?).size
      end
34

35 36
    size = group.projects.size

37 38
    if lfs_status == size
      'for all projects'
39
    else
40
      "for #{lfs_status} out of #{pluralize(size, 'project')}"
41 42 43 44
    end
  end

  def group_lfs_status(group)
45 46 47
    status = group.lfs_enabled? ? 'enabled' : 'disabled'

    content_tag(:span, class: "lfs-#{status}") do
48
      "#{status.humanize} #{projects_lfs_status(group)}"
49
    end
50
  end
51
end