Module: GitlabReviewable::ReviewsHelper
- Defined in:
- app/helpers/gitlab_reviewable/reviews_helper.rb
Instance Method Summary collapse
- #can_change_visibility_level?(project, current_user) ⇒ Boolean
- #license_short_name(project) ⇒ Object
- #link_to_member(project, author, opts = {}, &block) ⇒ Object
- #link_to_member_avatar(author, opts = {}) ⇒ Object
- #link_to_project(project) ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
- #project_for_deploy_key(deploy_key) ⇒ Object
- #project_nav_tab?(name) ⇒ Boolean
- #project_nav_tabs ⇒ Object
- #project_title(project, name = nil, url = nil) ⇒ Object
- #remove_fork_project_message(project) ⇒ Object
- #remove_from_project_team_message(project, member) ⇒ Object
- #remove_project_message(project) ⇒ Object
- #respond_to?(method) ⇒ Boolean
- #transfer_project_message(project) ⇒ Object
- #user_max_access_in_project(user_id, project) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'app/helpers/gitlab_reviewable/reviews_helper.rb', line 3 def method_missing method, *args, &block if method.to_s.end_with?('_path') or method.to_s.end_with?('_url') if main_app.respond_to?(method) main_app.send(method, *args) else super end else super end end |
Instance Method Details
#can_change_visibility_level?(project, current_user) ⇒ Boolean
133 134 135 136 137 138 139 140 141 |
# File 'app/helpers/gitlab_reviewable/reviews_helper.rb', line 133 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
151 152 153 154 155 156 157 |
# File 'app/helpers/gitlab_reviewable/reviews_helper.rb', line 151 def license_short_name(project) return 'LICENSE' if project.repository.license_key.nil? license = Licensee::License.new(project.repository.license_key) license.nickname || license.name end |
#link_to_member(project, author, opts = {}, &block) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/helpers/gitlab_reviewable/reviews_helper.rb', line 54 def link_to_member(project, , opts = {}, &block) default_opts = { avatar: true, name: true, size: 16, author_class: 'author', title: ":name" } opts = default_opts.merge(opts) return "(deleted)" unless = "" # Build avatar image tag << image_tag(avatar_icon(, 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] << content_tag(:span, sanitize("@#{.username}"), class: opts[:author_class]) if opts[:name] else << content_tag(:span, sanitize(.name), class: opts[:author_class]) if opts[:name] end << capture(&block) if block = .html_safe if opts[:name] link_to(, user_path(), class: "author_link #{"#{opts[:mobile_classes]}" if opts[:mobile_classes]}").html_safe else title = opts[:title].sub(":name", sanitize(.name)) link_to(, user_path(), class: "author_link has-tooltip", title: title, data: { container: 'body' } ).html_safe end end |
#link_to_member_avatar(author, opts = {}) ⇒ Object
48 49 50 51 52 |
# File 'app/helpers/gitlab_reviewable/reviews_helper.rb', line 48 def link_to_member_avatar(, opts = {}) default_opts = { avatar: true, name: true, size: 16, author_class: 'author', title: ":name" } opts = default_opts.merge(opts) image_tag(avatar_icon(, opts[:size]), width: opts[:size], class: "avatar avatar-inline #{"s#{opts[:size]}" if opts[:size]}", alt:'') if opts[:avatar] end |
#link_to_project(project) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/gitlab_reviewable/reviews_helper.rb', line 35 def link_to_project(project) link_to [project.namespace.becomes(Namespace), project], title: h(project.name) do title = content_tag(:span, project.name, class: 'project-name') if project.namespace namespace = content_tag(:span, "#{project.namespace.human_name} / ", class: 'namespace-name') title = namespace + title end title end end |
#project_for_deploy_key(deploy_key) ⇒ Object
125 126 127 128 129 130 131 |
# File 'app/helpers/gitlab_reviewable/reviews_helper.rb', line 125 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
121 122 123 |
# File 'app/helpers/gitlab_reviewable/reviews_helper.rb', line 121 def project_nav_tab?(name) project_nav_tabs.include? name end |
#project_nav_tabs ⇒ Object
117 118 119 |
# File 'app/helpers/gitlab_reviewable/reviews_helper.rb', line 117 def project_nav_tabs @nav_tabs ||= get_project_nav_tabs(@project, current_user) end |
#project_title(project, name = nil, url = nil) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/helpers/gitlab_reviewable/reviews_helper.rb', line 84 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), '#', { 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 << ' · '.html_safe << link_to(simple_sanitize(name), url) if name full_title end |
#remove_fork_project_message(project) ⇒ Object
113 114 115 |
# File 'app/helpers/gitlab_reviewable/reviews_helper.rb', line 113 def (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
27 28 29 30 31 32 33 |
# File 'app/helpers/gitlab_reviewable/reviews_helper.rb', line 27 def (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
105 106 107 |
# File 'app/helpers/gitlab_reviewable/reviews_helper.rb', line 105 def (project) "You are going to remove #{project.name_with_namespace}.\n Removed project CANNOT be restored!\n Are you ABSOLUTELY sure?" end |
#respond_to?(method) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/helpers/gitlab_reviewable/reviews_helper.rb', line 15 def respond_to?(method) if method.to_s.end_with?('_path') or method.to_s.end_with?('_url') if main_app.respond_to?(method) true else super end else super end end |
#transfer_project_message(project) ⇒ Object
109 110 111 |
# File 'app/helpers/gitlab_reviewable/reviews_helper.rb', line 109 def (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
143 144 145 146 147 148 149 |
# File 'app/helpers/gitlab_reviewable/reviews_helper.rb', line 143 def user_max_access_in_project(user_id, project) level = project.team.max_member_access(user_id) if level Gitlab::Access..key(level) end end |