Skip to content
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

Oct 4 Develop to Subscriptions update #359

Merged
merged 46 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0bbf2cf
feat: updated requirements
lc-hd Sep 16, 2024
c4fcdbc
feat: removed selenium-wire since it is outdated
lc-hd Sep 17, 2024
65169bb
feat: created placeholder code to house external api
lc-hd Sep 18, 2024
f4327a3
feat: created a test to verify external apis can be mocked
lc-hd Sep 18, 2024
377e538
feat: added templatetag for transforming external_urls to internal_ur…
lc-hd Sep 18, 2024
00af964
feat: use external_api template_tag for Native Land API
lc-hd Sep 18, 2024
cf6d3de
feat: created unit test for new templatetag
lc-hd Sep 18, 2024
5f884b2
add doi and guid as search params and fields in API v1
arojas1 Sep 19, 2024
a44b0c6
feat: test sets the TEST_LIVE_SERVER_DOMAIN environment variable
lc-hd Sep 19, 2024
c8b7740
feat: created mock endpoint for native_land_map_list
lc-hd Sep 19, 2024
ad095ca
feat: added fixture for a native land boundary response
lc-hd Sep 20, 2024
d6f51fd
feat: updated mocked external_api to serve the native_land boundary r…
lc-hd Sep 20, 2024
3cc51ba
feat: modified template so Native Land external call uses fixture dur…
lc-hd Sep 20, 2024
4306253
feat: update description
lc-hd Sep 20, 2024
e649f9c
feat: changed url name from boundary-view to boundary-preview
lc-hd Sep 20, 2024
ea33da3
feat: changed view name from boundary_view to boundary_preview
lc-hd Sep 20, 2024
664bb6a
feat: changed url from boundary-view to boundary-preview
lc-hd Sep 20, 2024
af1e532
feat: updated template names
lc-hd Sep 20, 2024
472ce81
feat: updated template names in view
lc-hd Sep 20, 2024
fe0d8dd
feat: updated view for boundary_preview so it does not check for the …
lc-hd Sep 20, 2024
7725f82
feat: code attempts to get boundary from local storage for preview
lc-hd Sep 20, 2024
719ecac
feat: refactored boundary-preview
lc-hd Sep 21, 2024
e83e31a
feat: the boundary-preview is set in localStorage
lc-hd Sep 21, 2024
c42275b
feat: the boundary-preview is set in localStorage
lc-hd Sep 21, 2024
f7d74b9
feat: removed unused tets code
lc-hd Sep 21, 2024
7c046df
feat: when "Clear Boundary" button is cliced, the BoundaryPayload is …
lc-hd Sep 23, 2024
f207bfb
feat: code does not attempt to save boundary payload when it is an em…
lc-hd Sep 23, 2024
9f72c01
Merge pull request #344 from localcontexts/CU-8689q6g1d-add-api-searc…
birbjam Sep 23, 2024
4603ac8
feat: added data-test-id to reference element
lc-hd Sep 27, 2024
593ce0d
feat: created testcase which verifies cleared boundaries are not saved
lc-hd Sep 27, 2024
39fbe56
feat: added similar testcase but for institutions
lc-hd Sep 30, 2024
c7438dd
Merge pull request #350 from localcontexts/8689u4y60-fix-boundary-sav…
lc-hd Sep 30, 2024
f86731d
feat: updated name of testcase
lc-hd Sep 30, 2024
96906aa
feat: created testcase file
lc-hd Sep 30, 2024
a3722d0
feat: updated testcase name
lc-hd Sep 30, 2024
9aedcc1
feat: added testcase for community project previews
lc-hd Sep 30, 2024
5294995
feat: added testcase for institution project previews
lc-hd Sep 30, 2024
a00c507
feat: added ttestcase for when no preview boundary is selected
lc-hd Sep 30, 2024
bd81787
Merge pull request #347 from localcontexts/8689u4y60-fix-boundary-sav…
birbjam Sep 30, 2024
9e960f7
Merge pull request #346 from localcontexts/8689u4y5u-fix-large-bounda…
birbjam Sep 30, 2024
1d8c4fa
feat: added testcase for researcher preview boundary
lc-hd Oct 1, 2024
d534c6c
feat: created testcase for community settings boundary preview
lc-hd Oct 1, 2024
c886a39
Merge pull request #341 from localcontexts/8689rhmp9-additional-gis-f…
birbjam Oct 3, 2024
664fa42
Merge pull request #352 from localcontexts/8689u4y5u-fix-large-bounda…
birbjam Oct 3, 2024
4130c16
Merge branch 'develop' of https://github.com/localcontexts/localconte…
arojas1 Oct 4, 2024
f133595
feat: modified test to use the updated param name for a researcher's id
lc-hd Oct 4, 2024
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
4 changes: 2 additions & 2 deletions api/base/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ProjectSerializer(serializers.ModelSerializer):

