-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/refactor in apps #229
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.urls import path | ||
|
||
from auth_mail import views | ||
|
||
urlpatterns = [ | ||
path( | ||
"", | ||
views.send_dataportaal_login_url_to_mail, | ||
name="login_link_to_email_endpoint", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import logging | ||
|
||
from django.conf import settings | ||
from django.http import HttpResponse | ||
from django.template.loader import render_to_string | ||
from django.views.decorators.csrf import csrf_exempt | ||
from django_ratelimit.decorators import ratelimit | ||
|
||
from auth_mail import authentication, mailing | ||
from iiif import parsing | ||
from main import utils | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
# TODO: limit to dataportaal urls | ||
@csrf_exempt | ||
@ratelimit( | ||
key="ip", rate="3/d", block=False | ||
) # TODO: Check django cache settings for rate limiter to work across parallel docker containers | ||
def send_dataportaal_login_url_to_mail(request): | ||
try: | ||
# Some basic sanity checks | ||
parsing.check_for_post(request) | ||
payload = parsing.parse_payload(request) | ||
email, origin_url = parsing.check_login_url_payload(payload) | ||
parsing.check_email_validity(email) | ||
|
||
# Create the login url | ||
token = authentication.create_mail_login_token(email, settings.JWT_SECRET_KEY) | ||
login_url = origin_url + "?auth=" + token | ||
|
||
# Send the email | ||
email_subject = "Toegang bouw- en omgevingsdossiers data.amsterdam.nl" | ||
email_body = render_to_string("login_link.html", {"login_url": login_url}) | ||
# TODO: move actually sending the email to a separate process | ||
mailing.send_email(payload["email"], email_subject, email_body) | ||
|
||
except utils.ImmediateHttpResponse as e: | ||
log.exception("ImmediateHttpResponse in login_url:") | ||
return e.response | ||
|
||
# Respond with a 200 to signal success. | ||
# The user will get an email asap with a login url | ||
return HttpResponse() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,7 @@ | ||
from django.urls import path | ||
|
||
from . import views | ||
from iiif import views | ||
|
||
urlpatterns = [ | ||
path( | ||
"login-link-to-email/", | ||
views.send_dataportaal_login_url_to_mail, | ||
name="login_link_to_email_endpoint", | ||
), | ||
path("zip/", views.request_multiple_files_in_zip, name="zip_endpoint"), | ||
path("<path:iiif_url>", views.index, name="iiif_endpoint"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.urls import path | ||
|
||
from zip_consumer import views | ||
|
||
urlpatterns = [ | ||
path("", views.request_multiple_files_in_zip, name="zip_endpoint"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import json | ||
import logging | ||
import uuid | ||
|
||
from django.conf import settings | ||
from django.http import HttpResponse | ||
from django.views.decorators.csrf import csrf_exempt | ||
|
||
from auth_mail import authentication | ||
from iiif import parsing | ||
from main import utils | ||
from main.utils_azure import store_blob_on_storage_account | ||
from zip_consumer import zip_tools | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
@csrf_exempt | ||
def request_multiple_files_in_zip(request): | ||
try: | ||
parsing.check_for_post(request) | ||
authentication.check_auth_availability(request) | ||
read_jwt_token, is_mail_login = authentication.read_out_mail_jwt_token(request) | ||
scope = authentication.get_max_scope(request, read_jwt_token) | ||
email_address = parsing.get_email_address(request, read_jwt_token) | ||
payload = parsing.parse_payload(request) | ||
parsing.check_zip_payload(payload) | ||
except utils.ImmediateHttpResponse as e: | ||
log.error(e.response.content) | ||
return e.response | ||
|
||
zip_info = { | ||
"email_address": email_address, | ||
"request_meta": request.META, | ||
"urls": {}, | ||
"scope": scope, | ||
"is_mail_login": is_mail_login, | ||
} | ||
for full_url in payload["urls"]: | ||
try: | ||
iiif_url = parsing.strip_full_iiif_url(full_url) | ||
url_info = parsing.get_url_info(iiif_url, True) | ||
authentication.check_wabo_for_mail_login(is_mail_login, url_info) | ||
|
||
# We create a new dict with all the info so that we have it when we want to get and zip the files later | ||
zip_info["urls"][iiif_url] = {"url_info": url_info} | ||
|
||
except utils.ImmediateHttpResponse as e: | ||
log.error(e.response.content) | ||
return e.response | ||
|
||
# The fact that we arrived here means that urls are formatted correctly and the info is extracted from it. | ||
# It does NOT mean that the metadata exists or that the user is allowed to access all the files. This will | ||
# be checked in the consumer. We now proceed with storing the info as a zip job so that a zip worker | ||
# can pick it up. | ||
|
||
# Zip_info is too large for the request body (hard limit by Azure). So we use the claim check pattern. | ||
# First, the jobs/zip_info is stored as a blob in the storage_account. Then we send a reference to the blob to the queue | ||
blob_name = str(uuid.uuid4()) | ||
zip_job = json.dumps( | ||
{ | ||
key: zip_info[key] | ||
for key in ["email_address", "scope", "is_mail_login", "urls"] | ||
} | ||
) | ||
store_blob_on_storage_account( | ||
settings.STORAGE_ACCOUNT_CONTAINER_ZIP_QUEUE_JOBS_NAME, blob_name, zip_job | ||
) | ||
zip_tools.store_zip_job(blob_name) | ||
|
||
# Respond with a 200 to signal success. | ||
# The user will get an email once the files have been zipped by a worker. | ||
return HttpResponse() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove todo? We were not going to add this anymore right?