Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Drop the PowerSync handler for the legacy weight table

Roland Geider972affc95afa
diff --git a/wger/core/api/views.py b/wger/core/api/views.py
index d40a4d0b3..f041ee4da 100644
--- a/wger/core/api/views.py
+++ b/wger/core/api/views.py
@@ -68,7 +68,6 @@ import wger.gallery.powersync # noqa: F401
import wger.manager.powersync # noqa: F401
import wger.measurements.powersync # noqa: F401
import wger.nutrition.powersync # noqa: F401
-import wger.weight.powersync # noqa: F401
from wger.core.api import powersync
from wger.core.api.serializers import (
LanguageCheckSerializer,
diff --git a/wger/utils/powersync.py b/wger/utils/powersync.py
index 29aa341ff..ddb266cae 100644
--- a/wger/utils/powersync.py
+++ b/wger/utils/powersync.py
@@ -63,12 +63,11 @@ class PowerSyncHandler:
# Set to a ViewSet class to enable check_fk_ownership against
# ``ViewSetClass.get_owner_objects()``. Leave as None if the model has
- # no FKs that need ownership-validation (e.g. WeightEntry).
+ # no FKs that need ownership-validation.
viewset_class = None
# Lookup config for update/delete:
# Model.objects.get(<lookup_field>=payload['id'], <user_filter>=user_id)
- # ``lookup_field`` is 'pk' (most models) or 'uuid' (WeightEntry).
# ``user_filter`` is 'user_id' for direct ownership or a chained lookup
# like 'plan__user_id' / 'meal__plan__user_id' / 'category__user_id'.
lookup_field: str = 'pk'
@@ -109,9 +108,9 @@ class PowerSyncHandler:
def create_save_kwargs(self, payload: dict[str, Any], user_id: int) -> dict[str, Any]:
"""
kwargs forwarded to ``serializer.save()`` on create. Default forces the
- owning user. Override for client-supplied UUID PKs (WeightEntry),
- ordering (Meal/MealItem) or models that don't take ``user_id`` because
- ownership rides on a FK chain (LogItem, MealItem).
+ owning user. Override for ordering (Meal/MealItem) or models that
+ don't take ``user_id`` because ownership rides on a FK chain
+ (LogItem, MealItem).
"""
return {'user_id': user_id}
diff --git a/wger/weight/powersync.py b/wger/weight/powersync.py
deleted file mode 100644
index 5a19831c5..000000000
--- a/wger/weight/powersync.py
+++ /dev/null
@@ -1,41 +0,0 @@
-# This file is part of wger Workout Manager.
-#
-# wger Workout Manager is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# wger Workout Manager is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.
-
-# Standard Library
-from typing import Any
-
-# wger
-from wger.utils.powersync import (
- PowerSyncHandler,
- register_handler,
-)
-from wger.weight.api.serializers import WeightEntrySerializer
-from wger.weight.models import WeightEntry
-
-
-@register_handler
-class WeightEntryHandler(PowerSyncHandler):
- """
- Body weight uses a client-supplied UUID as the synchronised primary key,
- so the handler must round-trip the payload's ``id`` into the ``uuid``
- column on create.
- """
-
- model = WeightEntry
- serializer_class = WeightEntrySerializer
- lookup_field = 'uuid'
-
- def create_save_kwargs(self, payload: dict[str, Any], user_id: int) -> dict[str, Any]:
- return {'user_id': user_id, 'uuid': payload['id']}
diff --git a/wger/weight/tests/test_powersync.py b/wger/weight/tests/test_powersync.py
deleted file mode 100644
index 8634af4d8..000000000
--- a/wger/weight/tests/test_powersync.py
+++ /dev/null
@@ -1,51 +0,0 @@
-# This file is part of wger Workout Manager.
-#
-# wger Workout Manager is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# wger Workout Manager is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-
-# wger
-from wger.core.tests import powersync_base_test
-from wger.weight.models import WeightEntry
-
-
-class WeightEntryPowerSyncTestCase(powersync_base_test.PowerSyncResourceTestCase):
- """
- Verify that the PowerSync handlers in wger/weight/powersync.py only let a
- user touch their own WeightEntry rows.
- """
-
- table = 'weight_weightentry'
- resource = WeightEntry
-
- # owned by user 'test'
- pk_owned = '11111111-1111-1111-1111-000000000003'
-
- # The client generates the row's UUID locally and sends it as `id`, the handler
- # must round-trip exactly that value
- create_payload = {
- 'id': '22222222-2222-2222-2222-000000000099',
- 'date': '2030-01-15T10:00:00Z',
- 'weight': '95.5',
- }
- update_payload = {
- 'id': pk_owned,
- 'weight': '88.5',
- }
-
- def _get_entry_for_update(self):
- # WeightEntry's PowerSync handler looks up by uuid, not pk
- return WeightEntry.objects.get(uuid=self.update_payload['id'])
-
- def _client_supplied_id_field(self, obj):
- # WeightEntry has an integer PK plus a separate uuid column; the
- # client-supplied id round-trips into uuid, not pk.
- return obj.uuid