class Meta:
model = Project
fields = ('unique_id', 'providers_id', 'source_project_uuid', 'project_page', 'title', 'project_privacy', 'date_added', 'date_modified', 'created_by', 'notice', 'sub_projects', 'related_projects', 'project_boundary_geojson')
fields = ('unique_id', 'providers_id', 'publication_doi', 'project_data_guid', 'source_project_uuid', 'project_page', 'title', 'project_privacy', 'date_added', 'date_modified', 'created_by', 'notice', 'sub_projects', 'related_projects', 'project_boundary_geojson')

def get_related_projects(self, obj):
return [project.unique_id for project in obj.related_projects.all()]
Expand All @@ -121,7 +121,7 @@ class ProjectNoNoticeSerializer(serializers.ModelSerializer):

class Meta:
model = Project
fields = ('unique_id', 'providers_id', 'source_project_uuid', 'project_page', 'title', 'project_privacy', 'date_added', 'date_modified', 'created_by', 'bc_labels', 'tk_labels', 'sub_projects', 'related_projects', 'project_boundary_geojson')
fields = ('unique_id', 'providers_id', 'publication_doi', 'project_data_guid', 'source_project_uuid', 'project_page', 'title', 'project_privacy', 'date_added', 'date_modified', 'created_by', 'bc_labels', 'tk_labels', 'sub_projects', 'related_projects', 'project_boundary_geojson')

def get_related_projects(self, obj):
return [project.unique_id for project in obj.related_projects.all()]
Expand Down
2 changes: 1 addition & 1 deletion api/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ProjectList(generics.ListAPIView):
serializer_class = ProjectOverviewSerializer

filter_backends = [filters.SearchFilter]
search_fields = ['^providers_id', '=unique_id', 'title']
search_fields = ['^providers_id', '=unique_id', 'title', 'publication_doi', 'project_data_guid']

# '^' starts-with search
# '=' exact matches
Expand Down
Empty file added api/templatetags/__init__.py
Empty file.
33 changes: 33 additions & 0 deletions api/templatetags/custom_api_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
from urllib.parse import urlparse
from urllib.parse import urljoin

from django import template


register = template.Library()


@register.simple_tag
def external_api(external_url: str) -> str:
"""
Tag converts an external_url into an internal_url
so the response can be mocked with a fixture.

Args:
external_url: Url to an external API resource.

Returns:
When TEST_LIVE_SERVER_DOMAIN is available, the url is transformed so
the external domain is swapped with the TEST_LIVE_SERVER_DOMAIN.
"""
test_live_server_domain = os.environ.get('TEST_LIVE_SERVER_DOMAIN')
if not test_live_server_domain:
return external_url
url_components = urlparse(external_url)

