BigW Consortium Gitlab

Commit 5117bf6f by Dmitriy Zaporozhets

Merge branch 'master' of github.com:gitlabhq/gitlabhq

parents 44730133 f881e436
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
avatar = avatar.replace('%{hash}', md5(user.email)) avatar = avatar.replace('%{hash}', md5(user.email))
avatar = avatar.replace('%{size}', '24') avatar = avatar.replace('%{size}', '24')
else else
avatar = gon.relative_url_root + "/assets/no_avatar.png" avatar = gon.relative_url_root + "#{image_path('no_avatar.png')}"
if user.id == '' if user.id == ''
avatarMarkup = '' avatarMarkup = ''
......
...@@ -7,7 +7,7 @@ $ -> ...@@ -7,7 +7,7 @@ $ ->
avatar = avatar.replace('%{hash}', md5(user.email)) avatar = avatar.replace('%{hash}', md5(user.email))
avatar = avatar.replace('%{size}', '24') avatar = avatar.replace('%{size}', '24')
else else
avatar = gon.relative_url_root + "/assets/no_avatar.png" avatar = gon.relative_url_root + "#{image_path('no_avatar.png')}"
"<div class='user-result'> "<div class='user-result'>
<div class='user-image'><img class='avatar s24' src='#{avatar}'></div> <div class='user-image'><img class='avatar s24' src='#{avatar}'></div>
......
...@@ -71,7 +71,7 @@ module ApplicationHelper ...@@ -71,7 +71,7 @@ module ApplicationHelper
size = 40 if size.nil? || size <= 0 size = 40 if size.nil? || size <= 0
if !Gitlab.config.gravatar.enabled || user_email.blank? if !Gitlab.config.gravatar.enabled || user_email.blank?
'/assets/no_avatar.png' image_path('no_avatar.png')
else else
gravatar_url = request.ssl? || gitlab_config.https ? Gitlab.config.gravatar.ssl_url : Gitlab.config.gravatar.plain_url gravatar_url = request.ssl? || gitlab_config.https ? Gitlab.config.gravatar.ssl_url : Gitlab.config.gravatar.plain_url
user_email.strip! user_email.strip!
......
...@@ -19,7 +19,7 @@ module GitlabMarkdownHelper ...@@ -19,7 +19,7 @@ module GitlabMarkdownHelper
escape_once(body) escape_once(body)
end end
gfm_body = gfm(escaped_body, html_options) gfm_body = gfm(escaped_body, @project, html_options)
gfm_body.gsub!(%r{<a.*?>.*?</a>}m) do |match| gfm_body.gsub!(%r{<a.*?>.*?</a>}m) do |match|
"</a>#{match}#{link_to("", url, html_options)[0..-5]}" # "</a>".length +1 "</a>#{match}#{link_to("", url, html_options)[0..-5]}" # "</a>".length +1
......
...@@ -13,76 +13,80 @@ module IssuesHelper ...@@ -13,76 +13,80 @@ module IssuesHelper
OpenStruct.new(id: 0, title: 'None (backlog)', name: 'Unassigned') OpenStruct.new(id: 0, title: 'None (backlog)', name: 'Unassigned')
end end
def url_for_project_issues def url_for_project_issues(project = @project)
return "" if @project.nil? return '' if project.nil?
if @project.used_default_issues_tracker? || !external_issues_tracker_enabled? if project.used_default_issues_tracker? || !external_issues_tracker_enabled?
project_issues_path(@project) project_issues_path(project)
else else
url = Gitlab.config.issues_tracker[@project.issues_tracker]["project_url"] url = Gitlab.config.issues_tracker[project.issues_tracker]['project_url']
url.gsub(':project_id', @project.id.to_s) url.gsub(':project_id', project.id.to_s).
.gsub(':issues_tracker_id', @project.issues_tracker_id.to_s) gsub(':issues_tracker_id', project.issues_tracker_id.to_s)
end end
end end
def url_for_new_issue def url_for_new_issue(project = @project)
return "" if @project.nil? return '' if project.nil?
if @project.used_default_issues_tracker? || !external_issues_tracker_enabled? if project.used_default_issues_tracker? || !external_issues_tracker_enabled?
url = new_project_issue_path project_id: @project url = new_project_issue_path project_id: project
else else
url = Gitlab.config.issues_tracker[@project.issues_tracker]["new_issue_url"] issues_tracker = Gitlab.config.issues_tracker[project.issues_tracker]
url.gsub(':project_id', @project.id.to_s) url = issues_tracker['new_issue_url']
.gsub(':issues_tracker_id', @project.issues_tracker_id.to_s) url.gsub(':project_id', project.id.to_s).
gsub(':issues_tracker_id', project.issues_tracker_id.to_s)
end end
end end
def url_for_issue(issue_iid) def url_for_issue(issue_iid, project = @project)
return "" if @project.nil? return '' if project.nil?
if @project.used_default_issues_tracker? || !external_issues_tracker_enabled? if project.used_default_issues_tracker? || !external_issues_tracker_enabled?
url = project_issue_url project_id: @project, id: issue_iid url = project_issue_url project_id: project, id: issue_iid
else else
url = Gitlab.config.issues_tracker[@project.issues_tracker]["issues_url"] url = Gitlab.config.issues_tracker[project.issues_tracker]['issues_url']
url.gsub(':id', issue_iid.to_s) url.gsub(':id', issue_iid.to_s).
.gsub(':project_id', @project.id.to_s) gsub(':project_id', project.id.to_s).
.gsub(':issues_tracker_id', @project.issues_tracker_id.to_s) gsub(':issues_tracker_id', project.issues_tracker_id.to_s)
end end
end end
def title_for_issue(issue_iid) def title_for_issue(issue_iid, project = @project)
return "" if @project.nil? return '' if project.nil?
if @project.used_default_issues_tracker? && issue = @project.issues.where(iid: issue_iid).first if project.used_default_issues_tracker?
issue.title issue = project.issues.where(iid: issue_iid).first
else return issue.title if issue
""
end end
''
end end
# Checks if issues_tracker setting exists in gitlab.yml # Checks if issues_tracker setting exists in gitlab.yml
def external_issues_tracker_enabled? def external_issues_tracker_enabled?
if Gitlab.config.issues_tracker && Gitlab.config.issues_tracker.values.any? Gitlab.config.issues_tracker && Gitlab.config.issues_tracker.values.any?
true
else
false
end
end end
def bulk_update_milestone_options def bulk_update_milestone_options
options_for_select(["None (backlog)"]) + options_from_collection_for_select(project_active_milestones, "id", "title", params[:milestone_id]) options_for_select(['None (backlog)']) +
options_from_collection_for_select(project_active_milestones, 'id',
'title', params[:milestone_id])
end end
def bulk_update_assignee_options def bulk_update_assignee_options(project = @project)
options_for_select(["None (unassigned)"]) + options_from_collection_for_select(@project.team.members, "id", "name", params[:assignee_id]) options_for_select(['None (unassigned)']) +
options_from_collection_for_select(project.team.members, 'id',
'name', params[:assignee_id])
end end
def assignee_options object def assignee_options(object, project = @project)
options_from_collection_for_select(@project.team.members.sort_by(&:name), 'id', 'name', object.assignee_id) options_from_collection_for_select(project.team.members.sort_by(&:name),
'id', 'name', object.assignee_id)
end end
def milestone_options object def milestone_options object
options_from_collection_for_select(object.project.milestones.active, 'id', 'title', object.milestone_id) options_from_collection_for_select(object.project.milestones.active,
'id', 'title', object.milestone_id)
end end
def issue_box_class(item) def issue_box_class(item)
......
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
.commit-row-title .commit-row-title
= link_to commit[:id][0..8], project_commit_path(project, commit[:id]), class: "commit_short_id", alt: '' = link_to commit[:id][0..8], project_commit_path(project, commit[:id]), class: "commit_short_id", alt: ''
&nbsp; &nbsp;
= gfm event_commit_title(commit[:message]) = gfm event_commit_title(commit[:message]), project
...@@ -26,11 +26,11 @@ ...@@ -26,11 +26,11 @@
- if @merge_request.closed? - if @merge_request.closed?
= link_to 'Reopen', project_merge_request_path(@project, @merge_request, merge_request: {state_event: :reopen }), method: :put, class: "btn btn-grouped btn-reopen reopen-mr-link", title: "Close merge request" = link_to 'Reopen', project_merge_request_path(@project, @merge_request, merge_request: {state_event: :reopen }), method: :put, class: "btn btn-grouped btn-reopen reopen-mr-link", title: "Close merge request"
.notes.tab-content.voting_notes#notes{ class: (controller.action_name == 'show') ? "" : "hide" }
= render "projects/notes/notes_with_form"
.diffs.tab-content .diffs.tab-content
- if current_page?(action: 'diffs') - if current_page?(action: 'diffs')
= render "projects/merge_requests/show/diffs" = render "projects/merge_requests/show/diffs"
.notes.tab-content.voting_notes#notes{ class: (controller.action_name == 'show') ? "" : "hide" }
= render "projects/notes/notes_with_form"
.status .status
:javascript :javascript
......
...@@ -33,10 +33,9 @@ module Gitlab ...@@ -33,10 +33,9 @@ module Gitlab
# Public: Parse the provided text with GitLab-Flavored Markdown # Public: Parse the provided text with GitLab-Flavored Markdown
# #
# text - the source text # text - the source text
# project - extra options for the reference links as given to link_to
# html_options - extra options for the reference links as given to link_to # html_options - extra options for the reference links as given to link_to
# def gfm(text, project = @project, html_options = {})
# Note: reference links will only be generated if @project is set
def gfm(text, html_options = {})
return text if text.nil? return text if text.nil?
# Duplicate the string so we don't alter the original, then call to_str # Duplicate the string so we don't alter the original, then call to_str
...@@ -56,14 +55,19 @@ module Gitlab ...@@ -56,14 +55,19 @@ module Gitlab
# TODO: add popups with additional information # TODO: add popups with additional information
text = parse(text) text = parse(text, project)
# Insert pre block extractions # Insert pre block extractions
text.gsub!(/\{gfm-extraction-(\h{32})\}/) do text.gsub!(/\{gfm-extraction-(\h{32})\}/) do
insert_piece($1) insert_piece($1)
end end
sanitize text.html_safe, attributes: ActionView::Base.sanitized_allowed_attributes + %w(id class), tags: ActionView::Base.sanitized_allowed_tags + %w(table tr td th) allowed_attributes = ActionView::Base.sanitized_allowed_attributes
allowed_tags = ActionView::Base.sanitized_allowed_tags
sanitize text.html_safe,
attributes: allowed_attributes + %w(id class),
tags: allowed_tags + %w(table tr td th)
end end
private private
...@@ -84,11 +88,9 @@ module Gitlab ...@@ -84,11 +88,9 @@ module Gitlab
# #
# text - Text to parse # text - Text to parse
# #
# Note: reference links will only be generated if @project is set
#
# Returns parsed text # Returns parsed text
def parse(text) def parse(text, project = @project)
parse_references(text) if @project parse_references(text, project) if project
parse_emoji(text) parse_emoji(text)
text text
...@@ -110,7 +112,7 @@ module Gitlab ...@@ -110,7 +112,7 @@ module Gitlab
TYPES = [:user, :issue, :merge_request, :snippet, :commit].freeze TYPES = [:user, :issue, :merge_request, :snippet, :commit].freeze
def parse_references(text) def parse_references(text, project = @project)
# parse reference links # parse reference links
text.gsub!(REFERENCE_PATTERN) do |match| text.gsub!(REFERENCE_PATTERN) do |match|
prefix = $~[:prefix] prefix = $~[:prefix]
...@@ -123,7 +125,7 @@ module Gitlab ...@@ -123,7 +125,7 @@ module Gitlab
# Avoid HTML entities # Avoid HTML entities
if prefix && suffix && prefix[0] == '&' && suffix[-1] == ';' if prefix && suffix && prefix[0] == '&' && suffix[-1] == ';'
match match
elsif ref_link = reference_link(type, identifier) elsif ref_link = reference_link(type, identifier, project)
"#{prefix}#{ref_link}#{suffix}" "#{prefix}#{ref_link}#{suffix}"
else else
match match
...@@ -153,7 +155,7 @@ module Gitlab ...@@ -153,7 +155,7 @@ module Gitlab
# #
# Returns boolean # Returns boolean
def valid_emoji?(emoji) def valid_emoji?(emoji)
Emoji.find_by_name emoji Emoji.find_by_name(emoji)
end end
# Private: Dispatches to a dedicated processing method based on reference # Private: Dispatches to a dedicated processing method based on reference
...@@ -162,52 +164,77 @@ module Gitlab ...@@ -162,52 +164,77 @@ module Gitlab
# identifier - Object identifier (Issue ID, SHA hash, etc.) # identifier - Object identifier (Issue ID, SHA hash, etc.)
# #
# Returns string rendered by the processing method # Returns string rendered by the processing method
def reference_link(type, identifier) def reference_link(type, identifier, project = @project)
send("reference_#{type}", identifier) send("reference_#{type}", identifier, project)
end end
def reference_user(identifier) def reference_user(identifier, project = @project)
if user = User.find_by_username(identifier) if user = User.find_by(username: identifier)
link_to("@#{identifier}", user_url(identifier), html_options.merge(class: "gfm gfm-team_member #{html_options[:class]}")) options = html_options.merge(
class: "gfm gfm-team_member #{html_options[:class]}"
)
link_to("@#{identifier}", user_url(identifier), options)
end end
end end
def reference_issue(identifier) def reference_issue(identifier, project = @project)
if @project.used_default_issues_tracker? || !external_issues_tracker_enabled? if project.used_default_issues_tracker? || !external_issues_tracker_enabled?
if @project.issue_exists? identifier if project.issue_exists? identifier
url = url_for_issue(identifier) url = url_for_issue(identifier, project)
title = title_for_issue(identifier) title = title_for_issue(identifier)
options = html_options.merge(
title: "Issue: #{title}",
class: "gfm gfm-issue #{html_options[:class]}"
)
link_to("##{identifier}", url, html_options.merge(title: "Issue: #{title}", class: "gfm gfm-issue #{html_options[:class]}")) link_to("##{identifier}", url, options)
end end
else elsif project.issues_tracker == 'jira'
reference_jira_issue(identifier) if @project.issues_tracker == "jira" reference_jira_issue(identifier, project)
end end
end end
def reference_merge_request(identifier) def reference_merge_request(identifier, project = @project)
if merge_request = @project.merge_requests.where(iid: identifier).first if merge_request = project.merge_requests.find_by(iid: identifier)
link_to("!#{identifier}", project_merge_request_url(@project, merge_request), html_options.merge(title: "Merge Request: #{merge_request.title}", class: "gfm gfm-merge_request #{html_options[:class]}")) options = html_options.merge(
title: "Merge Request: #{merge_request.title}",
class: "gfm gfm-merge_request #{html_options[:class]}"
)
url = project_merge_request_url(project, merge_request)
link_to("!#{identifier}", url, options)
end end
end end
def reference_snippet(identifier) def reference_snippet(identifier, project = @project)
if snippet = @project.snippets.where(id: identifier).first if snippet = project.snippets.find_by(id: identifier)
link_to("$#{identifier}", project_snippet_url(@project, snippet), html_options.merge(title: "Snippet: #{snippet.title}", class: "gfm gfm-snippet #{html_options[:class]}")) options = html_options.merge(
title: "Snippet: #{snippet.title}",
class: "gfm gfm-snippet #{html_options[:class]}"
)
link_to("$#{identifier}", project_snippet_url(project, snippet),
options)
end end
end end
def reference_commit(identifier) def reference_commit(identifier, project = @project)
if @project.valid_repo? && commit = @project.repository.commit(identifier) if project.valid_repo? && commit = project.repository.commit(identifier)
link_to(identifier, project_commit_url(@project, commit), html_options.merge(title: commit.link_title, class: "gfm gfm-commit #{html_options[:class]}")) options = html_options.merge(
title: commit.link_title,
class: "gfm gfm-commit #{html_options[:class]}"
)
link_to(identifier, project_commit_url(project, commit), options)
end end
end end
def reference_jira_issue(identifier) def reference_jira_issue(identifier, project = @project)
url = url_for_issue(identifier) url = url_for_issue(identifier)
title = Gitlab.config.issues_tracker[@project.issues_tracker]["title"] title = Gitlab.config.issues_tracker[@project.issues_tracker]["title"]
link_to("#{identifier}", url, html_options.merge(title: "Issue in #{title}", class: "gfm gfm-issue #{html_options[:class]}")) options = html_options.merge(
title: "Issue in #{title}",
class: "gfm gfm-issue #{html_options[:class]}"
)
link_to("#{identifier}", url, options)
end end
end end
end end
...@@ -51,7 +51,7 @@ module Gitlab ...@@ -51,7 +51,7 @@ module Gitlab
private private
def reference_link type, identifier def reference_link(type, identifier, project)
# Append identifier to the appropriate collection. # Append identifier to the appropriate collection.
send("#{type}s") << identifier send("#{type}s") << identifier
end end
......
...@@ -79,11 +79,11 @@ describe ApplicationHelper do ...@@ -79,11 +79,11 @@ describe ApplicationHelper do
it "should return a generic avatar path when Gravatar is disabled" do it "should return a generic avatar path when Gravatar is disabled" do
Gitlab.config.gravatar.stub(:enabled).and_return(false) Gitlab.config.gravatar.stub(:enabled).and_return(false)
gravatar_icon(user_email).should == '/assets/no_avatar.png' gravatar_icon(user_email).should match('no_avatar.png')
end end
it "should return a generic avatar path when email is blank" do it "should return a generic avatar path when email is blank" do
gravatar_icon('').should == '/assets/no_avatar.png' gravatar_icon('').should match('no_avatar.png')
end end
it "should return default gravatar url" do it "should return default gravatar url" do
......
...@@ -41,7 +41,8 @@ describe GitlabMarkdownHelper do ...@@ -41,7 +41,8 @@ describe GitlabMarkdownHelper do
end end
it "should forward HTML options to links" do it "should forward HTML options to links" do
gfm("Fixed in #{commit.id}", class: "foo").should have_selector("a.gfm.foo") gfm("Fixed in #{commit.id}", @project, class: 'foo').
should have_selector('a.gfm.foo')
end end
describe "referencing a commit" do describe "referencing a commit" do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment