Repository: openwisp/openwisp-network-topology (language: python)

Issue:
[bug] Unpublished topology is not shown in admin
Trying to show the graph of an unpublished topology in the admin fails because the API returns 404.

Maybe we can add a querystring to the api like ?unpublished=true to show also unpublished topologies and use this flag from the admin to fix this issue.
[bug] Unpublished topology is not shown in admin
Trying to show the graph of an unpublished topology in the admin fails because the API returns 404.

Maybe we can add a querystring to the api like ?unpublished=true to show also unpublished topologies and use this flag from the admin to fix this issue.


Discussion / hints:
I'll proposed my solution let me know about your thoughts
If we can able to change the API endpoints with adding some parameter to the API call, as you already said. This will specify whether we have to add the particular topology or not.
`const END = '/topologies'

//Here we can write async function 
here it'll return **url = END + (isinclueunpublished?"?unpublished=true":"")**
return data

`
Please let me notify 
I'll proposed my solution let me know about your thoughts
If we can able to change the API endpoints with adding some parameter to the API call, as you already said. This will specify whether we have to add the particular topology or not.
`const END = '/topologies'

//Here we can write async function 
here it'll return **url = END + (isinclueunpublished?"?unpublished=true":"")**
return data

`
Please let me notify 

Fix patch:
diff --git a/openwisp_network_topology/templates/netjsongraph/netjsongraph-script.html b/openwisp_network_topology/templates/netjsongraph/netjsongraph-script.html
index 71ad8b3f..fe439403 100644
--- a/openwisp_network_topology/templates/netjsongraph/netjsongraph-script.html
+++ b/openwisp_network_topology/templates/netjsongraph/netjsongraph-script.html
@@ -1,8 +1,8 @@
 {% load i18n %}
 
 <script>
-    loadNetJsonGraph = (el='body', url='{{ graph_url }}') => {
-        const history_url = '{{ history_url }}';
+    loadNetJsonGraph = (el='body', url='{{ graph_url }}?include_unpublished=true') => {
+        const history_url = '{{ history_url }}?include_unpublished=true';
         const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
         const wsUrl = `${wsProtocol}//${window.location.host}/ws/network-topology/topology/${getTopologyIdFromUrl()}/`;
         const socket = new WebSocket(wsUrl);


Test patch:
diff --git a/openwisp_network_topology/tests/test_selenium.py b/openwisp_network_topology/tests/test_selenium.py
index c85cc3a9..7e4a6578 100644
--- a/openwisp_network_topology/tests/test_selenium.py
+++ b/openwisp_network_topology/tests/test_selenium.py
@@ -129,6 +129,14 @@ def test_topology_admin_view_graph_visualizer(self):
         self.web_driver.find_element(By.CSS_SELECTOR, 'input.visualizelink').click()
         self._assert_topology_graph()
 
+    def test_unpublished_topology_admin_view_graph_visualizer(self):
+        self.topology_model.objects.update(published=False)
+        path = reverse(f'{self.prefix}_topology_change', args=[self.topology.pk])
+        self.login(username=self.admin_username, password=self.admin_password)
+        self.open(path)
+        self.web_driver.find_element(By.CSS_SELECTOR, 'input.visualizelink').click()
+        self._assert_topology_graph()
+
     def test_topology_non_admin_view_graph_visualizer(self):
         path = reverse('topology_list')
         self.login(username=self.admin_username, password=self.admin_password)