diff --git a/fittrackee/migrations/versions/24_cd0e6cf83207_add_ascent_record.py b/fittrackee/migrations/versions/24_cd0e6cf83207_add_ascent_record.py index 1129588e..760ec9d6 100644 --- a/fittrackee/migrations/versions/24_cd0e6cf83207_add_ascent_record.py +++ b/fittrackee/migrations/versions/24_cd0e6cf83207_add_ascent_record.py @@ -23,8 +23,16 @@ def upgrade(): """ ) + op.add_column( + 'users', sa.Column('display_ascent', sa.Boolean(), nullable=True) + ) + op.execute("UPDATE users SET display_ascent = true") + op.alter_column('users', 'display_ascent', nullable=False) + def downgrade(): + op.drop_column('users', 'display_ascent') + op.execute("DELETE FROM records WHERE record_type = 'HA';") op.execute("ALTER TYPE record_types RENAME TO record_types_old") op.execute("CREATE TYPE record_types AS ENUM('AS', 'FD', 'LD', 'MS')") diff --git a/fittrackee/tests/users/test_auth_api.py b/fittrackee/tests/users/test_auth_api.py index 3404e14a..96ff3bf5 100644 --- a/fittrackee/tests/users/test_auth_api.py +++ b/fittrackee/tests/users/test_auth_api.py @@ -1272,6 +1272,7 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin): weekm=True, language=input_language, imperial_units=True, + display_ascent=False, ) ), headers=dict(Authorization=f'Bearer {auth_token}'), @@ -1281,8 +1282,11 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin): data = json.loads(response.data.decode()) assert data['status'] == 'success' assert data['message'] == 'user preferences updated' + assert data['data']['display_ascent'] is False + assert data['data']['imperial_units'] is True assert data['data']['language'] == expected_language - assert data['data'] == jsonify_dict(user_1.serialize(user_1)) + assert data['data']['timezone'] == 'America/New_York' + assert data['data']['weekm'] is True class TestUserSportPreferencesUpdate(ApiTestCaseMixin): diff --git a/fittrackee/tests/users/test_users_model.py b/fittrackee/tests/users/test_users_model.py index 93a5e0c1..54694205 100644 --- a/fittrackee/tests/users/test_users_model.py +++ b/fittrackee/tests/users/test_users_model.py @@ -66,6 +66,7 @@ class TestUserSerializeAsAuthUser(UserModelAssertMixin): assert serialized_user['language'] == user_1.language assert serialized_user['timezone'] == user_1.timezone assert serialized_user['weekm'] == user_1.weekm + assert serialized_user['display_ascent'] == user_1.display_ascent def test_it_returns_workouts_infos(self, app: Flask, user_1: User) -> None: serialized_user = user_1.serialize(user_1) diff --git a/fittrackee/users/auth.py b/fittrackee/users/auth.py index ddaf8511..080de45e 100644 --- a/fittrackee/users/auth.py +++ b/fittrackee/users/auth.py @@ -830,6 +830,7 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]: # get post data post_data = request.get_json() user_mandatory_data = { + 'display_ascent', 'imperial_units', 'language', 'timezone', @@ -838,12 +839,14 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]: if not post_data or not post_data.keys() >= user_mandatory_data: return InvalidPayloadErrorResponse() + display_ascent = post_data.get('display_ascent') imperial_units = post_data.get('imperial_units') language = get_language(post_data.get('language')) timezone = post_data.get('timezone') weekm = post_data.get('weekm') try: + auth_user.display_ascent = display_ascent auth_user.imperial_units = imperial_units auth_user.language = language auth_user.timezone = timezone diff --git a/fittrackee/users/models.py b/fittrackee/users/models.py index bc19df4c..b10541c2 100644 --- a/fittrackee/users/models.py +++ b/fittrackee/users/models.py @@ -50,6 +50,7 @@ class User(BaseModel): is_active = db.Column(db.Boolean, default=False, nullable=False) email_to_confirm = db.Column(db.String(255), nullable=True) confirmation_token = db.Column(db.String(255), nullable=True) + display_ascent = db.Column(db.Boolean, default=True, nullable=False) def __repr__(self) -> str: return f'' @@ -170,6 +171,7 @@ class User(BaseModel): serialized_user = { **serialized_user, **{ + 'display_ascent': self.display_ascent, 'imperial_units': self.imperial_units, 'language': self.language, 'timezone': self.timezone,