groups_helper.rb 1.71 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
  def group_icon(group)
    if group.is_a?(String)
8
      group = Group.find_by_full_path(group)
9 10
    end

11
    group.try(:avatar_url) || image_path('no_group_avatar.png')
12
  end
13

14
  def group_title(group, name = nil, url = nil)
15 16 17 18 19 20 21 22
    full_title = ''

    group.parents.each do |parent|
      full_title += link_to(simple_sanitize(parent.name), group_path(parent))
      full_title += ' / '.html_safe
    end

    full_title += link_to(simple_sanitize(group.name), group_path(group))
23 24
    full_title += ' · '.html_safe + link_to(simple_sanitize(name), url) if name

25
    content_tag :span do
26
      full_title.html_safe
27 28
    end
  end
29

30 31 32 33 34 35 36
  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
37

38 39
    size = group.projects.size

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

47 48 49
  def size_limit_message_for_group(group)
    show_lfs = group.lfs_enabled? ? 'and their respective LFS files' : ''

50
    "Repositories within this group #{show_lfs} will be restricted to this maximum size. Can be overridden inside each project. 0 for unlimited. Leave empty to inherit the global value."
51 52
  end

53
  def group_lfs_status(group)
54 55 56
    status = group.lfs_enabled? ? 'enabled' : 'disabled'

    content_tag(:span, class: "lfs-#{status}") do
57
      "#{status.humanize} #{projects_lfs_status(group)}"
58
    end
59
  end
60 61 62 63

  def group_issues(group)
    IssuesFinder.new(current_user, group_id: group.id).execute
  end
64
end