Module: ProjectsHelper

Defined in:
app/helpers/projects_helper.rb

Instance Method Summary collapse

Instance Method Details

#can_change_visibility_level?(project, current_user) ⇒ Boolean

Returns:

  • (Boolean)

108
109
110
111
112
113
114
115
116
# File 'app/helpers/projects_helper.rb', line 108

def can_change_visibility_level?(project, current_user)
  return false unless can?(current_user, :change_visibility_level, project)

  if project.forked?
    project.forked_from_project.visibility_level > Gitlab::VisibilityLevel::PRIVATE
  else
    true
  end
end

#license_short_name(project) ⇒ Object


126
127
128
129
130
131
132
133
134
135
136
# File 'app/helpers/projects_helper.rb', line 126

def license_short_name(project)
  no_license_key = project.repository.license_key.nil? ||
    # Back-compat if cache contains 'no-license', can be removed in a few weeks
    project.repository.license_key == 'no-license'

  return 'LICENSE' if no_license_key

  license = Licensee::License.new(project.repository.license_key)

  license.nickname || license.name
end

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/projects_helper.rb', line 29

def link_to_member(project, author, opts = {}, &block)
  default_opts = { avatar: true, name: true, size: 16, author_class: 'author', title: ":name" }
  opts = default_opts.merge(opts)

  return "(deleted)" unless author

  author_html =  ""

  # Build avatar image tag
  author_html << image_tag(avatar_icon(author, opts[:size]), width: opts[:size], class: "avatar avatar-inline #{"s#{opts[:size]}" if opts[:size]}", alt:'') if opts[:avatar]

  # Build name span tag
  if opts[:by_username]
    author_html << (:span, sanitize("@#{author.username}"), class: opts[:author_class]) if opts[:name]
  else
    author_html << (:span, sanitize(author.name), class: opts[:author_class]) if opts[:name]
  end

  author_html << capture(&block) if block

  author_html = author_html.html_safe

  if opts[:name]
    link_to(author_html, user_path(author), class: "author_link #{"#{opts[:mobile_classes]}" if opts[:mobile_classes]}").html_safe
  else
    title = opts[:title].sub(":name", sanitize(author.name))
    link_to(author_html, user_path(author), class: "author_link has-tooltip", title: title, data: { container: 'body' } ).html_safe
  end
end

23
24
25
26
27
# File 'app/helpers/projects_helper.rb', line 23

def link_to_member_avatar(author, opts = {})
  default_opts = { avatar: true, name: true, size: 16, author_class: 'author', title: ":name" }
  opts = default_opts.merge(opts)
  image_tag(avatar_icon(author, opts[:size]), width: opts[:size], class: "avatar avatar-inline #{"s#{opts[:size]}" if opts[:size]}", alt:'') if opts[:avatar]
end

10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/projects_helper.rb', line 10

def link_to_project(project)
  link_to [project.namespace.becomes(Namespace), project], title: h(project.name) do
    title = (:span, project.name, class: 'project-name')

    if project.namespace
      namespace = (:span, "#{project.namespace.human_name} / ", class: 'namespace-name')
      title = namespace + title
    end

    title
  end
end

#project_for_deploy_key(deploy_key) ⇒ Object


100
101
102
103
104
105
106
# File 'app/helpers/projects_helper.rb', line 100

def project_for_deploy_key(deploy_key)
  if deploy_key.projects.include?(@project)
    @project
  else
    deploy_key.projects.find { |project| can?(current_user, :read_project, project) }
  end
end

#project_nav_tab?(name) ⇒ Boolean

Returns:

  • (Boolean)

96
97
98
# File 'app/helpers/projects_helper.rb', line 96

def project_nav_tab?(name)
  project_nav_tabs.include? name
end

#project_nav_tabsObject


92
93
94
# File 'app/helpers/projects_helper.rb', line 92

def project_nav_tabs
  @nav_tabs ||= get_project_nav_tabs(@project, current_user)
end

#project_title(project, name = nil, url = nil) ⇒ Object


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/helpers/projects_helper.rb', line 59

def project_title(project, name = nil, url = nil)
  namespace_link =
    if project.group
      link_to(simple_sanitize(project.group.name), group_path(project.group))
    else
      owner = project.namespace.owner
      link_to(simple_sanitize(owner.name), user_path(owner))
    end

  project_link = link_to simple_sanitize(project.name), project_path(project), { class: "project-item-select-holder" }

  if current_user
    project_link << icon("chevron-down", class: "dropdown-toggle-caret js-projects-dropdown-toggle", data: { target: ".js-dropdown-menu-projects", toggle: "dropdown" })
  end

  full_title = "#{namespace_link} / #{project_link}".html_safe
  full_title << ' &middot; '.html_safe << link_to(simple_sanitize(name), url) if name

  full_title
end

#remove_fork_project_message(project) ⇒ Object


88
89
90
# File 'app/helpers/projects_helper.rb', line 88

def remove_fork_project_message(project)
  "You are going to remove the fork relationship to source project #{@project.forked_from_project.name_with_namespace}.  Are you ABSOLUTELY sure?"
end

#remove_from_project_team_message(project, member) ⇒ Object


2
3
4
5
6
7
8
# File 'app/helpers/projects_helper.rb', line 2

def remove_from_project_team_message(project, member)
  if member.user
    "You are going to remove #{member.user.name} from #{project.name} project team. Are you sure?"
  else
    "You are going to revoke the invitation for #{member.invite_email} to join #{project.name} project team. Are you sure?"
  end
end

#remove_project_message(project) ⇒ Object


80
81
82
# File 'app/helpers/projects_helper.rb', line 80

def remove_project_message(project)
  "You are going to remove #{project.name_with_namespace}.\n Removed project CANNOT be restored!\n Are you ABSOLUTELY sure?"
end

#transfer_project_message(project) ⇒ Object


84
85
86
# File 'app/helpers/projects_helper.rb', line 84

def transfer_project_message(project)
  "You are going to transfer #{project.name_with_namespace} to another owner. Are you ABSOLUTELY sure?"
end

#user_max_access_in_project(user_id, project) ⇒ Object


118
119
120
121
122
123
124
# File 'app/helpers/projects_helper.rb', line 118

def user_max_access_in_project(user_id, project)
  level = project.team.max_member_access(user_id)

  if level
    Gitlab::Access.options_with_owner.key(level)
  end
end