try:
# return the internal_url formed by the domain and url_components.path
return urljoin(test_live_server_domain, url_components.path)
except Exception:
return external_url
2 changes: 1 addition & 1 deletion helpers/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
path('download/community/support-letter/', views.download_community_support_letter, name="download-community-support-letter"),
path('community-boundary-view/<int:community_id>', views.community_boundary_view, name="community-boundary-view"),
path('project-boundary-view/<int:project_id>', views.project_boundary_view, name="project-boundary-view"),
path('boundary-view/', views.boundary_view, name="boundary-view"),
path('boundary-preview/', views.boundary_preview, name="boundary-preview"),
]
2 changes: 1 addition & 1 deletion helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def create_or_update_boundary(post_data: dict, entity: Union['Community', 'Proje
entity.share_boundary_publicly = post_data.get('share-boundary-publicly') == 'on'
raw_boundary_payload = post_data.get('boundary-payload')

if raw_boundary_payload in ['', None]:
if raw_boundary_payload in ['', '{}', None]:
return

data = json.loads(raw_boundary_payload)
Expand Down
45 changes: 22 additions & 23 deletions helpers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
def restricted_view(request, exception=None):
return render(request, '403.html', status=403)


@login_required(login_url='login')
def delete_member_invite(request, pk):
invite = InviteMember.objects.get(id=pk)
Expand Down Expand Up @@ -78,6 +79,7 @@ def download_open_collaborate_notice(request, perm, researcher_id=None, institut
raise UnsubscribedAccountException(message)



@login_required(login_url='login')
def download_collections_care_notices(request, institution_id, perm):
# perm will be a 1 or 0
Expand All @@ -88,6 +90,7 @@ def download_collections_care_notices(request, institution_id, perm):
NoticeDownloadTracker.objects.create(institution=Institution.objects.get(id=institution_id), user=request.user, collections_care_notices=True)
return download_cc_notices(request)


@login_required(login_url='login')
def download_community_support_letter(request):
try:
Expand All @@ -105,6 +108,9 @@ def download_community_support_letter(request):

@xframe_options_sameorigin
def community_boundary_view(request, community_id):
"""
Uses boundary in community for view
"""
community = Community.objects.filter(id=community_id).first()
if not community:
message = 'Community Does Not Exist'
Expand All @@ -117,32 +123,14 @@ def community_boundary_view(request, community_id):
context = {
'boundary': boundary
}
return render(request, 'boundary/boundary-view.html', context)


@login_required(login_url='login')
def boundary_view(request):
try:
boundary = request.GET.get('boundary')
if boundary:
boundary = json.loads(
boundary.replace('(', '[').replace(')', ']')
)
else:
boundary = []

context = {
'boundary': boundary
}
return render(request, 'boundary/boundary-view.html', context)
except Exception as e:
message = 'Invalid Boundary Format'
print(f'{message}: {e}')
raise Exception(message)
return render(request, 'boundary/boundary-preview.html', context)


@xframe_options_sameorigin
def project_boundary_view(request, project_id):
"""
Uses boundary in project for view
"""
project = Project.objects.filter(id=project_id).first()
if not project:
message = 'Project Does Not Exist'
Expand All @@ -155,4 +143,15 @@ def project_boundary_view(request, project_id):
context = {
'boundary': boundary
}
return render(request, 'boundary/boundary-view.html', context)
return render(request, 'boundary/boundary-preview.html', context)


@login_required(login_url='login')
def boundary_preview(request):
"""
Uses boundary in local storage for preview
"""
context = {
'preview_boundary': True,
}
return render(request, 'boundary/boundary-preview.html', context)
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,53 @@
margin-top: 50px;
padding: 36px;
}
.invisible {
display: none
}
</style>
</head>
<body>
<div id="map"></div>

{% if boundary|length == 0 %}
<div id="no-boundary-container">
<div id="no-boundary">
No boundary Present
</div>
<div id="no-boundary-container">
<div id="no-boundary">
No boundary Present
</div>
</div>

<script>
// when boundary is not present, set default
let boundary = [
[[8.7832, 34.5085]]
]
let setInitialZoom = true

function boundaryExists() {
// when boundary exists, this is run to modify
// the settings
setInitialZoom = false
document.querySelector('#no-boundary').classList.add('invisible')
}
</script>

{% if preview_boundary %}
<script>
// when boundary are not present, set default
const boundary = [
[[8.7832, 34.5085]]
]
const setInitialZoom = true
// get boundary data from Local Storage
if (localStorage.hasOwnProperty('boundary_preview')) {
boundary = JSON.parse(
localStorage.getItem('boundary_preview')
)
boundaryExists()
}
</script>
{% else %}
{% elif boundary|length > 0 %}
<script>
const boundary = {{ boundary }}
const setInitialZoom = false
// Get boundary data from backend
boundary = {{ boundary }}
boundaryExists()
</script>
{% endif %}


<script>
// define map and its initial boundary
const map = L.map('map')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,11 @@
}

function setViewLocationsHref(selectionUnit, boundary) {
// set boundary-preview value in localStorage
localStorage.setItem('boundary_preview', JSON.stringify(boundary))

// set href for view-boundary-location
const href = `{% url 'boundary-view' %}?boundary=${JSON.stringify(boundary)}`
const href = "{% url 'boundary-preview' %}"
selectionUnit.querySelector('.view-boundary-link').setAttribute('href', href)
}

Expand Down Expand Up @@ -553,6 +556,8 @@
clearShapeFileInput(selectionUnit)
selectInitialShareBoundaryPublicly()
disableContinueButton()
BoundaryPayLoad = {}
setBoundaryPayloadForInputElement()
}
</script>
<script src="{% static 'javascript/shpjs.js' %}"></script>
8 changes: 4 additions & 4 deletions templates/communities/add-community-boundary.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'register-base.html' %} {% block title %} Add Community {% endblock %} {% load static %} {% block card %}
{% extends 'register-base.html' %} {% block title %} Add Community {% endblock %} {% load static %} {% block card %} {% load custom_api_tags %}
<style>
#define-community-top-text{
width: 94%;
Expand Down Expand Up @@ -184,7 +184,7 @@ <h2 class="mt-0">Search the Native Land Digital database</h2>
</div>

