示例#1
0
    def test_change_consent(self, mock_get_backends):
        good = MagicMock()
        mock_get_backends.return_value = [BadBackend(), good]

        analytics.change_consent(self.user, True)

        good.change_consent.assert_called_once_with(self.user, True)
示例#2
0
        def form_valid(self, form):
            if form.cleaned_data["consent"]:

                analytics.change_consent(self.request.user.email, True)

                for policy in Policy.get_policies_needing_consent(
                        self.request.user):
                    Consent.objects.create(policy=policy,
                                           user=self.request.user)
            else:

                # only revoke consent for currently active policies
                active_policies = Policy.objects.filter(
                    is_active=True,
                    requires_consent=True).values_list("id", flat=True)
                consents = Consent.objects.filter(
                    user=self.request.user,
                    policy__id__in=active_policies,
                    revoked_on=None)
                consents.update(revoked_on=timezone.now())
                # forget we were ever friends
                analytics.change_consent(self.request.user.email, False)

            redirect = self.request.POST.get("next")
            if not redirect:
                redirect = reverse("policies.policy_list")

            return HttpResponseRedirect(redirect)
示例#3
0
        def form_valid(self, form):
            if form.cleaned_data["consent"]:

                analytics.change_consent(self.request.user.email, True)

                for policy in Policy.get_policies_needing_consent(self.request.user):
                    Consent.objects.create(policy=policy, user=self.request.user)
            else:

                # only revoke consent for currently active policies
                active_policies = Policy.objects.filter(is_active=True, requires_consent=True).values_list(
                    "id", flat=True
                )
                consents = Consent.objects.filter(
                    user=self.request.user, policy__id__in=active_policies, revoked_on=None
                )
                consents.update(revoked_on=timezone.now())
                # forget we were ever friends
                analytics.change_consent(self.request.user.email, False)

            return HttpResponseRedirect(reverse("policies.policy_list"))
    def handle(self, *args, **options):
        count = 0
        consented = 0

        # now all users
        users = User.objects.all().order_by("id")
        total = users.count()
        for user in users:

            # update their policy consent
            if Policy.get_policies_needing_consent(user):
                analytics.change_consent(user, False)
            else:
                consented += 1
                analytics.change_consent(user, True)

            time.sleep(0.1)
            count += 1
            if count % 1000 == 0:
                print(f"Updated {count} of {total} users")

        print(f"Updated {count} users ({consented} consented).")
    def handle(self, *args, **options):
        analytics.init_analytics()
        count = 0
        consented = 0

        # now all users
        users = User.objects.all().order_by("id")
        total = users.count()
        for user in users:

            # update their policy consent
            if Policy.get_policies_needing_consent(user):
                analytics.change_consent(user.email, False)
            else:
                consented += 1
                analytics.change_consent(user.email, True)

            time.sleep(.1)
            count += 1
            if count % 1000 == 0:
                print(f"Updated {count} of {total} users")

        print(f"Updated {count} users ({consented} consented).")