@@ -25,44 +25,17 @@ class Meta:
25
25
fields = ['api_slug' , 'codename' , 'content_type' , 'name' ]
26
26
27
27
28
- class ObjectIDAnsibleIDField (serializers .Field ):
29
- "This is an ansible_id field intended to be used with source pointing to object_id, so, does conversion"
30
-
31
- def to_representation (self , value ):
32
- "The source for this field is object_id, which is ignored, use content_object instead"
33
- assignment = getattr (self , "_this_assignment" , None )
34
- if not assignment :
35
- return None
36
- content_object = assignment .content_object
37
- if isinstance (content_object , RemoteObject ):
38
- return None
39
- if hasattr (content_object , 'resource' ):
40
- return str (content_object .resource .ansible_id )
41
- return None
42
-
43
- def to_internal_value (self , value ):
44
- "Targeting object_id, this converts ansible_id into object_id"
45
- resource_cls = apps .get_model ('dab_resource_registry' , 'Resource' )
46
- resource = resource_cls .objects .get (ansible_id = value )
47
- return resource .object_id
48
-
49
-
50
28
assignment_common_fields = ('created' , 'created_by_ansible_id' , 'object_id' , 'object_ansible_id' , 'content_type' , 'role_definition' )
51
29
52
30
53
31
class BaseAssignmentSerializer (serializers .ModelSerializer ):
54
32
content_type = serializers .SlugRelatedField (read_only = True , slug_field = 'api_slug' )
55
33
role_definition = serializers .SlugRelatedField (slug_field = 'name' , queryset = RoleDefinition .objects .all ())
56
34
created_by_ansible_id = ActorAnsibleIdField (source = 'created_by' , required = False , allow_null = True )
57
- object_ansible_id = ObjectIDAnsibleIDField ( source = 'object_id' , required = False , allow_null = True )
35
+ object_ansible_id = serializers . UUIDField ( read_only = True , allow_null = True )
58
36
object_id = serializers .CharField (allow_blank = True , required = False , allow_null = True )
59
37
from_service = serializers .CharField (write_only = True )
60
38
61
- def to_representation (self , instance ):
62
- # hack to surface content_object for ObjectIDAnsibleIDField
63
- self .fields ["object_ansible_id" ]._this_assignment = instance
64
- return super ().to_representation (instance )
65
-
66
39
def get_created_by_ansible_id (self , obj ):
67
40
return str (obj .created_by .resource .ansible_id )
68
41
0 commit comments