Feature #16410 » 16410.patch
| app/models/wiki_page.rb | ||
|---|---|---|
|
:permission => :view_wiki_pages,
|
||
|
:project_key => "#{Wiki.table_name}.project_id"
|
||
|
attr_accessor :redirect_existing_links
|
||
|
attr_accessor :redirect_existing_links, :deleted_attachment_ids
|
||
|
validates_presence_of :title
|
||
|
validates_format_of :title, :with => /\A[^,\.\/\?\;\|\s]*\z/
|
||
| ... | ... | |
|
validate :validate_parent_title
|
||
|
before_destroy :delete_redirects
|
||
|
before_save :handle_rename_or_move, :update_wiki_start_page
|
||
|
after_save :handle_children_move
|
||
|
after_save :handle_children_move, :delete_selected_attachments
|
||
|
# eager load information about last updates, without loading text
|
||
|
scope :with_updated_on, lambda { preload(:content_without_text) }
|
||
| ... | ... | |
|
safe_attributes 'is_start_page',
|
||
|
:if => lambda {|page, user| user.allowed_to?(:manage_wiki, page.project)}
|
||
|
safe_attributes 'deleted_attachment_ids',
|
||
|
:if => lambda {|page, user| page.attachments_deletable?(user)}
|
||
|
def initialize(attributes=nil, *args)
|
||
|
super
|
||
|
if new_record? && DEFAULT_PROTECTED_PAGES.include?(title.to_s.downcase)
|
||
| ... | ... | |
|
ret
|
||
|
end
|
||
|
def deleted_attachment_ids
|
||
|
Array(@deleted_attachment_ids).map(&:to_i)
|
||
|
end
|
||
|
def delete_selected_attachments
|
||
|
if deleted_attachment_ids.present?
|
||
|
objects = attachments.where(:id => deleted_attachment_ids.map(&:to_i))
|
||
|
attachments.delete(objects)
|
||
|
end
|
||
|
end
|
||
|
protected
|
||
|
def validate_parent_title
|
||
| app/views/wiki/edit.html.erb | ||
|---|---|---|
|
<% end %>
|
||
|
<p><label><%= l(:field_comments) %></label><%= f.text_field :comments, :size => 120, :maxlength => 1024 %></p>
|
||
|
<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
|
||
|
<fieldset>
|
||
|
<legend><%=l(:label_attachment_plural)%></legend>
|
||
|
<% if @page.attachments.any? && @page.safe_attribute?('deleted_attachment_ids') %>
|
||
|
<div class="contextual"><%= link_to l(:label_edit_attachments), '#', :onclick => "$('#existing-attachments').toggle(); return false;" %></div>
|
||
|
<div id="existing-attachments" style="<%= @page.deleted_attachment_ids.blank? ? 'display:none;' : '' %>">
|
||
|
<% @page.attachments.each do |attachment| %>
|
||
|
<span class="existing-attachment">
|
||
|
<%= text_field_tag '', attachment.filename, :class => "icon icon-attachment filename", :disabled => true %>
|
||
|
<label class='inline'>
|
||
|
<%= check_box_tag 'wiki_page[deleted_attachment_ids][]',
|
||
|
attachment.id,
|
||
|
@page.deleted_attachment_ids.include?(attachment.id),
|
||
|
:id => nil, :class => "deleted_attachment" %> <%= l(:button_delete) %>
|
||
|
</label>
|
||
|
</span>
|
||
|
<% end %>
|
||
|
<hr />
|
||
|
</div>
|
||
|
<% end %>
|
||
|
<div id="new-attachments" style="display:inline-block;">
|
||
|
<%= render :partial => 'attachments/form' %>
|
||
|
</div>
|
||
|
</fieldset>
|
||
|
</div>
|
||
|
<p>
|
||
| test/functional/wiki_controller_test.rb | ||
|---|---|---|
|
assert_equal 1, page.content.version
|
||
|
end
|
||
|
def test_update_with_deleted_attachment_ids
|
||
|
@request.session[:user_id] = 2
|
||
|
page = WikiPage.find(4)
|
||
|
attachment = page.attachments.first
|
||
|
assert_difference 'Attachment.count', -1 do
|
||
|
put :update, :params => {
|
||
|
:project_id => page.wiki.project.id,
|
||
|
:id => page.title,
|
||
|
:content => {
|
||
|
:comments => 'delete file', # failure here, comment is too long
|
||
|
:text => 'edited'
|
||
|
},
|
||
|
:wiki_page => {:deleted_attachment_ids => [attachment.id]}
|
||
|
}
|
||
|
end
|
||
|
page.reload
|
||
|
refute_includes page.attachments, attachment
|
||
|
end
|
||
|
def test_update_with_deleted_attachment_ids_and_failure_should_preserve_selected_attachments
|
||
|
@request.session[:user_id] = 2
|
||
|
page = WikiPage.find(4)
|
||
|
attachment = page.attachments.first
|
||
|
assert_no_difference 'Attachment.count' do
|
||
|
put :update, :params => {
|
||
|
:project_id => page.wiki.project.id,
|
||
|
:id => page.title,
|
||
|
:content => {
|
||
|
:comments => 'a' * 1300, # failure here, comment is too long
|
||
|
:text => 'edited'
|
||
|
},
|
||
|
:wiki_page => {:deleted_attachment_ids => [attachment.id]}
|
||
|
}
|
||
|
end
|
||
|
page.reload
|
||
|
assert_includes page.attachments, attachment
|
||
|
end
|
||
|
def test_update_stale_page_should_not_raise_an_error
|
||
|
@request.session[:user_id] = 2
|
||
|
c = Wiki.find(1).find_page('Another_page').content
|
||
- « Previous
- 1
- 2
- 3
- Next »