Skip to content

Commit 8e0b504

Browse files
committed
feat(push_notification): implement user-owned device query and permission
- Add push_notification_device readAll operation to DataOperationRegistry - Update ModelActionPermission for collection and item GET for push_notification_device - Allow authenticated users to fetch their own notification devices - Implement ownership check for specific device retrieval
1 parent 599317e commit 8e0b504

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/src/registry/data_operation_registry.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ class DataOperationRegistry {
184184
sort: s,
185185
pagination: p,
186186
),
187+
'push_notification_device': (c, uid, f, s, p) =>
188+
c.read<DataRepository<PushNotificationDevice>>().readAll(
189+
userId: uid,
190+
filter: f,
191+
sort: s,
192+
pagination: p,
193+
),
187194
});
188195

189196
// --- Register Item Creators ---

lib/src/registry/model_registry.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,19 @@ final modelRegistry = <String, ModelConfig<dynamic>>{
429429
fromJson: PushNotificationDevice.fromJson,
430430
getId: (d) => d.id,
431431
getOwnerId: (dynamic item) => (item as PushNotificationDevice).userId,
432+
// Collection GET is allowed for a user to fetch their own notification devices.
433+
// The generic route handler will automatically scope the query to the
434+
// authenticated user's ID because `getOwnerId` is defined.
432435
getCollectionPermission: const ModelActionPermission(
433-
type: RequiredPermissionType.unsupported,
436+
type: RequiredPermissionType.specificPermission,
437+
permission: Permissions.pushNotificationDeviceReadOwned,
434438
),
435-
// Required by the ownership check middelware
439+
// Item GET is allowed for a user to fetch a single one of their devices.
440+
// The ownership check middleware will verify they own this specific item.
436441
getItemPermission: const ModelActionPermission(
437-
type: RequiredPermissionType.adminOnly,
442+
type: RequiredPermissionType.specificPermission,
443+
permission: Permissions.pushNotificationDeviceReadOwned,
444+
requiresOwnershipCheck: true,
438445
),
439446
// POST is allowed for any authenticated user to register their own device.
440447
// A custom check within the DataOperationRegistry's creator function will

0 commit comments

Comments
 (0)