diff --git a/forms/admin_menu.rb b/forms/admin_menu.rb index 2d46719ec9fe711110add8316e25e7f84da8a368..01e1738e52d21a7769bd7d0878d74f93d8e087b0 100644 --- a/forms/admin_menu.rb +++ b/forms/admin_menu.rb @@ -24,6 +24,7 @@ field( { value: "set_trust_level", label: "Set Trust Level" }, { value: "add_invites", label: "Add Referral Codes" }, { value: "number_change", label: "Number Change" }, - { value: "add_transaction", label: "Add Transaction" } + { value: "add_transaction", label: "Add Transaction" }, + { value: "launch_snikket", label: "Launch Snikket" } ] ) diff --git a/lib/admin_actions/launch_snikket.rb b/lib/admin_actions/launch_snikket.rb new file mode 100644 index 0000000000000000000000000000000000000000..ccd240cd0b2fe40d7c73d489b3289809a91ef07d --- /dev/null +++ b/lib/admin_actions/launch_snikket.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class AdminAction + class LaunchSnikket + def self.call(customer_id, reply:, snikket_repo:, **) + reply.call( + FormTemplate.render("snikket_launch") + ).then { |response| + domain = response.form.field("domain").value.to_s + IQ_MANAGER.write(Snikket::Launch.new( + nil, CONFIG[:snikket_hosting_api], domain: domain + )).then do |launched| + Snikket::CustomerInstance.for(customer_id, domain, launched) + end + }.then { |instance| save(snikket_repo, reply, instance) } + end + + def self.save(snikket_repo, reply, instance) + snikket_repo.put(instance).then do + reply.call(FormTemplate.render( + "snikket_launched", + instance: instance + )) + end + end + end +end diff --git a/lib/admin_command.rb b/lib/admin_command.rb index c35d48a372cc154a319a09e72854e7ace5d4c01e..101030f1a1ef2b4905c1cab5e2c6d457e7ccb9f3 100644 --- a/lib/admin_command.rb +++ b/lib/admin_command.rb @@ -8,6 +8,7 @@ require_relative "admin_actions/financial" require_relative "admin_actions/reset_declines" require_relative "admin_actions/set_trust_level" require_relative "admin_actions/number_change" +require_relative "admin_actions/launch_snikket" require_relative "bill_plan_command" require_relative "customer_info_form" require_relative "financial_info" @@ -17,10 +18,11 @@ class AdminCommand def self.for( target_customer, customer_repo, - admin_action_repo=AdminActionRepo.new + admin_action_repo=AdminActionRepo.new, + snikket_repo=Snikket::Repo.new ) if target_customer - new(target_customer, customer_repo, admin_action_repo) + new(target_customer, customer_repo, admin_action_repo, snikket_repo) else NoUser.new(customer_repo, admin_action_repo, notice: "Customer Not Found") end @@ -51,11 +53,13 @@ class AdminCommand def initialize( target_customer, customer_repo, - admin_action_repo=AdminActionRepo.new + admin_action_repo=AdminActionRepo.new, + snikket_repo=Snikket::Repo.new ) @target_customer = target_customer @customer_repo = customer_repo @admin_action_repo = admin_action_repo + @snikket_repo = snikket_repo end def start(command_action=:execute) @@ -98,7 +102,7 @@ class AdminCommand def new_context(q, command_action=:execute) CustomerInfoForm.new(@customer_repo) .parse_something(q).then do |new_customer| - AdminCommand.for(new_customer, @customer_repo, @admin_action_repo) + AdminCommand.for(new_customer, @customer_repo, @admin_action_repo, @snikket_repo) .then { |ac| ac.start(command_action) } end end @@ -142,11 +146,12 @@ class AdminCommand @klass = klass end - def call(customer_id, customer_repo:, **) + def call(customer_id, customer_repo:, snikket_repo:, **) @klass.call( customer_id, reply: method(:reply), - customer_repo: customer_repo + customer_repo: customer_repo, + snikket_repo: snikket_repo ).then { nil } end @@ -180,13 +185,15 @@ class AdminCommand [:set_trust_level, Undoable.new(AdminAction::SetTrustLevel::Command)], [:add_invites, Undoable.new(AdminAction::AddInvites::Command)], [:number_change, Undoable.new(AdminAction::NumberChange::Command)], - [:add_transaction, Undoable.new(AdminAction::AddTransaction::Command)] + [:add_transaction, Undoable.new(AdminAction::AddTransaction::Command)], + [:launch_snikket, Simple.new(AdminAction::LaunchSnikket)] ].each do |action, handler| define_method("action_#{action}") do handler.call( @target_customer, admin_action_repo: @admin_action_repo, - customer_repo: @customer_repo + customer_repo: @customer_repo, + snikket_repo: @snikket_repo ) end end