mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
advanced search fixes (#984)
* fix advanced search error when not logged in * fix error with data/my_organizations if user is not logged in * fix 500 error when viewing advanced search as a user that is not affiliated with any org * tests for adv search init and anonymous data/my_organizations request Co-authored-by: Stefan Pratter <[email protected]>
This commit is contained in:
co-authored by
Stefan Pratter
parent
207ad371c0
commit
de413ef1f6
@@ -195,6 +195,9 @@ def my_organizations(request):
|
||||
Returns a JSON response with a list of organization names and ids
|
||||
that the requesting user is a member of
|
||||
"""
|
||||
if not request.user.is_authenticated:
|
||||
return JsonResponse({"my_organizations": []})
|
||||
|
||||
return JsonResponse(
|
||||
{
|
||||
"my_organizations": [
|
||||
|
||||
@@ -13,7 +13,11 @@
|
||||
<div data-edit-type="select"
|
||||
data-edit-data="my_organizations"
|
||||
data-edit-multiple="yes"
|
||||
{% if request.user.organizations %}
|
||||
data-edit-value="{{ request.GET.org_present|default:request.user.organizations.0.id }}"
|
||||
{% else %}
|
||||
data-edit-value=""
|
||||
{% endif %}
|
||||
{% if request.GET.org_present %}
|
||||
data-edit-name="org_present"
|
||||
{% elif request.GET.org_not_present %}
|
||||
|
||||
@@ -100,3 +100,14 @@ def test_my_organizations():
|
||||
|
||||
assert response.status_code == 200
|
||||
assert len(response.json()["my_organizations"]) == 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_my_organizations_anon():
|
||||
call_command("pdb_generate_test_data", limit=3, commit=True)
|
||||
|
||||
client = Client()
|
||||
response = client.get("/data/my_organizations")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert len(response.json()["my_organizations"]) == 0
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import pytest
|
||||
from rest_framework.test import APIClient
|
||||
from django.test import Client
|
||||
|
||||
from peeringdb_server.models import (
|
||||
Network,
|
||||
@@ -113,3 +114,22 @@ def test_affiliate_to_nonexisting_org_multiple(client):
|
||||
response = client.post(URL, other_data)
|
||||
assert response.status_code == 200
|
||||
assert UserOrgAffiliationRequest.objects.count() == 2
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_adv_search_init():
|
||||
client = Client()
|
||||
response = client.get("/advanced_search")
|
||||
assert response.status_code == 200
|
||||
|
||||
user = User.objects.create(
|
||||
username="test",
|
||||
email="test@localhost",
|
||||
)
|
||||
user.set_password("test1234")
|
||||
user.save()
|
||||
|
||||
client.login(username="test", password="test1234")
|
||||
|
||||
response = client.get("/advanced_search")
|
||||
assert response.status_code == 200
|
||||
|
||||
Reference in New Issue
Block a user