<script>
fetch('https://native-land.ca/wp-json/nativeland/v1/map-list').then(resp => resp.json()).then(response => {
fetch('{% external_api "https://native-land.ca/wp-json/nativeland/v1/map-list" %}').then(resp => resp.json()).then(response => {

document.querySelector('#region-container input.search').addEventListener("keyup", (event) => {
let html = ''
Expand Down Expand Up @@ -248,8 +248,8 @@ <h2 class="mt-0">Search the Native Land Digital database</h2>
// do post call to get boundary
const href = document.querySelector('#community-boundary-continue-btn').getAttribute('href')
const slug = document.querySelector('#selected-title').getAttribute('data-slug')

const url = `https://native-land.ca/wp-json/nativeland/v1/api/index.php?maps=territories&name=${slug}`
const url = `{% external_api "https://native-land.ca/wp-json/nativeland/v1/api/index.php?maps=territories&name=${slug}" %}`
const boundaryResponse = await fetch(url)
const boundaryData = await boundaryResponse.json()
document.querySelector("#community-boundary-continue-btn .fa-spinner").classList.remove("spinner-container");
Expand Down
1 change: 1 addition & 0 deletions templates/partials/_project-actions.html
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ <h2 class="primary-black-text mt-0">Are you sure?</h2>
{% if 'native-land.ca' in project.source_of_boundary and project.name_of_boundary %}
<span>
<a
data-test-id="native-land-link"
href="{{project.source_of_boundary}}"
class="default-a" target="_blank" rel="noopener"
style="display: block; margin-bottom: 5px;">
Expand Down
5 changes: 4 additions & 1 deletion templates/widget_forms/boundary_widget.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@
return
}

// set boundary-preview value in localStorage
localStorage.setItem('boundary_preview', JSON.stringify(boundary))

// open boundary preview
const url = `{% url 'boundary-view' %}?boundary=[${boundary}]`
const url = "{% url 'boundary-preview' %}"
window.open(url, '_blank');
}
async function uploadShapeFileData(self) {
Expand Down
14 changes: 14 additions & 0 deletions tests/external_api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from localcontexts.urls import urlpatterns
from django.urls import path

from . views import (
native_land_map_list,
native_land_boundary_response
)


class UrlsWithMockedExternalApi:
urlpatterns = urlpatterns + [
path('wp-json/nativeland/v1/map-list/', native_land_map_list),
path('wp-json/nativeland/v1/api/index.php', native_land_boundary_response)
]
23 changes: 23 additions & 0 deletions tests/external_api/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import json

from django.http import JsonResponse


def native_land_map_list(request):
"""
This view is called when populating the dropdown
of Native Land territories
"""
json_data = open('tests/fixtures/native_land_map_list.json')
data = json.load(json_data)
return JsonResponse(data, safe=False)


def native_land_boundary_response(request):
"""
This view is called when getting specific boundary data
for a single Native Land territory
"""
json_data = open('tests/fixtures/native_land_boundary_response.json')
data = json.load(json_data)
return JsonResponse(data, safe=False)
Loading
Loading