def obj_get_list(self, bundle, domain, **kwargs): user_id = bundle.request.GET.get('user_id') request_params = bundle.request.GET status = api_closed_to_status(request_params.get('closed', 'false')) filters = get_filters_from_request_params(request_params, limit_top_level=self.fields) case_type = filters.get('properties/case_type', None) return map(dict_object, get_filtered_cases(domain, status=status, case_type=case_type, user_id=user_id, filters=filters))
def get_cases_vary_on(request, domain): request_params = request.GET return [ request.couch_user.get_id if request.couch_user.is_commcare_user() else request_params.get('user_id', ''), request_params.get('ids_only', 'false'), request_params.get('case_id', ''), request_params.get('footprint', 'false'), request_params.get('closed', 'false'), json.dumps(get_filters_from_request_params(request_params)), domain, ]
def get_cases(request, domain): request_params = request.GET if request.couch_user.is_commcare_user(): user_id = request.couch_user.get_id else: user_id = request_params.get("user_id", "") if not user_id and not request.couch_user.is_web_user(): return HttpResponseBadRequest("Must specify user_id!") ids_only = string_to_boolean(request_params.get("ids_only", "false")) case_id = request_params.get("case_id", "") footprint = string_to_boolean(request_params.get("footprint", "false")) accessor = CaseAccessors(domain) if toggles.HSPH_HACK.enabled(domain): hsph_case_id = request_params.get('hsph_hack', None) if hsph_case_id != 'None' and hsph_case_id and user_id: case = accessor.get_case(hsph_case_id) usercase_id = CommCareUser.get_by_user_id(user_id).get_usercase_id() usercase = accessor.get_case(usercase_id) if usercase_id else None return json_response(map( lambda case: CaseAPIResult(domain=domain, id=case['_id'], couch_doc=case, id_only=ids_only), filter(None, [case, case.parent, usercase]) )) if case_id and not footprint: # short circuit everything else and just return the case # NOTE: this allows any user in the domain to access any case given # they know its ID, which is slightly different from the previous # behavior (can only access things you own + footprint). If we want to # change this contract we would need to update this to check the # owned case list + footprint case = accessor.get_case(case_id) assert case.domain == domain cases = [CaseAPIResult(domain=domain, id=case_id, couch_doc=case, id_only=ids_only)] else: filters = get_filters_from_request_params(request_params) status = api_closed_to_status(request_params.get('closed', 'false')) case_type = filters.get('properties/case_type', None) cases = get_filtered_cases(domain, status=status, case_type=case_type, user_id=user_id, filters=filters, footprint=footprint, ids_only=ids_only, strip_history=True) return json_response(cases)
lambda case: CaseAPIResult( id=case['_id'], couch_doc=case, id_only=ids_only), filter(None, [case, case.parent, usercase]))) if case_id and not footprint: # short circuit everything else and just return the case # NOTE: this allows any user in the domain to access any case given # they know its ID, which is slightly different from the previous # behavior (can only access things you own + footprint). If we want to # change this contract we would need to update this to check the # owned case list + footprint case = accessor.get_case(case_id) assert case.domain == domain cases = [CaseAPIResult(id=case_id, couch_doc=case, id_only=ids_only)] else: filters = get_filters_from_request_params(request_params) status = api_closed_to_status(request_params.get('closed', 'false')) case_type = filters.get('properties/case_type', None) cases = get_filtered_cases(domain, status=status, case_type=case_type, user_id=user_id, filters=filters, footprint=footprint, ids_only=ids_only, strip_history=True) return json_response(cases) @cloudcare_api def filter_cases(request, domain, app_id, module_id, parent_id=None):