Skip to content

Send existingNetworkNumber to OSTicket only for Active nodes #767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/meshapi/tests/test_install_create_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,26 @@ def test_constructing_install_triggers_osticket_for_existing_node(self, request_
)
node.save()

inactive_node = Node(
network_number=77,
latitude=0,
longitude=0,
status=Node.NodeStatus.INACTIVE,
)
inactive_node.save()

install = Install(**self.sample_install_copy)
install.node = node
install.save()

install2 = Install(**self.sample_install_copy)
install2.save()

self.assertEqual(len(request_mocker.request_history), 2)
install3 = Install(**self.sample_install_copy)
install3.node = inactive_node
install3.save()

self.assertEqual(len(request_mocker.request_history), 3)
self.assertEqual(
request_mocker.request_history[0].url,
"http://example.com/test-url",
Expand Down Expand Up @@ -189,6 +201,25 @@ def test_constructing_install_triggers_osticket_for_existing_node(self, request_
"locale": "en",
},
)
self.assertEqual(
json.loads(request_mocker.request_history[2].text),
{
"node": install3.install_number,
"userNode": install3.install_number,
"email": "[email protected]",
"name": "John Smith",
"subject": f"NYC Mesh {install3.install_number} Rooftop Install",
"message": f"date: 2022-02-27\r\nnode: {install3.install_number}\r\nname: John Smith\r\nemail: [email protected]\r\nphone: +1 555-555-5555\r\nlocation: 3333 Chom St, Brooklyn NY, 11111\r\nrooftop: Rooftop install\r\nagree to ncl: True",
"phone": "+1 555-555-5555",
"location": "3333 Chom St, Brooklyn NY, 11111",
"apt": "3",
"rooftop": "Rooftop install",
"existingNetworkNumber": "",
"ncl": True,
"ip": "*.*.*.*",
"locale": "en",
},
)

@patch(
"meshapi.util.events.join_requests_slack_channel.SLACK_JOIN_REQUESTS_CHANNEL_WEBHOOK_URL",
Expand Down
4 changes: 2 additions & 2 deletions src/meshapi/util/events/osticket_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.dispatch import receiver
from flags.state import flag_enabled

from meshapi.models import Install
from meshapi.models import Install, Node
from meshapi.util.django_flag_decorator import skip_if_flag_disabled

OSTICKET_API_TOKEN = os.environ.get("OSTICKET_API_TOKEN")
Expand Down Expand Up @@ -79,7 +79,7 @@ def create_os_ticket_for_install(sender: ModelBase, instance: Install, created:
}

if flag_enabled("INTEGRATION_OSTICKET_INCLUDE_EXISTING_NETWORK_NUMBER"):
if install.network_number:
if install.node and install.node.network_number and install.node.status == Node.NodeStatus.ACTIVE:
data["existingNetworkNumber"] = str(install.network_number)
else:
data["existingNetworkNumber"] = ""
Expand Down
Loading