Module: NamespacesHelper

Defined in:
app/helpers/namespaces_helper.rb

Instance Method Summary collapse

Instance Method Details

#namespace_icon(namespace, size = 40) ⇒ Object


44
45
46
47
48
49
50
# File 'app/helpers/namespaces_helper.rb', line 44

def namespace_icon(namespace, size = 40)
  if namespace.is_a?(Group)
    group_icon_url(namespace)
  else
    avatar_icon_for_user(namespace.owner, size)
  end
end

#namespace_id_from(params) ⇒ Object


4
5
6
# File 'app/helpers/namespaces_helper.rb', line 4

def namespace_id_from(params)
  params.dig(:project, :namespace_id) || params[:namespace_id]
end

#namespaces_options(selected = :current_user, display_path: false, groups: nil, extra_group: nil, groups_only: false) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/namespaces_helper.rb', line 8

def namespaces_options(selected = :current_user, display_path: false, groups: nil, extra_group: nil, groups_only: false)
  groups ||= current_user.manageable_groups_with_routes
  users = [current_user.namespace]
  selected_id = selected

  unless extra_group.nil? || extra_group.is_a?(Group)
    extra_group = Group.find(extra_group) if Namespace.find(extra_group).kind == 'group'
  end

  if extra_group && extra_group.is_a?(Group)
    extra_group = dedup_extra_group(extra_group)

    if Ability.allowed?(current_user, :read_group, extra_group)
      # Assign the value to an invalid primary ID so that the select box works
      extra_group.id = -1 unless extra_group.persisted?
      selected_id = extra_group.id if selected == :extra_group
      groups |= [extra_group]
    else
      selected_id = current_user.namespace.id
    end
  end

  options = []
  options << options_for_group(groups, display_path: display_path, type: 'group')

  unless groups_only
    options << options_for_group(users, display_path: display_path, type: 'user')

    if selected == :current_user && current_user.namespace
      selected_id = current_user.namespace.id
    end
  end

  grouped_options_for_select(options, selected_id)
end

#namespaces_options_with_developer_maintainer_access(options = {}) ⇒ Object


52
53
54
55
56
57
# File 'app/helpers/namespaces_helper.rb', line 52

def namespaces_options_with_developer_maintainer_access(options = {})
  selected = options.delete(:selected) || :current_user
  options[:groups] = current_user.manageable_groups_with_routes(include_groups_with_developer_maintainer_access: true)

  namespaces_options(selected, options)
end