diff --git a/core/datetimes/ad_datetime.py b/core/datetimes/ad_datetime.py index bda6655..af72e53 100644 --- a/core/datetimes/ad_datetime.py +++ b/core/datetimes/ad_datetime.py @@ -1,5 +1,6 @@ import sys import datetime as py_datetime +from functools import total_ordering from .shared import datetimedelta __all__ = ["tzinfo", "timezone", "AdDate", "date", "AdDatetime", "datetime"] @@ -14,7 +15,7 @@ tzinfo = py_datetime.tzinfo timezone = py_datetime.timezone - +@total_ordering class AdDate(py_datetime.date): @classmethod @@ -78,15 +79,33 @@ def __repr__(self): del L[-1] if L[-1] == 0: del L[-1] - return "%s.date(%s)" % (self.__class__.__module__, - ", ".join(map(str, L))) + return "%s.date(%s)" % (self.__class__.__module__, ", ".join(map(str, L))) + + def _date_operation(self, operation, other): + if not other: + return operation(other) + if isinstance(other, py_datetime.date): + return operation(other) + if isinstance(other, py_datetime.datetime): + return operation(AdDatetime.from_ad_datetime(other)) + def __eq__(self, other): + result = self._date_operation(super(AdDate, self).__eq__, other) + return result if result else self - other == datetimedelta() + + def __gt__(self, other): + return self._date_operation(super(AdDate, self).__gt__, other) + + def __lt__(self, other): + return self._date_operation(super(AdDate, self).__lt__, other) + + date = AdDate date.min = AdDate(1, 1, 1) date.max = AdDate(9999, 12, 31) - +@total_ordering class AdDatetime(py_datetime.datetime): @classmethod diff --git a/core/schema.py b/core/schema.py index 14613b2..fe96f46 100644 --- a/core/schema.py +++ b/core/schema.py @@ -1534,7 +1534,7 @@ def update_or_create_user(data, user): if uuid.UUID(str(user_uuid)) == uuid.UUID(str(user.id)) and user.is_imis_admin and imis_administrator_system not in data.get("roles", []): raise ValidationError("Administrator cannot deprovision himself.") - current_user = InteractiveUser.objects.filter(user__id=data['uuid']).first() + current_user = InteractiveUser.objects.filter(user__id=user_uuid).first() current_email = current_user.email if current_user else None diff --git a/core/services/userServices.py b/core/services/userServices.py index 2483339..7de44f9 100644 --- a/core/services/userServices.py +++ b/core/services/userServices.py @@ -14,6 +14,8 @@ from core.validation.obligatoryFieldValidation import validate_payload_for_obligatory_fields from django.contrib.auth import authenticate from rest_framework import exceptions +from core.utils import filter_validity +from django.db.models import Q logger = logging.getLogger(__file__) @@ -284,7 +286,15 @@ def check_user_unique_email(user_email): def reset_user_password(request, username): - user = User.objects.get(username=username) + user = User.objects.filter( + Q(username=username) | Q(i_user__email=username), + *filter_validity(), + *filter_validity(prefix='i_user__') + ).first() + # we don't want to inform is a username was not found + if not user: + return None + user.clear_refresh_tokens() if not user.email: