1
0
mirror of https://github.com/peeringdb/peeringdb.git synced 2024-05-11 05:55:09 +00:00

Insert links into ID fields in DESKPRO AUTOASN tickets (#615)

This commit is contained in:
Stefan Pratter
2020-04-03 13:36:44 +00:00
parent 45c25a6223
commit 6d38950901
14 changed files with 126 additions and 24 deletions

View File

@@ -551,6 +551,15 @@ class Organization(pdb_models.OrganizationBase):
"admin:peeringdb_server_organization_change", args=(self.id,)
)
@property
def view_url(self):
"""
Return the URL to this organizations web view
"""
return "{}{}".format(
settings.BASE_URL, django.urls.reverse("org-view", args=(self.id,))
)
@property
def owned(self):
"""
@@ -1136,6 +1145,16 @@ class Facility(pdb_models.FacilityBase, GeocodeBaseMixin):
"""
return self.netfac_set_active.count()
@property
def view_url(self):
"""
Return the URL to this facility's web view
"""
return "{}{}".format(
settings.BASE_URL, django.urls.reverse("fac-view", args=(self.id,))
)
def nsp_has_perms_PUT(self, user, request):
return validate_PUT_ownership(user, self, request.data, ["org"])
@@ -1424,6 +1443,17 @@ class InternetExchange(pdb_models.InternetExchangeBase):
"""
return self.org.sponsorship
@property
def view_url(self):
"""
Return the URL to this facility's web view
"""
return "{}{}".format(
settings.BASE_URL, django.urls.reverse("ix-view", args=(self.id,))
)
def nsp_has_perms_PUT(self, user, request):
return validate_PUT_ownership(user, self, request.data, ["org"])
@@ -2319,6 +2349,16 @@ class Network(pdb_models.NetworkBase):
def sponsorship(self):
return self.org.sponsorship
@property
def view_url(self):
"""
Return the URL to this networks web view
"""
return "{}{}".format(
settings.BASE_URL, django.urls.reverse("net-view", args=(self.id,))
)
def nsp_has_perms_PUT(self, user, request):
return validate_PUT_ownership(user, self, request.data, ["org"])

View File

@@ -1709,9 +1709,11 @@ class NetworkSerializer(ModelSerializer):
if rdap and user.validate_rdap_relationship(rdap):
# user email exists in RiR data, skip verification queue
validated_data["status"] = "ok"
net = super(ModelSerializer, self).create(validated_data)
ticket_queue_asnauto_skipvq(
user, validated_data["org"], validated_data, rdap
user, validated_data["org"], net, rdap
)
return net
elif self.Meta.model in QUEUE_ENABLED:
# user email does NOT exist in RiR data, put into verification
@@ -1723,6 +1725,7 @@ class NetworkSerializer(ModelSerializer):
return super(ModelSerializer, self).create(validated_data)
def finalize_create(self, request):
rdap_error = getattr(request, "rdap_error", None)
if rdap_error:

View File

@@ -3,5 +3,5 @@
{% trans "Ownership of organization was automatically granted to user" %}:
{% trans "User" %}: '{{ user.username }}' ({{ user.email }})
{% trans "Organization" %}: '{{ org.name }}' ({{ org.id }})
{% trans "Network" %}: '{{ net.name }}' {% trans "AS" %}{{ net.asn }}{% endlanguage %}
{% trans "Organization" %}: '{{ org.name }}' (<a href="{{ org.view_url }}">{{ org.id }}</a>)
{% trans "Network" %}: '{{ net.name }}' <a href="{{ net.view_url }}">{% trans "AS" %}{{ net.asn }}</a>{% endlanguage %}

View File

@@ -1,12 +1,12 @@
{% load i18n %}
{% language 'en' %}
{% if org_created %}
{% blocktrans with o_name=org.name o_id=org.id u_name=user.username trimmed %}
Organization {{ o_name }} ({{ o_id }}) was automatically created during user '{{ u_name }}'s affiliation request to AS{{ asn }}
{% blocktrans with o_name=org.name o_id=org.id o_url=org.view_url u_name=user.username trimmed %}
Organization {{ o_name }} (<a href="{{ o_url }}">{{ o_id }}</a>) was automatically created during user '{{ u_name }}'s affiliation request to AS{{ asn }}
{% endblocktrans %}
{% endif %}
{% if net_created %}
{% blocktrans with n_name=net.name n_id=net.id u_name=user.username trimmed %}
Network {{ n_name }} ({{ n_id }}) was automatically created during user '{{ u_name }}'s affiliation request to AS{{ asn }}
{% blocktrans with n_name=net.name n_id=net.id n_url=net.view_url u_name=user.username trimmed %}
Network {{ n_name }} (<a href="{{ n_url }}">{{ n_id }}</a>) was automatically created during user '{{ u_name }}'s affiliation request to AS{{ asn }}
{% endblocktrans %}
{% endif %}{% endlanguage %}

View File

@@ -1,8 +1,8 @@
{% load i18n %}
{% language 'en' %}
{% blocktrans with u_name=user.username n_name=net.name n_asn=net.asn n_id=net.id o_name=org.name o_id=org.id trimmed %}
User '{{ u_name }}' created Network {{ n_name }} AS{{ n_asn }} ({{n_id}}) under organzation {{ o_name }} ({{ o_id }}).
{% blocktrans with u_name=user.username n_name=net.name n_asn=net.asn n_id=net.id o_name=org.name o_id=org.id n_url=net.view_url o_url=org.view_url trimmed %}
User '{{ u_name }}' created Network {{ n_name }} AS{{ n_asn }} (<a href="{{ n_url }}">{{n_id}}</a>) under organzation {{ o_name }} (<a href="{{ o_url }}">{{ o_id }}</a>).
{% endblocktrans %}
{% trans "As the user's email address was succesfully matched against RiR entry data this network has skipped the verification queue." %}

View File

@@ -34,9 +34,9 @@
{% trans "The user is affiliated with other organizations" %}:
{% for org in user.organizations %}
{% if user in org.admin_usergroup.user_set.all %}
<a href="{{ base_url }}{{org.admin_url}}">{{ base_url }}{{org.admin_url}}</a> | {{ org.name }} | {% trans "ADMIN" %}
<a href="{{ base_url }}{{org.admin_url}}">{{ base_url }}{{org.admin_url}}</a> | <a href="{{ org.view_url }}">{{ org.name }}</a> | {% trans "ADMIN" %}
{% else %}
<a href="{{ base_url }}{{org.admin_url}}">{{ base_url }}{{org.admin_url}}</a> | {{ org.name }} | {% trans "MEMBER" %}
<a href="{{ base_url }}{{org.admin_url}}">{{ base_url }}{{org.admin_url}}</a> | <a href="{{ org.view_url }}">{{ org.name }}</a> | {% trans "MEMBER" %}
{% endif %}
{% endfor %}
{% endif %}

View File

@@ -18,7 +18,7 @@ A new '{{ entity_type_name }}' has been created and requires your approval.
{% for email in rdap.emails %} - {{ email }} {% endfor %}
{% endif %}
{% trans "Name" %}: {{ item }}
{% trans "Name" %}: <a href="{{ item.view_url }}">{{ item }}</a>
{% trans "Requested by user" %}: {{ user.full_name }} ({{ user.email }})
{% trans "You can go to" %} <a href="{{ edit_url }}">{{ edit_url }}</a> {% trans "to view and approve or deny this entry" %}{% endlanguage %}

View File

@@ -100,10 +100,10 @@ urlpatterns = [
url(r"^affiliate-to-org$", view_affiliate_to_org),
url(r"^cancel-affiliation-request/(?P<uoar_id>\d+)/$", cancel_affiliation_request, name="cancel-affiliation-request"),
url(r"^request-ownership$", view_request_ownership),
url(r"^%s/(?P<id>\d+)/?$" % Network.handleref.tag, view_network),
url(r"^%s/(?P<id>\d+)/?$" % InternetExchange.handleref.tag, view_exchange),
url(r"^%s/(?P<id>\d+)/?$" % Facility.handleref.tag, view_facility),
url(r"^%s/(?P<id>\d+)/?$" % Organization.handleref.tag, view_organization),
url(r"^%s/(?P<id>\d+)/?$" % Network.handleref.tag, view_network, name="net-view"),
url(r"^%s/(?P<id>\d+)/?$" % InternetExchange.handleref.tag, view_exchange, name="ix-view"),
url(r"^%s/(?P<id>\d+)/?$" % Facility.handleref.tag, view_facility, name="fac-view"),
url(r"^%s/(?P<id>\d+)/?$" % Organization.handleref.tag, view_organization, name="org-view"),
url(r"^%s$" % Network.handleref.tag, view_network_by_query),
url(r"^asn/(?P<asn>\d+)/?$", view_network_by_asn),
url(r"^org_admin/users$", peeringdb_server.org_admin_views.users),

View File

@@ -1,8 +1,8 @@
Organization ORG AS9000001 (2) was automatically created during user 'user_a's affiliation request to AS9000001
Organization ORG AS9000001 (<a href="https://localhost/org/2">2</a>) was automatically created during user 'user_a's affiliation request to AS9000001
Network AS9000001 (1) was automatically created during user 'user_a's affiliation request to AS9000001
Network AS9000001 (<a href="https://localhost/net/1">1</a>) was automatically created during user 'user_a's affiliation request to AS9000001

View File

@@ -3,5 +3,5 @@
Ownership of organization was automatically granted to user:
User: 'user_a' (Neteng@20c.com)
Organization: 'ORG AS9000001' (2)
Network: 'AS9000001' AS9000001
Organization: 'ORG AS9000001' (<a href="https://localhost/org/2">2</a>)
Network: 'AS9000001' <a href="https://localhost/net/1">AS9000001</a>

View File

@@ -0,0 +1,27 @@
user (neteng@other.com) wishes to be affiliated to Organization 'ORG AS9000002'
They also provided this ASN in their request: 9000002
ATTENTION: This is an ownership request, approving it will grant the user administration rights over the organization and any entities it owns.
These are the email addresses we could fetch from the ASNs belonging to this organization:
- neteng@20c.com
The user is affiliated with other organizations:
<a href="https://localhost/cp/peeringdb_server/organization/2/change/">https://localhost/cp/peeringdb_server/organization/2/change/</a> | <a href="https://localhost/org/2">Org with admin user</a> | ADMIN
<a href="https://localhost/cp/peeringdb_server/organization/3/change/">https://localhost/cp/peeringdb_server/organization/3/change/</a> | <a href="https://localhost/org/3">Org with normal user</a> | MEMBER
<a href="https://localhost/cp/peeringdb_server/user/2/change/">Review Affiliation/Ownership Request</a>
<a href="https://localhost/cp/peeringdb_server/userorgaffiliationrequest/1/action/approve_and_notify/">Approve Ownership Request and Notify User</a>

View File

@@ -10,7 +10,7 @@
- neteng@20c.com
<a href="localost/cp/peeringdb_server/user/2/change/">Review Affiliation/Ownership Request</a>
<a href="https://localhost/cp/peeringdb_server/user/2/change/">Review Affiliation/Ownership Request</a>
<a href="localost/cp/peeringdb_server/userorgaffiliationrequest/2/action/approve_and_notify/">Approve Ownership Request and Notify User</a>
<a href="https://localhost/cp/peeringdb_server/userorgaffiliationrequest/2/action/approve_and_notify/">Approve Ownership Request and Notify User</a>

View File

@@ -101,7 +101,7 @@ settings.configure(
GUEST_GROUP_ID=1,
USER_GROUP_ID=2,
TEMPLATE_DEBUG=False,
BASE_URL="localost",
BASE_URL="https://localhost",
PASSWORD_RESET_URL="localhost",
API_CACHE_ROOT="tests/api-cache",
API_CACHE_ENABLED=False,

View File

@@ -83,6 +83,7 @@ class AsnAutomationTestCase(TestCase):
"asnauto-9000001-org-net-created.txt",
"asnauto-9000001-user-granted-ownership.txt",
"asnauto-9000002-user-requested-ownership.txt",
"asnauto-9000002-affiliated-user-requested-ownership.txt",
]:
with open(
os.path.join(os.path.dirname(__file__), "data", "deskpro", ticket_name),
@@ -191,7 +192,7 @@ class AsnAutomationTestCase(TestCase):
self.assertEqual(net.org.status, "ok")
# test 3: test affiliation to asn that hsa RiR entry and user relationship
# cannot be verifiedi (ASN 9000002)
# cannot be verified (ASN 9000002)
request = self.factory.post("/affiliate-to-org", data={"asn": asn_ok_b})
request.user = self.user_b
request._dont_enforce_csrf_checks = True
@@ -287,6 +288,37 @@ class AsnAutomationTestCase(TestCase):
assert response.status_code == 404
assert self.user_b.pending_affiliation_requests.count() == 1
def test_affil_already_affiliated(self):
"""
When a user needs pdb admin approval of an affiliation an deskpro
ticket is created.
When the user is already affiliated to another organization, there is
extra information appended to that ticket, such as what organizations
the user is already affiliated to.
"""
org_1 = models.Organization.objects.create(name="Org with admin user", status="ok")
org_2 = models.Organization.objects.create(name="Org with normal user", status="ok")
org_1.admin_usergroup.user_set.add(self.user_b)
org_2.usergroup.user_set.add(self.user_b)
request = self.factory.post("/affiliate-to-org", data={"asn": 9000002})
request.user = self.user_b
request._dont_enforce_csrf_checks = True
resp = json.loads(pdbviews.view_affiliate_to_org(request).content)
self.assertEqual(resp.get("status"), "ok")
ticket = models.DeskProTicket.objects.get(
subject="[test]User user_b wishes to request ownership of ORG AS9000002"
)
self.assertEqual(
ticket.body, self.ticket["asnauto-9000002-affiliated-user-requested-ownership.txt"]
)
def test_affiliate_to_bogon_asn(self):
"""
tests affiliation with non-existant asn