Ejemplo n.º 1
0
def safe_hard_delete(case):
    """
    Hard delete a case - by deleting the case itself as well as all forms associated with it
    permanently from the database.

    Will fail hard if the case has any reverse indices or if any of the forms associated with
    the case also touch other cases.

    This is used primarily for cleaning up system cases/actions (e.g. the location delegate case).
    """
    if not settings.UNIT_TESTING:
        from corehq.apps.commtrack.const import USER_LOCATION_OWNER_MAP_TYPE
        if not (case.is_deleted or case.type == USER_LOCATION_OWNER_MAP_TYPE):
            raise CommCareCaseError("Attempt to hard delete a live case whose type isn't white listed")
Ejemplo n.º 2
0
def safe_hard_delete(case):
    """
    Hard delete a case - by deleting the case itself as well as all forms associated with it
    permanently from the database.

    Will fail hard if the case has any reverse indices or if any of the forms associated with
    the case also touch other cases.

    This is used primarily for cleaning up system cases/actions (e.g. the location delegate case).
    """
    if case.reverse_indices:
        raise CommCareCaseError(
            "You can't hard delete a case that has other dependencies ({})!".
            format(case._id))
    forms = get_case_forms(case._id)
    for form in forms:
        case_updates = get_case_updates(form)
        if any([c.id != case._id for c in case_updates]):
            raise CommCareCaseError(
                "You can't hard delete a case that has shared forms with other cases!"
            )
Ejemplo n.º 3
0
    This is used primarily for cleaning up system cases/actions (e.g. the location delegate case).
    """
    if not settings.UNIT_TESTING:
        from corehq.apps.commtrack.const import USER_LOCATION_OWNER_MAP_TYPE
        if not (case.is_deleted or case.type == USER_LOCATION_OWNER_MAP_TYPE):
            raise CommCareCaseError("Attempt to hard delete a live case whose type isn't white listed")

    if case.reverse_indices:
        raise CommCareCaseError("You can't hard delete a case that has other dependencies ({})!".format(case.case_id))
    interface = FormProcessorInterface(case.domain)
    forms = interface.get_case_forms(case.case_id)
    for form in forms:
        case_updates = get_case_updates(form)
        if any([c.id != case.case_id for c in case_updates]):
            raise CommCareCaseError("You can't hard delete a case that has shared forms with other cases!")

    interface.hard_delete_case_and_forms(case, forms)


def claim_case(domain, owner_id, host_id, host_type=None, host_name=None, device_id=None):
    """
    Claim a case identified by host_id for claimant identified by owner_id.

    Creates an extension case so that the claimed case is synced to the claimant's device.
    """
    claim_id = uuid4().hex
    if not (host_type and host_name):
        case = CaseAccessors(domain).get_case(host_id)
        host_type = case.type
        host_name = case.name