|
| 1 | +import 'package:ht_shared/ht_shared.dart'; |
| 2 | + |
1 | 3 | // ignore_for_file: public_member_api_docs
|
2 | 4 |
|
3 | 5 | /// Defines the roles and permissions used in the RBAC system.
|
|
6 | 8 | /// Roles are defined as constants.
|
7 | 9 | /// The `rolePermissions` map defines which permissions are granted to each role.
|
8 | 10 |
|
9 |
| -library; |
10 |
| - |
11 |
| -/// {@template role} |
12 |
| -/// Defines the available user roles in the system. |
13 |
| -/// {@endtemplate} |
14 |
| -abstract class Role { |
15 |
| - /// Administrator role with full access. |
16 |
| - static const String admin = 'admin'; |
17 |
| - |
18 |
| - /// Standard user role with limited access. |
19 |
| - static const String standardUser = 'standard_user'; |
20 |
| - |
21 |
| - // Add other roles here as needed. |
22 |
| -} |
23 |
| - |
24 |
| -/// {@template permission} |
25 |
| -/// Defines the available permissions in the system. |
26 |
| -/// |
27 |
| -/// Permissions follow the format `resource.action`. |
28 |
| -/// {@endtemplate} |
29 |
| -abstract class Permission { |
30 |
| - // Headline Permissions |
31 |
| - static const String headlineRead = 'headline.read'; |
32 |
| - static const String headlineCreate = 'headline.create'; |
33 |
| - static const String headlineUpdate = 'headline.update'; |
34 |
| - static const String headlineDelete = 'headline.delete'; |
35 |
| - |
36 |
| - // Category Permissions |
37 |
| - static const String categoryRead = 'category.read'; |
38 |
| - static const String categoryCreate = 'category.create'; |
39 |
| - static const String categoryUpdate = 'category.update'; |
40 |
| - static const String categoryDelete = 'category.delete'; |
41 |
| - |
42 |
| - // Source Permissions |
43 |
| - static const String sourceRead = 'source.read'; |
44 |
| - static const String sourceCreate = 'source.create'; |
45 |
| - static const String sourceUpdate = 'source.update'; |
46 |
| - static const String sourceDelete = 'source.delete'; |
47 |
| - |
48 |
| - // Country Permissions |
49 |
| - static const String countryRead = 'country.read'; |
50 |
| - static const String countryCreate = 'country.create'; |
51 |
| - static const String countryUpdate = 'country.update'; |
52 |
| - static const String countryDelete = 'country.delete'; |
53 |
| - |
54 |
| - // User Settings Permissions |
55 |
| - static const String userSettingsRead = 'user_settings.read'; |
56 |
| - static const String userSettingsUpdate = 'user_settings.update'; |
57 |
| - // Note: User settings delete is handled via account deletion, no separate permission needed here. |
58 |
| - |
59 |
| - // Add other resource permissions here as needed. |
60 |
| -} |
61 |
| - |
62 | 11 | /// A map defining which permissions are granted to each role.
|
63 | 12 | ///
|
64 | 13 | /// The key is the role string, and the value is a set of permission strings.
|
65 |
| -final Map<String, Set<String>> rolePermissions = { |
66 |
| - Role.admin: { |
| 14 | +final Map<UserRole, Set<Permission>> rolePermissions = { |
| 15 | + UserRole.admin: { |
67 | 16 | // Admins have all permissions. You might have a more
|
68 | 17 | // sophisticated way to represent this, but listing them explicitly is clear.
|
69 |
| - Permission.headlineRead, |
70 |
| - Permission.headlineCreate, |
71 |
| - Permission.headlineUpdate, |
72 |
| - Permission.headlineDelete, |
73 |
| - Permission.categoryRead, |
74 |
| - Permission.categoryCreate, |
75 |
| - Permission.categoryUpdate, |
76 |
| - Permission.categoryDelete, |
77 |
| - Permission.sourceRead, |
78 |
| - Permission.sourceCreate, |
79 |
| - Permission.sourceUpdate, |
80 |
| - Permission.sourceDelete, |
81 |
| - Permission.countryRead, |
82 |
| - Permission.countryCreate, |
83 |
| - Permission.countryUpdate, |
84 |
| - Permission.countryDelete, |
85 |
| - Permission.userSettingsRead, |
86 |
| - Permission.userSettingsUpdate, |
| 18 | + const Permission(name: 'headlineRead'), |
| 19 | + const Permission(name: 'headlineCreate'), |
| 20 | + const Permission(name: 'headlineUpdate'), |
| 21 | + const Permission(name: 'headlineDelete'), |
| 22 | + const Permission(name: 'categoryRead'), |
| 23 | + const Permission(name: 'categoryCreate'), |
| 24 | + const Permission(name: 'categoryUpdate'), |
| 25 | + const Permission(name: 'categoryDelete'), |
| 26 | + const Permission(name: 'sourceRead'), |
| 27 | + const Permission(name: 'sourceCreate'), |
| 28 | + const Permission(name: 'sourceUpdate'), |
| 29 | + const Permission(name: 'sourceDelete'), |
| 30 | + const Permission(name: 'countryRead'), |
| 31 | + const Permission(name: 'countryCreate'), |
| 32 | + const Permission(name: 'countryUpdate'), |
| 33 | + const Permission(name: 'countryDelete'), |
| 34 | + const Permission(name: 'userSettingsRead'), |
| 35 | + const Permission(name: 'userSettingsUpdate'), |
87 | 36 | // Add other admin permissions here.
|
88 | 37 | },
|
89 |
| - Role.standardUser: { |
| 38 | + UserRole.standardUser: { |
90 | 39 | // Standard users can read public data and manage their own settings.
|
91 |
| - Permission.headlineRead, |
92 |
| - Permission.categoryRead, |
93 |
| - Permission.sourceRead, |
94 |
| - Permission.countryRead, |
95 |
| - Permission.userSettingsRead, // Can read their own settings |
96 |
| - Permission.userSettingsUpdate, // Can update their own settings |
| 40 | + const Permission(name: 'headlineRead'), |
| 41 | + const Permission(name: 'categoryRead'), |
| 42 | + const Permission(name: 'sourceRead'), |
| 43 | + const Permission(name: 'countryRead'), |
| 44 | + const Permission(name: 'userSettingsRead'), // Can read their own settings |
| 45 | + const Permission( |
| 46 | + name: 'userSettingsUpdate', |
| 47 | + ), // Can update their own settings |
97 | 48 | // Add other standard user permissions here.
|
98 | 49 | },
|
99 | 50 | // Add mappings for other roles here.
|
|
0 commit comments