Use utils function to parse datetime strings

Rather than hard-coding a format string in a bunch of different places
we can use the function we already have in utils.

This commit also refactors some logic around password resets to put the
date-parsing changes in the most sensible bit of the codebase, so it’s
clearer what the intention of the view-layer code is.
This commit is contained in:
Chris Hill-Scott
2020-01-21 12:23:30 +00:00
parent 87b2686875
commit d93866bc7e
4 changed files with 25 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
from flask import abort, current_app, request, session
from flask_login import AnonymousUserMixin, UserMixin, login_user
from notifications_python_client.errors import HTTPError
from notifications_utils.timezones import utc_string_to_aware_gmt_datetime
from werkzeug.utils import cached_property
from app.models import JSONModel, ModelList
@@ -108,6 +109,15 @@ class User(JSONModel, UserMixin):
response = user_api_client.update_password(self.id, password)
self.__init__(response)
def password_changed_more_recently_than(self, datetime_string):
if not self.password_changed_at:
return False
return utc_string_to_aware_gmt_datetime(
self.password_changed_at
) > utc_string_to_aware_gmt_datetime(
datetime_string
)
def set_permissions(self, service_id, permissions, folder_permissions):
user_api_client.set_user_permissions(
self.id,