Esempio n. 1
0
    def partial_update(self, request, *args, **kwargs):

        instance_id = kwargs["pk"]
        try:
            before_update = self.get_queryset().get(pk=instance_id)
        except Person.DoesNotExist:
            before_update = None

        kwargs["partial"] = True
        response = self.update(request, *args, **kwargs)

        updated_instance = self.get_object()

        changes = changes_between(model_type="Person", previous=before_update, current=updated_instance)
        log_activity(
            organization_id=self.organization.id,
            team_id=self.team.id,
            user=request.user,
            item_id=instance_id,
            scope="Person",
            activity="updated",
            detail=Detail(changes=changes),
        )

        return response
Esempio n. 2
0
 def test_a_change_of_soft_delete_can_be_logged(self):
     actual = changes_between(
         model_type="FeatureFlag",
         previous=self._a_feature_flag_with(deleted=False,),
         current=self._a_feature_flag_with(deleted=True,),
     )
     expected = [Change(type="FeatureFlag", field="deleted", action="changed", before=False, after=True,)]
     assert actual == expected
Esempio n. 3
0
 def test_a_change_of_rollout_percentage_can_be_logged(self):
     actual = changes_between(
         model_type="FeatureFlag",
         previous=self._a_feature_flag_with(rollout_percentage=12,),
         current=self._a_feature_flag_with(rollout_percentage=23,),
     )
     expected = [Change(type="FeatureFlag", field="rollout_percentage", action="changed", before=12, after=23)]
     assert actual == expected
Esempio n. 4
0
 def test_a_change_of_key_can_be_logged(self):
     actual = changes_between(
         model_type="FeatureFlag",
         previous=self._a_feature_flag_with(key="the-key"),
         current=self._a_feature_flag_with(key="the-new-key"),
     )
     expected = [Change(type="FeatureFlag", field="key", action="changed", before="the-key", after="the-new-key",)]
     assert actual == expected
Esempio n. 5
0
 def test_a_change_of_name_can_be_logged(self):
     actual = changes_between(
         model_type="FeatureFlag",
         previous=self._a_feature_flag_with(name="a"),
         current=self._a_feature_flag_with(name="b"),
     )
     expected = [Change(type="FeatureFlag", field="name", action="changed", before="a", after="b")]
     assert actual == expected
Esempio n. 6
0
 def test_a_change_of_filters_can_be_logged(self):
     actual = changes_between(
         model_type="FeatureFlag",
         previous=self._a_feature_flag_with(filters={"some": "value"},),
         current=self._a_feature_flag_with(filters={"new": "content"},),
     )
     expected = [
         Change(
             type="FeatureFlag",
             field="filters",
             action="changed",
             before={"some": "value"},
             after={"new": "content"},
         )
     ]
     assert actual == expected
Esempio n. 7
0
    def perform_update(self, serializer):
        instance_id = serializer.instance.id

        try:
            before_update = FeatureFlag.objects.get(pk=instance_id)
        except FeatureFlag.DoesNotExist:
            before_update = None

        serializer.save()

        changes = changes_between("FeatureFlag",
                                  previous=before_update,
                                  current=serializer.instance)

        log_activity(
            organization_id=self.organization.id,
            team_id=self.team_id,
            user=serializer.context["request"].user,
            item_id=instance_id,
            scope="FeatureFlag",
            activity="updated",
            detail=Detail(changes=changes, name=serializer.instance.key),
        )
Esempio n. 8
0
 def test_comparing_two_nothings_results_in_no_changes(self):
     actual = changes_between(model_type="FeatureFlag", previous=None, current=None)
     assert actual == []