From beff5d8f1208b5fbeb0e866a030d103512b8dfb6 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Mon, 9 Dec 2019 05:40:53 +0000 Subject: [PATCH] return patch policy when agent requests new updates --- api/djangormm/winupdate/serializers.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/api/djangormm/winupdate/serializers.py b/api/djangormm/winupdate/serializers.py index 635f90b8..fd8a05c3 100644 --- a/api/djangormm/winupdate/serializers.py +++ b/api/djangormm/winupdate/serializers.py @@ -19,17 +19,22 @@ class UpdateSerializer(serializers.ModelSerializer): "hostname", "winupdates", ) - -class ApprovedUpdateSerializer(serializers.ModelSerializer): - winupdates = WinUpdateSerializer(read_only=True) - agentid = serializers.ReadOnlyField(source='agent.pk') - - class Meta: - model = WinUpdate - fields = ("id", "kb", "guid", "agentid", "winupdates",) - class WinUpdatePolicySerializer(serializers.ModelSerializer): class Meta: model = WinUpdatePolicy - fields = "__all__" \ No newline at end of file + fields = "__all__" + +class ApprovedUpdateSerializer(serializers.ModelSerializer): + winupdates = WinUpdateSerializer(read_only=True) + agentid = serializers.ReadOnlyField(source='agent.pk') + patch_policy = serializers.SerializerMethodField('get_policies') + + def get_policies(self, obj): + policy = WinUpdatePolicy.objects.get(agent=obj.agent) + return WinUpdatePolicySerializer(policy).data + + class Meta: + model = WinUpdate + fields = ("id", "kb", "guid", "agentid", "winupdates", "patch_policy",) +