18
18
ACLInterfaceAssignment ,
19
19
ACLStandardRule ,
20
20
)
21
- from .nested_serializers import NestedAccessListSerializer
22
21
23
22
__all__ = [
24
23
"AccessListSerializer" ,
33
32
error_message_action_remark_source_prefix_set = "Action is set to remark, Source Prefix CANNOT be set."
34
33
# Sets a standard error message for ACL rules with an action not set to remark, but no remark is set.
35
34
error_message_remark_without_action_remark = "CANNOT set remark unless action is set to remark."
36
- # Sets a standard error message for ACL rules no associated to an ACL of the same type.
35
+ # Sets a standard error message for ACL rules no associated with an ACL of the same type.
37
36
error_message_acl_type = "Provided parent Access List is not of right type."
38
37
39
38
40
39
class AccessListSerializer (NetBoxModelSerializer ):
41
40
"""
42
- Defines the serializer for the django AccessList model & associates it to a view.
41
+ Defines the serializer for the django AccessList model and associates it with a view.
43
42
"""
44
43
45
44
url = serializers .HyperlinkedIdentityField (
@@ -106,13 +105,13 @@ def validate(self, data):
106
105
107
106
class ACLInterfaceAssignmentSerializer (NetBoxModelSerializer ):
108
107
"""
109
- Defines the serializer for the django ACLInterfaceAssignment model & associates it to a view.
108
+ Defines the serializer for the django ACLInterfaceAssignment model and associates it with a view.
110
109
"""
111
110
112
111
url = serializers .HyperlinkedIdentityField (
113
112
view_name = "plugins-api:netbox_acls-api:aclinterfaceassignment-detail" ,
114
113
)
115
- access_list = NestedAccessListSerializer ( )
114
+ access_list = AccessListSerializer ( nested = True , required = True )
116
115
assigned_object_type = ContentTypeField (
117
116
queryset = ContentType .objects .filter (ACL_INTERFACE_ASSIGNMENT_MODELS ),
118
117
)
@@ -142,9 +141,7 @@ class Meta:
142
141
143
142
@extend_schema_field (serializers .DictField ())
144
143
def get_assigned_object (self , obj ):
145
- serializer = get_serializer_for_model (
146
- obj .assigned_object
147
- )
144
+ serializer = get_serializer_for_model (obj .assigned_object )
148
145
context = {"request" : self .context ["request" ]}
149
146
return serializer (obj .assigned_object , nested = True , context = context ).data
150
147
@@ -160,7 +157,9 @@ def validate(self, data):
160
157
if data ["assigned_object_type" ].model == "interface" :
161
158
interface_host = data ["assigned_object_type" ].get_object_for_this_type (id = data ["assigned_object_id" ]).device
162
159
elif data ["assigned_object_type" ].model == "vminterface" :
163
- interface_host = data ["assigned_object_type" ].get_object_for_this_type (id = data ["assigned_object_id" ]).virtual_machine
160
+ interface_host = (
161
+ data ["assigned_object_type" ].get_object_for_this_type (id = data ["assigned_object_id" ]).virtual_machine
162
+ )
164
163
else :
165
164
interface_host = None
166
165
# Check that the associated interface's parent host has the selected ACL defined.
@@ -177,18 +176,18 @@ def validate(self, data):
177
176
178
177
class ACLStandardRuleSerializer (NetBoxModelSerializer ):
179
178
"""
180
- Defines the serializer for the django ACLStandardRule model & associates it to a view.
179
+ Defines the serializer for the django ACLStandardRule model and associates it with a view.
181
180
"""
182
181
183
182
url = serializers .HyperlinkedIdentityField (
184
183
view_name = "plugins-api:netbox_acls-api:aclstandardrule-detail" ,
185
184
)
186
- access_list = NestedAccessListSerializer ( )
185
+ access_list = AccessListSerializer ( nested = True , required = True )
187
186
source_prefix = PrefixSerializer (
187
+ nested = True ,
188
188
required = False ,
189
189
allow_null = True ,
190
190
default = None ,
191
- nested = True
192
191
)
193
192
194
193
class Meta :
@@ -242,24 +241,24 @@ def validate(self, data):
242
241
243
242
class ACLExtendedRuleSerializer (NetBoxModelSerializer ):
244
243
"""
245
- Defines the serializer for the django ACLExtendedRule model & associates it to a view.
244
+ Defines the serializer for the django ACLExtendedRule model and associates it with a view.
246
245
"""
247
246
248
247
url = serializers .HyperlinkedIdentityField (
249
248
view_name = "plugins-api:netbox_acls-api:aclextendedrule-detail" ,
250
249
)
251
- access_list = NestedAccessListSerializer ( )
250
+ access_list = AccessListSerializer ( nested = True , required = True )
252
251
source_prefix = PrefixSerializer (
252
+ nested = True ,
253
253
required = False ,
254
254
allow_null = True ,
255
255
default = None ,
256
- nested = True
257
256
)
258
257
destination_prefix = PrefixSerializer (
258
+ nested = True ,
259
259
required = False ,
260
260
allow_null = True ,
261
261
default = None ,
262
- nested = True
263
262
)
264
263
265
264
class Meta :
@@ -288,6 +287,7 @@ class Meta:
288
287
"remark" ,
289
288
)
290
289
brief_fields = ("id" , "url" , "display" )
290
+
291
291
def validate (self , data ):
292
292
"""
293
293
Validate the ACLExtendedRule django model's inputs before allowing it to update the instance:
0 commit comments