API - it returns if user accepted to last privacy policy
This commit is contained in:
parent
f37cecec78
commit
1c1d2a77b7
@ -35,6 +35,7 @@ def update_app_config_from_database(
|
||||
current_app.config[
|
||||
'is_registration_enabled'
|
||||
] = db_config.is_registration_enabled
|
||||
current_app.config['privacy_policy_date'] = db_config.privacy_policy_date
|
||||
|
||||
|
||||
def verify_app_config(config_data: Dict) -> List:
|
||||
|
@ -78,15 +78,45 @@ class TestUserSerializeAsAuthUser(UserModelAssertMixin):
|
||||
|
||||
self.assert_workouts_keys_are_present(serialized_user)
|
||||
|
||||
def test_it_returns_accepted_privacy_policy_date(
|
||||
def test_it_returns_user_did_not_accept_default_privacy_policy(
|
||||
self, app: Flask, user_1: User
|
||||
) -> None:
|
||||
# default privacy policy
|
||||
app.config['privacy_policy_date'] = None
|
||||
user_1.accepted_policy_date = None
|
||||
serialized_user = user_1.serialize(user_1)
|
||||
|
||||
assert (
|
||||
serialized_user['accepted_policy_date']
|
||||
== user_1.accepted_policy_date
|
||||
)
|
||||
assert serialized_user['accepted_privacy_policy'] is False
|
||||
|
||||
def test_it_returns_user_did_accept_default_privacy_policy(
|
||||
self, app: Flask, user_1: User
|
||||
) -> None:
|
||||
# default privacy policy
|
||||
app.config['privacy_policy_date'] = None
|
||||
user_1.accepted_policy_date = datetime.utcnow()
|
||||
serialized_user = user_1.serialize(user_1)
|
||||
|
||||
assert serialized_user['accepted_privacy_policy'] is True
|
||||
|
||||
def test_it_returns_user_did_not_accept_last_policy(
|
||||
self, app: Flask, user_1: User
|
||||
) -> None:
|
||||
user_1.accepted_policy_date = datetime.utcnow()
|
||||
# custom privacy policy
|
||||
app.config['privacy_policy_date'] = datetime.utcnow()
|
||||
serialized_user = user_1.serialize(user_1)
|
||||
|
||||
assert serialized_user['accepted_privacy_policy'] is False
|
||||
|
||||
def test_it_returns_user_did_accept_last_policy(
|
||||
self, app: Flask, user_1: User
|
||||
) -> None:
|
||||
# custom privacy policy
|
||||
app.config['privacy_policy_date'] = datetime.utcnow()
|
||||
user_1.accepted_policy_date = datetime.utcnow()
|
||||
serialized_user = user_1.serialize(user_1)
|
||||
|
||||
assert serialized_user['accepted_privacy_policy'] is True
|
||||
|
||||
def test_it_does_not_return_confirmation_token(
|
||||
self, app: Flask, user_1_admin: User, user_2: User
|
||||
@ -133,7 +163,7 @@ class TestUserSerializeAsAdmin(UserModelAssertMixin):
|
||||
) -> None:
|
||||
serialized_user = user_2.serialize(user_1_admin)
|
||||
|
||||
assert 'accepted_policy_date' not in serialized_user
|
||||
assert 'accepted_privacy_policy' not in serialized_user
|
||||
|
||||
def test_it_does_not_return_confirmation_token(
|
||||
self, app: Flask, user_1_admin: User, user_2: User
|
||||
|
@ -189,10 +189,18 @@ class User(BaseModel):
|
||||
'username': self.username,
|
||||
}
|
||||
if role == UserRole.AUTH_USER:
|
||||
accepted_privacy_policy = False
|
||||
if self.accepted_policy_date:
|
||||
accepted_privacy_policy = (
|
||||
True
|
||||
if current_app.config['privacy_policy_date'] is None
|
||||
else current_app.config['privacy_policy_date']
|
||||
< self.accepted_policy_date
|
||||
)
|
||||
serialized_user = {
|
||||
**serialized_user,
|
||||
**{
|
||||
'accepted_policy_date': self.accepted_policy_date,
|
||||
'accepted_privacy_policy': accepted_privacy_policy,
|
||||
'date_format': self.date_format,
|
||||
'display_ascent': self.display_ascent,
|
||||
'imperial_units': self.imperial_units,
|
||||
|
Loading…
Reference in New Issue
Block a user