-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Journalize the deletion of Wiki Pages
- Loading branch information
Showing
6 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require_dependency 'wiki_controller' | ||
|
||
class WikiController | ||
include RedmineAdminActivity::Journalizable | ||
|
||
after_action :journalized_wiki_page_deletion, :only => [:destroy] | ||
before_action :self_and_descendants, :only => [:destroy] | ||
|
||
def self_and_descendants | ||
@self_and_descendants = [@page] # case of leaf page, or page without children, or page with children and params[:todo] = nullify or reassign | ||
@self_and_descendants += @page.descendants.to_a if params[:todo].present? && params[:todo] == 'destroy' | ||
end | ||
|
||
def journalized_wiki_page_deletion | ||
return unless @page.present? && @page.destroyed? | ||
|
||
@self_and_descendants.each do |wiki| | ||
|
||
add_wiki_page_journal_entry(project: wiki.project, | ||
value: nil, | ||
old_value: wiki.title) | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
require 'spec_helper' | ||
|
||
describe WikiController, type: :controller do | ||
|
||
render_views | ||
|
||
fixtures :projects, :users, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :journals, :journal_details | ||
|
||
include Redmine::I18n | ||
|
||
before do | ||
@controller = WikiController.new | ||
@request = ActionDispatch::TestRequest.create | ||
@response = ActionDispatch::TestResponse.new | ||
User.current = nil | ||
@request.session[:user_id] = 1 #permissions are hard | ||
end | ||
|
||
let(:project) { projects(:projects_001) } | ||
let(:parent_page) { wiki_pages(:wiki_pages_002) } | ||
|
||
describe "DELETE destroy, logs change on Journal and JournalDetail" do | ||
|
||
it "When we delete a page without children" do | ||
wiki_title = WikiPage.find(6).title | ||
|
||
expect do | ||
delete :destroy, :params => { :project_id => project.id, :id => wiki_title } | ||
end.to change { Journal.count }.by(1) | ||
.and change { JournalDetail.count }.by(1) | ||
.and change { WikiPage.count }.by(-1) | ||
|
||
expect(JournalDetail.last.old_value).to eq(wiki_title) | ||
expect(JournalDetail.last.prop_key).to eq("wiki_page") | ||
expect(JournalDetail.last.property).to eq("wiki_page") | ||
expect(Journal.last.journalized).to eq(project) | ||
end | ||
|
||
it "When we delete a parent page with option nullify" do | ||
expect do | ||
delete :destroy, :params => {:project_id => project.id, :id => parent_page.title, :todo => 'nullify'} | ||
end.to change { Journal.count }.by(1) | ||
.and change { JournalDetail.count }.by(1) | ||
.and change { WikiPage.count }.by(-1) | ||
|
||
expect(JournalDetail.last.old_value).to eq(parent_page.title) | ||
expect(JournalDetail.last.prop_key).to eq("wiki_page") | ||
expect(JournalDetail.last.property).to eq("wiki_page") | ||
expect(Journal.last.journalized).to eq(project) | ||
end | ||
|
||
it "When we delete a parent page with option destroy cascade" do | ||
total_size = parent_page.descendants.size + 1 | ||
|
||
expect do | ||
delete :destroy, :params => {:project_id => project.id, :id => parent_page.title, :todo => 'destroy'} | ||
end.to change { Journal.count }.by(total_size) | ||
.and change { JournalDetail.count }.by(total_size) | ||
.and change { WikiPage.count }.by(-total_size) | ||
end | ||
it "When we delete a parent page with option reassign" do | ||
expect do | ||
delete :destroy, :params => {:project_id => project.id, :id => parent_page.title, :todo => 'reassign', :reassign_to_id => 1 } | ||
end.to change { Journal.count }.by(1) | ||
.and change { JournalDetail.count }.by(1) | ||
.and change { WikiPage.count }.by(-1) | ||
|
||
expect(JournalDetail.last.old_value).to eq(parent_page.title) | ||
expect(JournalDetail.last.prop_key).to eq("wiki_page") | ||
expect(JournalDetail.last.property).to eq("wiki_page") | ||
expect(Journal.last.journalized).to eq(project) | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters