FIX: Import sub-sub-categories (#8810)

This should make the importer more resilient to incomplete or damaged
backups. It will disable some validations and attempt to automatically
repair category permissions before importing.
This commit is contained in:
Dan Ungureanu
2020-01-30 18:46:33 +02:00
committed by GitHub
parent e470b27b41
commit 62b9a432bd
2 changed files with 107 additions and 14 deletions

View File

@ -33,17 +33,43 @@ describe ImportExport::Importer do
.and change { User.count }.by(2)
end
it 'categories and groups' do
data = import_data.dup
data[:topics] = nil
data[:users] = nil
context 'categories and groups' do
it 'works' do
data = import_data.dup
data[:topics] = nil
data[:users] = nil
expect {
import(data)
}.to change { Category.count }.by(6)
.and change { Group.count }.by(2)
.and change { Topic.count }.by(6)
.and change { User.count }.by(0)
expect {
import(data)
}.to change { Category.count }.by(6)
.and change { Group.count }.by(2)
.and change { Topic.count }.by(6)
.and change { User.count }.by(0)
end
it 'works with sub-sub-categories' do
data = import_data.dup
# 11 -> 10 -> 15
data[:categories].find { |c| c[:id] == 10 }[:parent_category_id] = 11
data[:categories].find { |c| c[:id] == 15 }[:parent_category_id] = 10
expect { import(data) }
.to change { Category.count }.by(6)
.and change { SiteSetting.max_category_nesting }.from(2).to(3)
end
it 'fixes permissions' do
data = import_data.dup
data[:categories].find { |c| c[:id] == 10 }[:permissions_params] = { custom_group: 1 }
data[:categories].find { |c| c[:id] == 15 }[:permissions_params] = { staff: 1 }
permissions = data[:categories].find { |c| c[:id] == 10 }[:permissions_params]
expect { import(data) }
.to change { Category.count }.by(6)
.and change { permissions[:staff] }.from(nil).to(1)
end
end
it 'categories, groups and users' do