|
1 | 1 | import 'package:ht_api/src/rbac/permissions.dart';
|
2 | 2 | import 'package:ht_shared/ht_shared.dart';
|
3 | 3 |
|
4 |
| -final Set<String> _guestUserPermissions = { |
| 4 | +// --- App Role Permissions --- |
| 5 | + |
| 6 | +final Set<String> _appGuestUserPermissions = { |
5 | 7 | Permissions.headlineRead,
|
6 |
| - Permissions.categoryRead, |
| 8 | + Permissions.topicRead, |
7 | 9 | Permissions.sourceRead,
|
8 | 10 | Permissions.countryRead,
|
9 |
| - Permissions.appSettingsReadOwned, |
10 |
| - Permissions.appSettingsUpdateOwned, |
11 |
| - Permissions.userPreferencesReadOwned, |
12 |
| - Permissions.userPreferencesUpdateOwned, |
13 |
| - Permissions.appConfigRead, |
| 11 | + Permissions.userAppSettingsReadOwned, |
| 12 | + Permissions.userAppSettingsUpdateOwned, |
| 13 | + Permissions.userContentPreferencesReadOwned, |
| 14 | + Permissions.userContentPreferencesUpdateOwned, |
| 15 | + Permissions.remoteConfigRead, |
14 | 16 | };
|
15 | 17 |
|
16 |
| -final Set<String> _standardUserPermissions = { |
17 |
| - ..._guestUserPermissions, |
| 18 | +final Set<String> _appStandardUserPermissions = { |
| 19 | + ..._appGuestUserPermissions, |
18 | 20 | Permissions.userReadOwned,
|
19 | 21 | Permissions.userUpdateOwned,
|
20 | 22 | Permissions.userDeleteOwned,
|
21 | 23 | };
|
22 | 24 |
|
23 |
| -// For now, premium users have the same permissions as standard users, |
24 |
| -// but this set can be expanded later for premium-specific features. |
25 |
| -final Set<String> _premiumUserPermissions = {..._standardUserPermissions}; |
| 25 | +final Set<String> _appPremiumUserPermissions = { |
| 26 | + ..._appStandardUserPermissions, |
| 27 | + // Future premium-only permissions can be added here. |
| 28 | +}; |
| 29 | + |
| 30 | +// --- Dashboard Role Permissions --- |
26 | 31 |
|
27 |
| -final Set<String> _publisherPermissions = { |
28 |
| - ..._standardUserPermissions, |
| 32 | +final Set<String> _dashboardPublisherPermissions = { |
29 | 33 | Permissions.headlineCreate,
|
30 | 34 | Permissions.headlineUpdate,
|
31 | 35 | Permissions.headlineDelete,
|
32 | 36 | };
|
33 | 37 |
|
34 |
| -final Set<String> _adminPermissions = { |
35 |
| - ..._standardUserPermissions, |
36 |
| - Permissions.headlineCreate, |
37 |
| - Permissions.headlineUpdate, |
38 |
| - Permissions.headlineDelete, |
39 |
| - Permissions.categoryCreate, |
40 |
| - Permissions.categoryUpdate, |
41 |
| - Permissions.categoryDelete, |
| 38 | +final Set<String> _dashboardAdminPermissions = { |
| 39 | + ..._dashboardPublisherPermissions, |
| 40 | + Permissions.topicCreate, |
| 41 | + Permissions.topicUpdate, |
| 42 | + Permissions.topicDelete, |
42 | 43 | Permissions.sourceCreate,
|
43 | 44 | Permissions.sourceUpdate,
|
44 | 45 | Permissions.sourceDelete,
|
45 | 46 | Permissions.countryCreate,
|
46 | 47 | Permissions.countryUpdate,
|
47 | 48 | Permissions.countryDelete,
|
48 |
| - Permissions.userRead, |
49 |
| - Permissions.appConfigCreate, |
50 |
| - Permissions.appConfigUpdate, |
51 |
| - Permissions.appConfigDelete, |
| 49 | + Permissions.userRead, // Allows reading any user's profile |
| 50 | + Permissions.remoteConfigCreate, |
| 51 | + Permissions.remoteConfigUpdate, |
| 52 | + Permissions.remoteConfigDelete, |
52 | 53 | };
|
53 | 54 |
|
54 |
| -/// Defines the mapping between user roles and the permissions they possess. |
55 |
| -/// |
56 |
| -/// This map is the core of the Role-Based Access Control (RBAC) system. |
57 |
| -/// Each key is a role string, and the associated value is a [Set] of |
58 |
| -/// [Permissions] strings that users with that role are granted. |
| 55 | +/// Defines the mapping between user roles (both app and dashboard) and the |
| 56 | +/// permissions they possess. |
59 | 57 | ///
|
60 |
| -/// Note: Administrators typically have implicit access to all resources |
61 |
| -/// regardless of this map, but including their permissions here can aid |
62 |
| -/// documentation and clarity. The `PermissionService` should handle the |
63 |
| -/// explicit admin bypass if desired. |
64 |
| -final Map<String, Set<String>> rolePermissions = { |
65 |
| - UserRoles.guestUser: _guestUserPermissions, |
66 |
| - UserRoles.standardUser: _standardUserPermissions, |
67 |
| - UserRoles.premiumUser: _premiumUserPermissions, |
68 |
| - UserRoles.publisher: _publisherPermissions, |
69 |
| - UserRoles.admin: _adminPermissions, |
| 58 | +/// The `PermissionService` will look up a user's `appRole` and |
| 59 | +/// `dashboardRole` in this map and combine the resulting permission sets to |
| 60 | +/// determine their total access rights. |
| 61 | +final Map<Enum, Set<String>> rolePermissions = { |
| 62 | + // App Roles |
| 63 | + AppUserRole.guestUser: _appGuestUserPermissions, |
| 64 | + AppUserRole.standardUser: _appStandardUserPermissions, |
| 65 | + AppUserRole.premiumUser: _appPremiumUserPermissions, |
| 66 | + // Dashboard Roles |
| 67 | + DashboardUserRole.none: {}, |
| 68 | + DashboardUserRole.publisher: _dashboardPublisherPermissions, |
| 69 | + DashboardUser-Role.admin: _dashboardAdminPermissions, |
70 | 70 | };
|
0 commit comments