@@ -17,25 +17,25 @@ import 'package:collection/collection.dart';
17
17
/// );
18
18
/// ```
19
19
@immutable
20
- class Policy {
20
+ class Role {
21
21
/// Creates a new policy with the specified role name and allowed content.
22
22
///
23
- /// The [roleName ] identifies the role this policy applies to.
23
+ /// The [name ] identifies the role this policy applies to.
24
24
/// The [allowedContent] list contains the content types or actions that are
25
25
/// permitted for this role. The [metadata] provides additional configuration
26
26
/// options and defaults to an empty map if not specified.
27
27
///
28
- /// Throws an [ArgumentError] if [roleName ] is empty or [allowedContent] is null.
29
- const Policy ({
30
- required this .roleName ,
28
+ /// Throws an [ArgumentError] if [name ] is empty or [allowedContent] is null.
29
+ const Role ({
30
+ required this .name ,
31
31
required this .allowedContent,
32
32
this .metadata = const {},
33
33
});
34
34
35
35
/// The name of the role this policy applies to.
36
36
///
37
37
/// This should be a unique identifier for the role within your application.
38
- final String roleName ;
38
+ final String name ;
39
39
40
40
/// List of content types or actions that are allowed for this role.
41
41
///
@@ -52,7 +52,7 @@ class Policy {
52
52
53
53
/// Creates a copy of this policy with the given fields replaced by new values.
54
54
///
55
- /// Returns a new [Policy ] instance with the same values as this one,
55
+ /// Returns a new [Role ] instance with the same values as this one,
56
56
/// except for the fields that are explicitly provided in the parameters.
57
57
///
58
58
/// Example:
@@ -62,13 +62,13 @@ class Policy {
62
62
/// metadata: {'priority': 'low'},
63
63
/// );
64
64
/// ```
65
- Policy copyWith ({
66
- String ? roleName ,
65
+ Role copyWith ({
66
+ String ? name ,
67
67
List <String >? allowedContent,
68
68
Map <String , dynamic >? metadata,
69
69
}) =>
70
- Policy (
71
- roleName : roleName ?? this .roleName ,
70
+ Role (
71
+ name : name ?? this .name ,
72
72
allowedContent: allowedContent ?? this .allowedContent,
73
73
metadata: metadata ?? this .metadata,
74
74
);
@@ -88,15 +88,15 @@ class Policy {
88
88
89
89
/// Compares this policy with another object for equality.
90
90
///
91
- /// Two policies are considered equal if they have the same [roleName ] and
91
+ /// Two policies are considered equal if they have the same [name ] and
92
92
/// the same [allowedContent] (regardless of order). The [metadata] is not
93
93
/// considered in the equality comparison.
94
94
@override
95
95
bool operator == (Object other) {
96
96
if (identical (this , other)) return true ;
97
- if (other is ! Policy ) return false ;
97
+ if (other is ! Role ) return false ;
98
98
99
- if (roleName != other.roleName ) return false ;
99
+ if (name != other.name ) return false ;
100
100
if (allowedContent.length != other.allowedContent.length) return false ;
101
101
102
102
// Sort both lists to ensure order-independent comparison (same as hashCode)
@@ -108,22 +108,22 @@ class Policy {
108
108
109
109
/// Returns the hash code for this policy.
110
110
///
111
- /// The hash code is based on the [roleName ] and [allowedContent] fields.
111
+ /// The hash code is based on the [name ] and [allowedContent] fields.
112
112
/// The allowedContent is sorted to ensure consistent hash codes regardless of order.
113
113
@override
114
114
int get hashCode {
115
115
final sortedContent = List <String >.from (allowedContent)..sort ();
116
- return Object .hash (roleName , const ListEquality ().hash (sortedContent));
116
+ return Object .hash (name , const ListEquality ().hash (sortedContent));
117
117
}
118
118
119
119
/// Returns a string representation of this policy.
120
120
///
121
121
/// The string includes the role name, allowed content, and metadata.
122
122
@override
123
123
String toString () =>
124
- 'Policy(roleName: $roleName , allowedContent: $allowedContent , metadata: $metadata )' ;
124
+ 'Policy(roleName: $name , allowedContent: $allowedContent , metadata: $metadata )' ;
125
125
126
- /// Creates a [Policy ] instance from a JSON map.
126
+ /// Creates a [Role ] instance from a JSON map.
127
127
///
128
128
/// The JSON map should contain:
129
129
/// - `roleName` : A string representing the role name
@@ -141,12 +141,12 @@ class Policy {
141
141
/// };
142
142
/// final policy = Policy.fromJson(json);
143
143
/// ```
144
- factory Policy .fromJson (Map <String , dynamic > json) {
145
- final roleName = json['roleName' ];
144
+ factory Role .fromJson (Map <String , dynamic > json) {
145
+ final name = json['roleName' ];
146
146
final allowedContent = json['allowedContent' ];
147
147
final metadata = json['metadata' ];
148
148
149
- if (roleName == null || roleName is ! String ) {
149
+ if (name == null || name is ! String ) {
150
150
throw ArgumentError ('roleName must be a non-null string' );
151
151
}
152
152
if (allowedContent == null || allowedContent is ! List ) {
@@ -156,8 +156,8 @@ class Policy {
156
156
throw ArgumentError ('All allowedContent items must be strings' );
157
157
}
158
158
159
- return Policy (
160
- roleName : roleName ,
159
+ return Role (
160
+ name : name ,
161
161
allowedContent: allowedContent.cast <String >(),
162
162
metadata:
163
163
metadata is Map <String , dynamic > ? metadata : < String , dynamic > {},
@@ -179,7 +179,7 @@ class Policy {
179
179
/// // }
180
180
/// ```
181
181
Map <String , dynamic > toJson () => {
182
- 'roleName' : roleName ,
182
+ 'roleName' : name ,
183
183
'allowedContent' : allowedContent,
184
184
'metadata' : metadata,
185
185
};
0 commit comments