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

Make invalid input gdpr compliant #562

Open
wants to merge 4 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ stregsystem.log
# nix
.direnv
.envrc
result
result
/.vscode
5 changes: 5 additions & 0 deletions stregsystem/templates/stregsystem/error_invalidquickbuy.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

{% load stregsystem_extras %}

{% block head %}
{{ block.super }}
{% include "stregsystem/gdpr.html" %}
{% endblock %}

{% block headline %}
<div>Du forsøgte at bruge quickbuy men fejlede.</div>
<div>This incident will be reported.</div>
Expand Down
27 changes: 26 additions & 1 deletion stregsystem/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@
)
from stregsystem.purchase_heatmap import prepare_heatmap_template_context
from stregsystem.templatetags.stregsystem_extras import caffeine_emoji_render
from stregsystem.utils import mobile_payment_exact_match_member, strip_emoji, PaymentToolException
from stregsystem.utils import (
mobile_payment_exact_match_member,
strip_emoji,
PaymentToolException,
insert_gdpr_span,
)
from stregsystem.mail import data_sent


Expand Down Expand Up @@ -2283,3 +2288,23 @@ def test_welcome_mail_paid_approved(self, mock_mail_method: MagicMock):

signup_request.approve()
mock_mail_method.assert_called_once()


class MiscUtilTests(TestCase):
fixtures = ['initial_data']

def test_gdpr_is_inserted(self):
assumed_user = "jokke"
assumed_non_user = "nonuser"

simple_quickbuy = assumed_user
simple_gdpr_quickbuy = insert_gdpr_span(simple_quickbuy)
expected_simple_gdpr_quickbuy = '<span class="username">' + assumed_user + '</span>'

self.assertEqual(simple_gdpr_quickbuy, expected_simple_gdpr_quickbuy)

advanced_quickbuy = assumed_user + " " + assumed_non_user
advanced_gdpr_quickbuy = insert_gdpr_span(advanced_quickbuy)
expected_advanced_gdpr_quickbuy = '<span class="username">' + assumed_user + '</span> ' + assumed_non_user

self.assertEqual(advanced_gdpr_quickbuy, expected_advanced_gdpr_quickbuy)
15 changes: 15 additions & 0 deletions stregsystem/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,21 @@ def mobilepay_launch_uri(comment: str, amount: float) -> str:
return 'mobilepay://send?{}'.format(urllib.parse.urlencode(query))


def insert_gdpr_span(text: str) -> str:
from stregsystem.models import Member

parts = text.split(' ')

for i, part in enumerate(parts):
try:
Member.objects.get(username__iexact=part)
parts[i] = '<span class="username">' + part + '</span>'
except Member.DoesNotExist:
continue

return " ".join(parts)


class stregsystemTestRunner(DiscoverRunner):
def __init__(self, *args, **kwargs):
settings.TEST_MODE = True
Expand Down
10 changes: 8 additions & 2 deletions stregsystem/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
namedtuple,
)

from django.utils.safestring import mark_safe

from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.decorators import permission_required
from django.core import management
Expand Down Expand Up @@ -54,6 +56,7 @@
parse_csv_and_create_mobile_payments,
PaymentToolException,
make_unprocessed_signups_query,
insert_gdpr_span,
)

from .booze import ballmer_peak
Expand Down Expand Up @@ -131,9 +134,12 @@ def sale(request, room_id):
try:
username, bought_ids = parser.parse(_pre_process(buy_string))
except parser.QuickBuyError as err:
correct = mark_safe(insert_gdpr_span(err.parsed_part))
incorrect = mark_safe(insert_gdpr_span(err.failed_part))

values = {
'correct': err.parsed_part,
'incorrect': err.failed_part,
'correct': correct,
'incorrect': incorrect,
'error_ptr': '~' * (len(err.parsed_part)) + '^',
'error_msg': ' ' * (len(err.parsed_part) - 4) + 'Fejl her',
'room': room,
Expand Down
Loading