(by_domain, for_domain, couch_user, changed_by_user, changed_via=None,
                    change_messages=None, fields_changed=None, action=None,
                    by_domain_required_for_log=True, for_domain_required_for_log=True,
                    bulk_upload_record_id=None)
return UserHistory.objects.create(
        by_domain=by_domain,
        for_domain=for_domain,
        user_type=couch_user.doc_type,
        user_repr=couch_user.raw_username,
        changed_by_repr=changed_by_repr,
        user_id=couch_user.get_id,
        changed_by=changed_by_id,
        changes=_get_changed_details(couch_user, action, fields_changed),
        changed_via=changed_via,
        change_messages=change_messages,
        action=action.value,
        user_upload_record_id=bulk_upload_record_id,
    )
Log changes done to a user.
    For a new user or a deleted user, log only specific fields.

    :param by_domain: domain where the update was initiated
    :param for_domain: domain for which the update was initiated or the domain whose operations will get
        effected by this change.
        From user's perspective,
        A commcare user is completely owned by the domain
        A web user's membership that let's it perform operations on a domain is owned by the domain.
    :param couch_user: user being changed
    :param changed_by_user: user making the change or SYSTEM_USER_ID
    :param changed_via: changed via medium i.e API/Web
    :param change_messages: Optional dict of change messages
    :param fields_changed: dict of user fields that have changed with their current value
    :param action: action on the user
    :param by_domain_required_for_log: set to False to allow domain less log for specific changes
    :param for_domain_required_for_log: set to False to allow domain less log for specific changes
    :param bulk_upload_record_id: ID of bulk upload record if changed via bulk upload
Log changes done to a user.
    For a new user or a deleted user, log only specific fields.
Log changes done to a user . For a new user or a deleted user log only specific fields .
def log_user_change(by_domain, for_domain, couch_user, changed_by_user, changed_via=None,
                    change_messages=None, fields_changed=None, action=None,
                    by_domain_required_for_log=True, for_domain_required_for_log=True,
                    bulk_upload_record_id=None):
    """
    Log changes done to a user.
    For a new user or a deleted user, log only specific fields.

    :param by_domain: domain where the update was initiated
    :param for_domain: domain for which the update was initiated or the domain whose operations will get
        effected by this change.
        From user's perspective,
        A commcare user is completely owned by the domain
        A web user's membership that let's it perform operations on a domain is owned by the domain.
    :param couch_user: user being changed
    :param changed_by_user: user making the change or SYSTEM_USER_ID
    :param changed_via: changed via medium i.e API/Web
    :param change_messages: Optional dict of change messages
    :param fields_changed: dict of user fields that have changed with their current value
    :param action: action on the user
    :param by_domain_required_for_log: set to False to allow domain less log for specific changes
    :param for_domain_required_for_log: set to False to allow domain less log for specific changes
    :param bulk_upload_record_id: ID of bulk upload record if changed via bulk upload
    """
    from corehq.apps.users.models import UserHistory
    from corehq.apps.users.model_log import UserModelAction

    action = action or UserModelAction.UPDATE
    fields_changed = fields_changed or {}
    change_messages = change_messages or {}

    # domains are essential to filter changes done in and by a domain
    if by_domain_required_for_log and changed_by_user != SYSTEM_USER_ID and not by_domain:
        raise ValueError("missing 'by_domain' argument'")
    if for_domain_required_for_log and not for_domain:
        raise ValueError("missing 'for_domain' argument'")

    # for an update, there should always be fields that have changed or change messages
    if action == UserModelAction.UPDATE and not fields_changed and not change_messages:
        raise ValueError("missing both 'fields_changed' and 'change_messages' argument for update.")

    if changed_by_user == SYSTEM_USER_ID:
        changed_by_id = SYSTEM_USER_ID
        changed_by_repr = SYSTEM_USER_ID
    else:
        changed_by_id = changed_by_user.get_id
        changed_by_repr = changed_by_user.raw_username
    return UserHistory.objects.create(
        by_domain=by_domain,
        for_domain=for_domain,
        user_type=couch_user.doc_type,
        user_repr=couch_user.raw_username,
        changed_by_repr=changed_by_repr,
        user_id=couch_user.get_id,
        changed_by=changed_by_id,
        changes=_get_changed_details(couch_user, action, fields_changed),
        changed_via=changed_via,
        change_messages=change_messages,
        action=action.value,
        user_upload_record_id=bulk_upload_record_id,
    )
def log_user_change ( by_domain , for_domain , couch_user , changed_by_user , changed_via = None , change_messages = None , fields_changed = None , action = None , by_domain_required_for_log = True , for_domain_required_for_log = True , bulk_upload_record_id = None ) : from corehq . apps . users . models import UserHistory from corehq . apps . users . model_log import UserModelAction action = action or UserModelAction . UPDATE fields_changed = fields_changed or { } change_messages = change_messages or { } # domains are essential to filter changes done in and by a domain if by_domain_required_for_log and changed_by_user != SYSTEM_USER_ID and not by_domain : raise ValueError ( "missing 'by_domain' argument'" ) if for_domain_required_for_log and not for_domain : raise ValueError ( "missing 'for_domain' argument'" ) # for an update, there should always be fields that have changed or change messages if action == UserModelAction . UPDATE and not fields_changed and not change_messages : raise ValueError ( "missing both 'fields_changed' and 'change_messages' argument for update." ) if changed_by_user == SYSTEM_USER_ID : changed_by_id = SYSTEM_USER_ID changed_by_repr = SYSTEM_USER_ID else : changed_by_id = changed_by_user . get_id changed_by_repr = changed_by_user . raw_username return UserHistory . objects . create ( by_domain = by_domain , for_domain = for_domain , user_type = couch_user . doc_type , user_repr = couch_user . raw_username , changed_by_repr = changed_by_repr , user_id = couch_user . get_id , changed_by = changed_by_id , changes = _get_changed_details ( couch_user , action , fields_changed ) , changed_via = changed_via , change_messages = change_messages , action = action . value , user_upload_record_id = bulk_upload_record_id , )