Skip to content

Commit

Permalink
Merge pull request #352 from openimis/release/24.10
Browse files Browse the repository at this point in the history
MERGING release/24.10 into develop
  • Loading branch information
delcroip authored Nov 1, 2024
2 parents d553fb9 + 47e1577 commit d3aa537
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
27 changes: 23 additions & 4 deletions core/datetimes/ad_datetime.py
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -14,7 +15,7 @@
tzinfo = py_datetime.tzinfo
timezone = py_datetime.timezone


@total_ordering
class AdDate(py_datetime.date):

@classmethod
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion core/services/userServices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d3aa537

Please sign in to comment.