From b8a924e4e1cb6e73299b8e13b5ee8ec625cda2b7 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 28 Nov 2011 20:12:03 +0000 Subject: [PATCH] Adds #current_version? method to wiki content. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7972 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/wiki_controller.rb | 2 +- app/models/wiki_content.rb | 10 ++++++++++ app/views/wiki/show.html.erb | 8 ++++---- test/fixtures/wiki_content_versions.yml | 24 ++++++++++++++++++++++++ test/unit/wiki_content_test.rb | 7 +++++++ 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 8713e91c4..2f4724f38 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -86,7 +86,7 @@ class WikiController < ApplicationController end @editable = editable? @sections_editable = @editable && User.current.allowed_to?(:edit_wiki_pages, @page.project) && - @content.version == @page.content.version && + @content.current_version? && Redmine::WikiFormatting.supports_section_edit? render :action => 'show' diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb index b1fe60fec..430e9a50e 100644 --- a/app/models/wiki_content.rb +++ b/app/models/wiki_content.rb @@ -45,6 +45,11 @@ class WikiContent < ActiveRecord::Base notified.collect(&:mail) end + # Return true if the content is the current page content + def current_version? + true + end + class Version belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id' belongs_to :author, :class_name => '::User', :foreign_key => 'author_id' @@ -101,6 +106,11 @@ class WikiContent < ActiveRecord::Base page.project end + # Return true if the content is the current page content + def current_version? + page.content.version == self.version + end + # Returns the previous version or nil def previous @previous ||= WikiContent::Version.find(:first, diff --git a/app/views/wiki/show.html.erb b/app/views/wiki/show.html.erb index 22f3bab72..25dfc1062 100644 --- a/app/views/wiki/show.html.erb +++ b/app/views/wiki/show.html.erb @@ -1,19 +1,19 @@
<% if @editable %> -<%= link_to_if_authorized(l(:button_edit), {:action => 'edit', :id => @page.title}, :class => 'icon icon-edit', :accesskey => accesskey(:edit)) if @content.version == @page.content.version %> +<%= link_to_if_authorized(l(:button_edit), {:action => 'edit', :id => @page.title}, :class => 'icon icon-edit', :accesskey => accesskey(:edit)) if @content.current_version? %> <%= watcher_tag(@page, User.current) %> <%= link_to_if_authorized(l(:button_lock), {:action => 'protect', :id => @page.title, :protected => 1}, :method => :post, :class => 'icon icon-lock') if !@page.protected? %> <%= link_to_if_authorized(l(:button_unlock), {:action => 'protect', :id => @page.title, :protected => 0}, :method => :post, :class => 'icon icon-unlock') if @page.protected? %> -<%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :id => @page.title}, :class => 'icon icon-move') if @content.version == @page.content.version %> +<%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :id => @page.title}, :class => 'icon icon-move') if @content.current_version? %> <%= link_to_if_authorized(l(:button_delete), {:action => 'destroy', :id => @page.title}, :method => :delete, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') %> -<%= link_to_if_authorized(l(:button_rollback), {:action => 'edit', :id => @page.title, :version => @content.version }, :class => 'icon icon-cancel') if @content.version < @page.content.version %> +<%= link_to_if_authorized(l(:button_rollback), {:action => 'edit', :id => @page.title, :version => @content.version }, :class => 'icon icon-cancel') unless @content.current_version? %> <% end %> <%= link_to_if_authorized(l(:label_history), {:action => 'history', :id => @page.title}, :class => 'icon icon-history') %>
<%= wiki_page_breadcrumb(@page) %> -<% if @content.version != @page.content.version %> +<% unless @content.current_version? %>

<%= link_to(("\xc2\xab " + l(:label_previous)), :action => 'show', :id => @page.title, :project_id => @page.project, diff --git a/test/fixtures/wiki_content_versions.yml b/test/fixtures/wiki_content_versions.yml index cdfeadd94..e7c0d4832 100644 --- a/test/fixtures/wiki_content_versions.yml +++ b/test/fixtures/wiki_content_versions.yml @@ -64,6 +64,8 @@ wiki_content_versions_005: @WHATEVER@ Maecenas sed elit sit amet mi accumsan vestibulum non nec velit. Proin porta tincidunt lorem, consequat rhoncus dolor fermentum in. + + Cras ipsum felis, ultrices at porttitor vel, faucibus eu nunc. h2. Heading 2 @@ -75,4 +77,26 @@ wiki_content_versions_005: version: 2 author_id: 1 comments: +wiki_content_versions_006: + data: |- + h1. Title + + Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. + + h2. Heading 1 + + @WHATEVER@ + + Maecenas sed elit sit amet mi accumsan vestibulum non nec velit. Proin porta tincidunt lorem, consequat rhoncus dolor fermentum in. + + h2. Heading 2 + + Morbi facilisis accumsan orci non pharetra. + updated_on: 2007-03-08 00:18:07 +01:00 + page_id: 11 + wiki_content_id: 11 + id: 6 + version: 3 + author_id: 1 + comments: diff --git a/test/unit/wiki_content_test.rb b/test/unit/wiki_content_test.rb index 97c6b8ade..4900f48e2 100644 --- a/test/unit/wiki_content_test.rb +++ b/test/unit/wiki_content_test.rb @@ -85,4 +85,11 @@ class WikiContentTest < ActiveSupport::TestCase page.reload assert_equal 500.kilobyte, page.content.text.size end + + def test_current_version + content = WikiContent.find(11) + assert_equal true, content.current_version? + assert_equal true, content.versions.first(:order => 'version DESC').current_version? + assert_equal false, content.versions.first(:order => 'version ASC').current_version? + end end -- 2.39.5