Compare commits

..
Author SHA1 Message Date
Richard Schreiber 5e8cf1833b Allow discount reordering to use int as well as str 2026-11-17 15:46:19 +01:00
5 changed files with 12 additions and 21 deletions

No files matched your search

+1
View File
@@ -80,6 +80,7 @@ dependencies = [
"psycopg2-binary",
"pycountry",
"pycparser==3.12",
"pycryptodome==3.24.*",
"pypdf==6.21.*",
"python-bidi==0.6.*", # Support for Arabic in reportlab
"python-dateutil==4.0.*",
+3 -2
View File
@@ -256,8 +256,9 @@ def reorder_discounts(request, organizer, event):
ids = json.loads(request.body.decode('utf-8'))['ids']
except (JSONDecodeError, KeyError, ValueError):
return HttpResponseBadRequest("expected JSON: {ids:[]}")
ids = [int(i) for i in ids if isinstance(i, int) or i.isdigit()]
input_discounts = list(request.event.discounts.filter(id__in=[i for i in ids if i.isdigit()]))
input_discounts = list(request.event.discounts.filter(id__in=ids))
if len(input_discounts) != len(ids):
raise Http404(_("Some of the provided object ids are invalid."))
@@ -266,7 +267,7 @@ def reorder_discounts(request, organizer, event):
raise Http404(_("Not all discounts have been selected."))
for c in input_discounts:
pos = ids.index(str(c.pk))
pos = ids.index(c.pk)
if pos != c.position: # Save unneccessary UPDATE queries
c.position = pos
c.save(update_fields=['position'])
+1 -1
View File
@@ -267,7 +267,7 @@ class CustomerStep(CartMixin, TemplateFlowStep):
else None
),
prefix='login',
request=self.request,
request=self.request.event,
)
for field in f.fields.values():
field._show_required = field.required
+4 -7
View File
@@ -26,8 +26,7 @@ from binascii import unhexlify
from datetime import timedelta
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
from cryptography.hazmat.primitives.serialization import load_pem_public_key
from Crypto.PublicKey import RSA
from django.db import transaction
from django.http import Http404, HttpResponse, JsonResponse
from django.shortcuts import redirect, render
@@ -499,9 +498,7 @@ class KeysView(View):
def get(self, request, *args, **kwargs):
privkey, pubkey = _get_or_create_server_keypair(request.organizer)
kid = hashlib.sha256(pubkey.encode()).hexdigest()[:16]
public_key = load_pem_public_key(pubkey.encode())
assert isinstance(public_key, RSAPublicKey)
public_numbers = public_key.public_numbers()
pubkey = RSA.import_key(pubkey)
return JsonResponse({
'keys': [
@@ -510,8 +507,8 @@ class KeysView(View):
'alg': 'RS256',
'kid': kid,
'use': 'sig',
'e': self._encode_int(public_numbers.e).decode().rstrip("="),
'n': self._encode_int(public_numbers.n).decode().rstrip("="),
'e': self._encode_int(pubkey.e).decode().rstrip("="),
'n': self._encode_int(pubkey.n).decode().rstrip("="),
}
]
})
+3 -11
View File
@@ -30,10 +30,7 @@ from urllib.parse import quote
import jwt
import pytest
from bs4 import BeautifulSoup
from cryptography.hazmat.primitives.asymmetric.rsa import (
RSAPublicKey, RSAPublicNumbers,
)
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat
from Crypto.PublicKey import RSA
from django.utils.timezone import now
from django_scopes import scopes_disabled
from freezegun import freeze_time
@@ -694,11 +691,6 @@ def test_keys_endpoint(env, client, ssoclient):
e = decode_int(data['keys'][0]['e'])
n = decode_int(data['keys'][0]['n'])
pubkey = RSAPublicNumbers(e, n).public_key()
assert isinstance(pubkey, RSAPublicKey)
representation = pubkey.public_bytes(
Encoding.PEM, PublicFormat.SubjectPublicKeyInfo
).decode()
pubkey = RSA.construct((n, e))
representation = pubkey.export_key('PEM').decode()
assert representation.strip() == env[0].settings.sso_server_signing_key_rsa256_public.strip()