@@ -68,7 +68,8 @@ class ModelConfig<T> {
68
68
const ModelConfig ({
69
69
required this .fromJson,
70
70
required this .getId,
71
- required this .getPermission,
71
+ required this .getCollectionPermission, // New field for GET collection
72
+ required this .getItemPermission, // New field for GET item
72
73
required this .postPermission,
73
74
required this .putPermission,
74
75
required this .deletePermission,
@@ -86,8 +87,11 @@ class ModelConfig<T> {
86
87
/// is true for any action.
87
88
final String ? Function (T item)? getOwnerId;
88
89
89
- /// Authorization configuration for GET requests.
90
- final ModelActionPermission getPermission;
90
+ /// Authorization configuration for GET requests to the collection endpoint.
91
+ final ModelActionPermission getCollectionPermission;
92
+
93
+ /// Authorization configuration for GET requests to a specific item endpoint.
94
+ final ModelActionPermission getItemPermission;
91
95
92
96
/// Authorization configuration for POST requests.
93
97
final ModelActionPermission postPermission;
@@ -120,7 +124,11 @@ final modelRegistry = <String, ModelConfig<dynamic>>{
120
124
fromJson: Headline .fromJson,
121
125
getId: (h) => h.id,
122
126
// Headlines: Admin-owned, read allowed by standard/guest users
123
- getPermission: const ModelActionPermission (
127
+ getCollectionPermission: const ModelActionPermission (
128
+ type: RequiredPermissionType .specificPermission,
129
+ permission: Permissions .headlineRead,
130
+ ),
131
+ getItemPermission: const ModelActionPermission (
124
132
type: RequiredPermissionType .specificPermission,
125
133
permission: Permissions .headlineRead,
126
134
),
@@ -138,7 +146,11 @@ final modelRegistry = <String, ModelConfig<dynamic>>{
138
146
fromJson: Category .fromJson,
139
147
getId: (c) => c.id,
140
148
// Categories: Admin-owned, read allowed by standard/guest users
141
- getPermission: const ModelActionPermission (
149
+ getCollectionPermission: const ModelActionPermission (
150
+ type: RequiredPermissionType .specificPermission,
151
+ permission: Permissions .categoryRead,
152
+ ),
153
+ getItemPermission: const ModelActionPermission (
142
154
type: RequiredPermissionType .specificPermission,
143
155
permission: Permissions .categoryRead,
144
156
),
@@ -156,7 +168,11 @@ final modelRegistry = <String, ModelConfig<dynamic>>{
156
168
fromJson: Source .fromJson,
157
169
getId: (s) => s.id,
158
170
// Sources: Admin-owned, read allowed by standard/guest users
159
- getPermission: const ModelActionPermission (
171
+ getCollectionPermission: const ModelActionPermission (
172
+ type: RequiredPermissionType .specificPermission,
173
+ permission: Permissions .sourceRead,
174
+ ),
175
+ getItemPermission: const ModelActionPermission (
160
176
type: RequiredPermissionType .specificPermission,
161
177
permission: Permissions .sourceRead,
162
178
),
@@ -174,7 +190,11 @@ final modelRegistry = <String, ModelConfig<dynamic>>{
174
190
fromJson: Country .fromJson,
175
191
getId: (c) => c.id, // Assuming Country has an 'id' field
176
192
// Countries: Admin-owned, read allowed by standard/guest users
177
- getPermission: const ModelActionPermission (
193
+ getCollectionPermission: const ModelActionPermission (
194
+ type: RequiredPermissionType .specificPermission,
195
+ permission: Permissions .countryRead,
196
+ ),
197
+ getItemPermission: const ModelActionPermission (
178
198
type: RequiredPermissionType .specificPermission,
179
199
permission: Permissions .countryRead,
180
200
),
@@ -193,7 +213,10 @@ final modelRegistry = <String, ModelConfig<dynamic>>{
193
213
getId: (u) => u.id,
194
214
getOwnerId: (dynamic item) =>
195
215
(item as User ).id as String ? , // User is the owner of their profile
196
- getPermission: const ModelActionPermission (
216
+ getCollectionPermission: const ModelActionPermission (
217
+ type: RequiredPermissionType .adminOnly, // Only admin can list all users
218
+ ),
219
+ getItemPermission: const ModelActionPermission (
197
220
type: RequiredPermissionType .specificPermission,
198
221
permission: Permissions .userReadOwned, // User can read their own
199
222
requiresOwnershipCheck: true , // Must be the owner
@@ -218,7 +241,10 @@ final modelRegistry = <String, ModelConfig<dynamic>>{
218
241
getId: (s) => s.id,
219
242
getOwnerId: (dynamic item) =>
220
243
(item as UserAppSettings ).id as String ? , // User ID is the owner ID
221
- getPermission: const ModelActionPermission (
244
+ getCollectionPermission: const ModelActionPermission (
245
+ type: RequiredPermissionType .unsupported, // Not accessible via collection
246
+ ),
247
+ getItemPermission: const ModelActionPermission (
222
248
type: RequiredPermissionType .specificPermission,
223
249
permission: Permissions .appSettingsReadOwned,
224
250
requiresOwnershipCheck: true ,
@@ -244,7 +270,10 @@ final modelRegistry = <String, ModelConfig<dynamic>>{
244
270
getId: (p) => p.id,
245
271
getOwnerId: (dynamic item) => (item as UserContentPreferences ).id
246
272
as String ? , // User ID is the owner ID
247
- getPermission: const ModelActionPermission (
273
+ getCollectionPermission: const ModelActionPermission (
274
+ type: RequiredPermissionType .unsupported, // Not accessible via collection
275
+ ),
276
+ getItemPermission: const ModelActionPermission (
248
277
type: RequiredPermissionType .specificPermission,
249
278
permission: Permissions .userPreferencesReadOwned,
250
279
requiresOwnershipCheck: true ,
@@ -269,9 +298,12 @@ final modelRegistry = <String, ModelConfig<dynamic>>{
269
298
fromJson: AppConfig .fromJson,
270
299
getId: (config) => config.id,
271
300
getOwnerId: null , // AppConfig is a global resource, not user-owned
272
- getPermission: const ModelActionPermission (
301
+ getCollectionPermission: const ModelActionPermission (
302
+ type: RequiredPermissionType .unsupported, // Not accessible via collection
303
+ ),
304
+ getItemPermission: const ModelActionPermission (
273
305
type: RequiredPermissionType
274
- .none, // Readable by any authenticated user via /api/v1/data
306
+ .none, // Readable by any authenticated user via /api/v1/data/[id]
275
307
),
276
308
postPermission: const ModelActionPermission (
277
309
type: RequiredPermissionType .adminOnly, // Only administrators can create
0 commit comments