Project

General

Profile

Patch #43372 » macro_recent_pages_add_project.patch

Florian Walchshofer, 2025-10-20 23:14

View differences:

lib/redmine/wiki_formatting/macros.rb (working copy)
220 220
             "{{recent_pages}} -- displays pages updated within the last 7 days\n" +
221 221
             "{{recent_pages(days=3)}} -- displays pages updated within the last 3 days\n" +
222 222
             "{{recent_pages(limit=5)}} -- limits the maximum number of pages to display to 5\n" +
223
             "{{recent_pages(time=true)}} -- displays pages updated within the last 7 days with updated time"
223
             "{{recent_pages(time=true)}} -- displays pages updated within the last 7 days with updated time\n" +
224
             "{{recent_pages(project=identifier)}} -- displays pages updated within the last 7 days from a specific project"
224 225

  
225 226
      macro :recent_pages do |obj, args|
226
        return '' if @project.nil?
227
        return '' unless User.current.allowed_to?(:view_wiki_pages, @project)
228

  
229
        args, options = extract_macro_options(args, :days, :limit, :time)
227
        args, options = extract_macro_options(args, :days, :limit, :time, :project)
230 228
        days_to_list = (options[:days].presence || 7).to_i
231 229
        limit = options[:limit].to_i if options[:limit].present?
232 230
        is_show_time = options[:time].to_s == 'true'
231
        project = Project.find_by_identifier(options[:project].to_s) if options[:project].present?
232
        project = @project if project.nil?
233 233

  
234
        return '' if project.nil?
235
        return '' unless User.current.allowed_to?(:view_wiki_pages, project)
236

  
234 237
        pages = WikiPage.
235 238
          joins(:content, :wiki).
236
          where(["#{Wiki.table_name}.project_id = ? AND #{WikiContent.table_name}.updated_on >= ?", @project.id, days_to_list.days.ago]).
239
          where(["#{Wiki.table_name}.project_id = ? AND #{WikiContent.table_name}.updated_on >= ?", project.id, days_to_list.days.ago]).
237 240
          order("#{WikiContent.table_name}.updated_on desc, id").
238 241
          limit(limit)
239 242

  
......
241 244
          pages.each do |page|
242 245
            concat(
243 246
              tag.li do
244
                html = link_to(h(page.pretty_title), project_wiki_page_path(@project, page.title))
247
                html = link_to(h(page.pretty_title), project_wiki_page_path(project, page.title))
245 248
                html << " (#{time_ago_in_words(page.content.updated_on)})" if is_show_time
246 249
                html
247 250
              end
test/unit/lib/redmine/wiki_formatting/macros_test.rb (working copy)
566 566
      end
567 567
    end
568 568
  end
569

  
570
  def test_recent_pages_macro_with_project_option
571
    @project = Project.find(1)
572
    freeze_time do
573
      WikiContent.update_all(updated_on: Time.current)
574
      @project.wiki.pages.each_with_index do |page, i|
575
        page.content.update_attribute(:updated_on, (i + 1).days.ago)
576
      end
577

  
578
      with_settings :text_formatting => 'textile' do
579
        result = textilizable('{{recent_pages(time=true, days=3, project=' + @project.identifier + ')}}')
580
        assert_select_in result, 'ul>li', :count => 3
581
        assert_select_in result, 'ul>li:first-of-type', :text => 'Another page (1 day)'
582
        assert_select_in result, 'ul>li:last-of-type', :text => 'Child 1 1 (3 days)'
583
      end
584
    end
585
  end
569 586
end
(1-1/2)