Browse Source

Adds #current_version? method to wiki content.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7972 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/1.3.0
Jean-Philippe Lang 12 years ago
parent
commit
b8a924e4e1

+ 1
- 1
app/controllers/wiki_controller.rb View File

@@ -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'

+ 10
- 0
app/models/wiki_content.rb View File

@@ -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,

+ 4
- 4
app/views/wiki/show.html.erb View File

@@ -1,19 +1,19 @@
<div class="contextual">
<% 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') %>
</div>

<%= wiki_page_breadcrumb(@page) %>

<% if @content.version != @page.content.version %>
<% unless @content.current_version? %>
<p>
<%= link_to(("\xc2\xab " + l(:label_previous)),
:action => 'show', :id => @page.title, :project_id => @page.project,

+ 24
- 0
test/fixtures/wiki_content_versions.yml View File

@@ -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:

+ 7
- 0
test/unit/wiki_content_test.rb View File

@@ -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

Loading…
Cancel
Save