aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/admin_public_body_controller.rb57
1 files changed, 26 insertions, 31 deletions
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb
index bd85f6eed..8cb7043a0 100644
--- a/app/controllers/admin_public_body_controller.rb
+++ b/app/controllers/admin_public_body_controller.rb
@@ -138,41 +138,36 @@ class AdminPublicBodyController < AdminController
def import_csv
if params[:csv_file]
- if !params[:tag].empty?
- if params['commit'] == 'Dry run'
- dry_run_only = true
- elsif params['commit'] == 'Upload'
- dry_run_only = false
+ if params['commit'] == 'Dry run'
+ dry_run_only = true
+ elsif params['commit'] == 'Upload'
+ dry_run_only = false
+ else
+ raise "internal error, unknown button label"
+ end
+
+ # Try with dry run first
+ csv_contents = params[:csv_file].read
+ en = PublicBody.import_csv(csv_contents, params[:tag], true, admin_http_auth_user(), I18n.available_locales)
+ errors = en[0]
+ notes = en[1]
+
+ if errors.size == 0
+ if dry_run_only
+ notes.push("Dry run was successful, real run would do as above.")
else
- raise "internal error, unknown button label"
- end
-
- # Try with dry run first
- csv_contents = params[:csv_file].read
- en = PublicBody.import_csv(csv_contents, params[:tag], true, admin_http_auth_user(), available_locales)
- errors = en[0]
- notes = en[1]
-
- if errors.size == 0
- if dry_run_only
- notes.push("Dry run was successful, real run would do as above.")
- else
- # And if OK, with real run
- en = PublicBody.import_csv(csv_contents, params[:tag], false, admin_http_auth_user(), I18n.available_locales)
- errors = en[0]
- notes = en[1]
- if errors.size != 0
- raise "dry run mismatched real run"
- end
- notes.push("Import was successful.")
+ # And if OK, with real run
+ en = PublicBody.import_csv(csv_contents, params[:tag], false, admin_http_auth_user(), I18n.available_locales)
+ errors = en[0]
+ notes = en[1]
+ if errors.size != 0
+ raise "dry run mismatched real run"
end
+ notes.push("Import was successful.")
end
- @errors = errors.join("\n")
- @notes = notes.join("\n")
- else
- @errors = "Please enter a tag, use a singular e.g. sea_fishery_committee"
- @notes = ""
end
+ @errors = errors.join("\n")
+ @notes = notes.join("\n")
else
@errors = ""
@notes = ""