M forms/admin_number_change.rb => forms/admin_number_change.rb +7 -0
@@ 8,3 8,10 @@ field(
label: "Number to change to?",
value: ""
)
+
+field(
+ var: "should_delete",
+ type: "boolean",
+ label: "Should we delete the old number?",
+ value: 0
+)
M lib/admin_action.rb => lib/admin_action.rb +7 -0
@@ 99,6 99,13 @@ class AdminAction
@attributes[:parent_id]
end
+ # This tells us if this is the first time we're running this command.
+ # This can be used by actions which take destructive or annoying actions
+ # and don't want to redo those parts on an undo or redo.
+ def first_time?
+ !parent_id
+ end
+
def actor_id
@attributes[:actor_id]
end
M lib/admin_actions/number_change.rb => lib/admin_actions/number_change.rb +23 -2
@@ 56,6 56,10 @@ class AdminAction
@attributes[:new_tel]
end
+ def should_delete?
+ ["1", "true"].include?(@attributes[:should_delete])
+ end
+
def check_forward
EMPromise.all([
check_noop,
@@ 67,7 71,8 @@ class AdminAction
sgx = TrivialBackendSgxRepo.new.get(customer_id)
EMPromise.all([
REDIS.rename("catapult_fwd-#{old_tel}", "catapult_fwd-#{new_tel}"),
- sgx.register!(new_tel)
+ sgx.register!(new_tel),
+ should_delete? && first_time? ? disconnect_number : nil
]).then { self }
end
@@ 79,11 84,27 @@ class AdminAction
end
def to_s
- "number_change(#{customer_id}): #{old_tel} -> #{new_tel}"
+ "number_change(#{customer_id}): #{old_tel} -> #{new_tel}#{delete_warning}"
end
protected
+ def disconnect_number
+ # Order name is limited to 40 characters
+ # Assuming 12 chars for new_tel and 12 for customer_id, this is tight
+ # but ok
+ BandwidthTnRepo.new.disconnect(
+ old_tel,
+ "cust #{customer_id} swap to #{new_tel}"
+ )
+ end
+
+ def delete_warning
+ return "" unless should_delete? && !first_time?
+
+ " * NOT DELETING"
+ end
+
def check_noop
EMPromise.reject(NoOp.new) if new_tel == old_tel
end