Fix account creation and import updates

This commit is contained in:
Stanko K.R.
2026-01-29 11:31:30 +01:00
parent b97934ff48
commit 0452d243e1
2 changed files with 16 additions and 20 deletions
+14 -18
View File
@@ -1,5 +1,5 @@
class ImportsController < ApplicationController class ImportsController < ApplicationController
disallow_account_scope disallow_account_scope only: %i[ new create ]
layout "public" layout "public"
@@ -7,32 +7,28 @@ class ImportsController < ApplicationController
end end
def create def create
account = create_account_for_import signup = Signup.new(identity: Current.identity, full_name: "Import", skip_account_seeding: true)
Current.set(account: account) do if signup.complete
@import = account.imports.create!(identity: Current.identity, file: params[:file]) start_import(signup.account)
else
render :new, alert: "Couldn't create account."
end end
@import.perform_later
redirect_to import_path(@import)
end end
def show def show
@import = Current.identity.imports.find(params[:id]) @import = Current.account.imports.find(params[:id])
end end
private private
def create_account_for_import def start_import(account)
Account.create_with_owner( import = nil
account: { name: account_name_from_zip },
owner: { name: Current.identity.email_address.split("@").first, identity: Current.identity }
)
end
def account_name_from_zip Current.set(account: account) do
Zip::File.open(params[:file].tempfile.path) do |zip| import = account.imports.create!(identity: Current.identity, file: params[:file])
entry = zip.find_entry("data/account.json") import.process_later
JSON.parse(entry.get_input_stream.read)["name"]
end end
redirect_to import_path(import, script_name: account.slug)
end end
end end
+2 -2
View File
@@ -3,7 +3,7 @@ class Signup
include ActiveModel::Attributes include ActiveModel::Attributes
include ActiveModel::Validations include ActiveModel::Validations
attr_accessor :full_name, :email_address, :identity attr_accessor :full_name, :email_address, :identity, :skip_account_seeding
attr_reader :account, :user attr_reader :account, :user
validates :email_address, format: { with: URI::MailTo::EMAIL_REGEXP }, on: :identity_creation validates :email_address, format: { with: URI::MailTo::EMAIL_REGEXP }, on: :identity_creation
@@ -65,7 +65,7 @@ class Signup
} }
) )
@user = @account.users.find_by!(role: :owner) @user = @account.users.find_by!(role: :owner)
@account.setup_customer_template @account.setup_customer_template unless skip_account_seeding
end end
def generate_account_name def generate_account_name