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