Exemple #1
0
 def process_delete_phone_number(self):
     self.request.couch_user.delete_phone_number(self.phone_number)
     log_user_change(
         by_domain=None,
         for_domain=None,
         couch_user=self.request.couch_user,
         changed_by_user=self.request.couch_user,
         changed_via=USER_CHANGE_VIA_WEB,
         change_messages=UserChangeMessage.phone_numbers_removed(
             [self.phone_number]),
         by_domain_required_for_log=False,
         for_domain_required_for_log=False,
     )
     messages.success(self.request, _("Phone number deleted."))
     return HttpResponseRedirect(reverse(MyAccountSettingsView.urlname))
Exemple #2
0
    def test_process_delete_phone_number(self):
        phone_number = "9999999999"
        self.client.post(self.url, {
            "form_type": "delete-phone-number",
            "phone_number": phone_number
        })

        user_history_log = UserHistory.objects.get(
            user_id=self.couch_user.get_id)
        self.assertIsNone(user_history_log.message)
        self.assertEqual(
            user_history_log.change_messages,
            UserChangeMessage.phone_numbers_removed([phone_number]))
        self.assertEqual(user_history_log.changed_by, self.couch_user.get_id)
        self.assertIsNone(user_history_log.by_domain)
        self.assertIsNone(user_history_log.for_domain)
        self.assertEqual(user_history_log.changed_via, USER_CHANGE_VIA_WEB)
Exemple #3
0
    def test_delete_phone_number(self):
        phone_number = '99999999'
        self.client.post(
            reverse('delete_phone_number',
                    args=[self.domain, self.commcare_user.get_id]),
            {'phone_number': phone_number})

        user_history_log = UserHistory.objects.get(
            user_id=self.commcare_user.get_id)
        self.assertIsNone(user_history_log.message)
        self.assertEqual(
            user_history_log.change_messages,
            UserChangeMessage.phone_numbers_removed([phone_number]))
        self.assertEqual(user_history_log.changed_by, self.web_user.get_id)
        self.assertEqual(user_history_log.by_domain, self.domain)
        self.assertEqual(user_history_log.for_domain, self.domain)
        self.assertEqual(user_history_log.changed_via, USER_CHANGE_VIA_WEB)
Exemple #4
0
    def _log_phone_number_changes(self, old_phone_numbers, new_phone_numbers):
        (items_added,
         items_removed) = find_differences_in_list(target=new_phone_numbers,
                                                   source=old_phone_numbers)

        change_messages = {}
        if items_added:
            change_messages.update(
                UserChangeMessage.phone_numbers_added(
                    list(items_added))["phone_numbers"])

        if items_removed:
            change_messages.update(
                UserChangeMessage.phone_numbers_removed(
                    list(items_removed))["phone_numbers"])

        if change_messages:
            self.logger.add_change_message({'phone_numbers': change_messages})
Exemple #5
0
def _log_phone_number_change(new_phone_numbers, old_phone_numbers,
                             user_change_logger):
    numbers_added, numbers_removed = find_differences_in_list(
        target=list(new_phone_numbers), source=list(old_phone_numbers))

    change_messages = {}
    if numbers_removed:
        change_messages.update(
            UserChangeMessage.phone_numbers_removed(
                list(numbers_removed))["phone_numbers"])

    if numbers_added:
        change_messages.update(
            UserChangeMessage.phone_numbers_added(
                list(numbers_added))["phone_numbers"])

    if change_messages:
        user_change_logger.add_change_message(
            {'phone_numbers': change_messages})