Defect #43526 ยป 0001-Fix-include-and-recent_pages-macros.patch
| app/helpers/application_helper.rb | ||
|---|---|---|
| 459 | 459 |
s = +'' |
| 460 | 460 |
if projects.any? |
| 461 | 461 |
ancestors = [] |
| 462 |
original_project = @project |
|
| 463 | 462 |
projects.sort_by(&:lft).each do |project| |
| 464 |
# set the project environment to please macros. |
|
| 465 |
@project = project |
|
| 466 | 463 |
if ancestors.empty? || project.is_descendant_of?(ancestors.last) |
| 467 | 464 |
s << "<ul class='projects #{ancestors.empty? ? 'root' : nil}'>\n"
|
| 468 | 465 |
else |
| ... | ... | |
| 481 | 478 |
ancestors << project |
| 482 | 479 |
end |
| 483 | 480 |
s << ("</li></ul>\n" * ancestors.size)
|
| 484 |
@project = original_project |
|
| 485 | 481 |
end |
| 486 | 482 |
s.html_safe |
| 487 | 483 |
end |
| app/helpers/projects_helper.rb | ||
|---|---|---|
| 83 | 83 |
s << tag.span(sprite_icon('user', l(:label_my_projects), icon_only: true), class: 'icon-only icon-user my-project') if User.current.member_of?(project)
|
| 84 | 84 |
s << tag.span(sprite_icon('bookmarked', l(:label_my_bookmarks), icon_only: true), class: 'icon-only icon-bookmarked-project') if bookmarked_project_ids.include?(project.id)
|
| 85 | 85 |
if project.description.present? |
| 86 |
s << content_tag('div', textilizable(project.short_description, :project => project), :class => 'wiki description')
|
|
| 86 |
s << content_tag('div', textilizable(project, :short_description, :project => project), :class => 'wiki description')
|
|
| 87 | 87 |
end |
| 88 | 88 |
s |
| 89 | 89 |
end |
| lib/redmine/wiki_formatting/macros.rb | ||
|---|---|---|
| 65 | 65 |
end |
| 66 | 66 |
return [args, options] |
| 67 | 67 |
end |
| 68 | ||
| 69 |
def current_project(obj) |
|
| 70 |
@project || (obj.is_a?(Project) && obj) || (obj.respond_to?(:project) && obj.project) |
|
| 71 |
end |
|
| 68 | 72 |
end |
| 69 | 73 | |
| 70 | 74 |
@@available_macros = {}
|
| ... | ... | |
| 223 | 227 |
"{{recent_pages(time=true)}} -- displays pages updated within the last 7 days with updated time"
|
| 224 | 228 | |
| 225 | 229 |
macro :recent_pages do |obj, args| |
| 226 |
return '' if @project.nil? |
|
| 227 |
return '' unless User.current.allowed_to?(:view_wiki_pages, @project) |
|
| 230 |
project = current_project(obj) |
|
| 231 |
return '' if project.nil? |
|
| 232 |
return '' unless User.current.allowed_to?(:view_wiki_pages, project) |
|
| 228 | 233 | |
| 229 | 234 |
args, options = extract_macro_options(args, :days, :limit, :time) |
| 230 | 235 |
days_to_list = (options[:days].presence || 7).to_i |
| ... | ... | |
| 233 | 238 | |
| 234 | 239 |
pages = WikiPage. |
| 235 | 240 |
joins(:content, :wiki). |
| 236 |
where(["#{Wiki.table_name}.project_id = ? AND #{WikiContent.table_name}.updated_on >= ?", @project.id, days_to_list.days.ago]).
|
|
| 241 |
where(["#{Wiki.table_name}.project_id = ? AND #{WikiContent.table_name}.updated_on >= ?", project.id, days_to_list.days.ago]).
|
|
| 237 | 242 |
order("#{WikiContent.table_name}.updated_on desc, id").
|
| 238 | 243 |
limit(limit) |
| 239 | 244 | |
| ... | ... | |
| 241 | 246 |
pages.each do |page| |
| 242 | 247 |
concat( |
| 243 | 248 |
tag.li do |
| 244 |
html = link_to(h(page.pretty_title), project_wiki_page_path(@project, page.title))
|
|
| 249 |
html = link_to(h(page.pretty_title), project_wiki_page_path(project, page.title)) |
|
| 245 | 250 |
html << " (#{time_ago_in_words(page.content.updated_on)})" if is_show_time
|
| 246 | 251 |
html |
| 247 | 252 |
end |
| ... | ... | |
| 254 | 259 |
"{{include(Foo)}}\n" +
|
| 255 | 260 |
"{{include(projectname:Foo)}} -- to include a page of a specific project wiki"
|
| 256 | 261 |
macro :include do |obj, args| |
| 257 |
page = Wiki.find_page(args.first.to_s, :project => @project) |
|
| 262 |
project = current_project(obj) |
|
| 263 |
page = Wiki.find_page(args.first.to_s, :project => project) |
|
| 258 | 264 |
raise t(:error_page_not_found) if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project) |
| 259 | 265 | |
| 260 | 266 |
@included_wiki_pages ||= [] |
| test/integration/projects_test.rb | ||
|---|---|---|
| 68 | 68 |
assert_select 'td.buttons', text: '' |
| 69 | 69 |
end |
| 70 | 70 |
end |
| 71 | ||
| 72 |
def test_index_should_render_include_macro_in_short_description |
|
| 73 |
project = Project.find(1) |
|
| 74 |
project.update!(:description => '{{include(Another page)}}')
|
|
| 75 | ||
| 76 |
log_user('admin', 'admin')
|
|
| 77 | ||
| 78 |
get '/projects', :params => {:display_type => 'list'}
|
|
| 79 |
assert_response :success |
|
| 80 |
assert_select 'td.short_description div.wiki', :text => /This is a link to a ticket/ |
|
| 81 | ||
| 82 |
get '/projects', :params => {:display_type => ''}
|
|
| 83 |
assert_response :success |
|
| 84 |
assert_select 'div.wiki.description', :text => /This is a link to a ticket/ |
|
| 85 |
end |
|
| 86 | ||
| 87 |
def test_index_should_render_recent_pages_macro_in_short_description |
|
| 88 |
freeze_time do |
|
| 89 |
project = Project.find(1) |
|
| 90 |
project.update!(:description => '{{recent_pages}}')
|
|
| 91 | ||
| 92 |
WikiContent.update_all(updated_on: Time.current) |
|
| 93 |
project.wiki.pages.each_with_index do |page, i| |
|
| 94 |
page.content.update_attribute(:updated_on, (i + 1).days.ago) |
|
| 95 |
end |
|
| 96 | ||
| 97 |
log_user('admin', 'admin')
|
|
| 98 | ||
| 99 |
get '/projects', :params => {:display_type => 'list'}
|
|
| 100 |
assert_response :success |
|
| 101 |
assert_select 'td.short_description div.wiki ul li a', :count => 7 |
|
| 102 |
assert_select 'td.short_description div.wiki ul li:first a', :text => 'Another page' |
|
| 103 | ||
| 104 |
get '/projects', :params => {:display_type => ''}
|
|
| 105 |
assert_response :success |
|
| 106 |
assert_select 'div.wiki.description ul li a', :count => 7 |
|
| 107 |
assert_select 'div.wiki.description ul li:first a', :text => 'Another page' |
|
| 108 |
end |
|
| 109 |
end |
|
| 71 | 110 |
end |
| test/unit/lib/redmine/wiki_formatting/macros_test.rb | ||
|---|---|---|
| 232 | 232 |
assert_include 'Page not found', textilizable(text) |
| 233 | 233 |
end |
| 234 | 234 | |
| 235 |
def test_include_macro_accepts_project_from_multiple_sources |
|
| 236 |
project = Project.find(1) |
|
| 237 | ||
| 238 |
# Resolve using the @project |
|
| 239 |
@project = project |
|
| 240 |
assert_include 'This is a link to a ticket', textilizable('{{include(Another page)}}')
|
|
| 241 |
@project = nil |
|
| 242 | ||
| 243 |
# Resolve using object: project |
|
| 244 |
assert_include 'This is a link to a ticket', textilizable('{{include(Another page)}}', {object: project})
|
|
| 245 | ||
| 246 |
# Resolve using issue.project |
|
| 247 |
issue = Issue.first |
|
| 248 |
issue.update(description: '{{include(Another page)}}')
|
|
| 249 |
assert_include 'This is a link to a ticket', textilizable(issue, :description) |
|
| 250 |
end |
|
| 251 | ||
| 235 | 252 |
def test_macro_collapse |
| 236 | 253 |
text = "{{collapse\n*Collapsed* block of text\n}}"
|
| 237 | 254 |
with_locale 'en' do |
| ... | ... | |
| 517 | 534 |
end |
| 518 | 535 |
end |
| 519 | 536 | |
| 537 |
def test_recent_pages_macro_accepts_project_from_multiple_sources |
|
| 538 |
project = Project.find(1) |
|
| 539 |
freeze_time do |
|
| 540 |
WikiContent.update_all(updated_on: Time.current) |
|
| 541 |
project.wiki.pages.each_with_index do |page, i| |
|
| 542 |
page.content.update_attribute(:updated_on, (i + 1).days.ago) |
|
| 543 |
end |
|
| 544 | ||
| 545 |
with_settings :text_formatting => 'textile' do |
|
| 546 |
results = {}
|
|
| 547 | ||
| 548 |
# Resolve using the @project |
|
| 549 |
@project = project |
|
| 550 |
results[:project_instance_variable] = textilizable('{{recent_pages}}')
|
|
| 551 |
@project = nil |
|
| 552 | ||
| 553 |
# Resolve using object: project |
|
| 554 |
results[:object_project] = textilizable('{{recent_pages}}', {object: project})
|
|
| 555 | ||
| 556 |
# Resolve using issue.project |
|
| 557 |
issue = Issue.first |
|
| 558 |
issue.update(description: '{{recent_pages}}')
|
|
| 559 |
results[:issue_argument] = textilizable(issue, :description) |
|
| 560 | ||
| 561 |
# Assertions |
|
| 562 |
results.each do |key, result| |
|
| 563 |
assert_select_in result, 'ul>li', {:count => 7}, "[#{key}] unexpected number of list items"
|
|
| 564 |
assert_select_in result, 'ul>li:first-of-type', {:text => 'Another page'}, "[#{key}] first list item text mismatch"
|
|
| 565 |
assert_select_in result, 'ul>li:last-of-type', {:text => 'Page with sections'}, "[#{key}] last list item text mismatch"
|
|
| 566 |
end |
|
| 567 |
end |
|
| 568 |
end |
|
| 569 |
end |
|
| 570 | ||
| 520 | 571 |
def test_recent_pages_macro_with_limit_option |
| 521 | 572 |
@project = Project.find(1) |
| 522 | 573 |
freeze_time do |