def get_list(self, request=None, **kwargs): form = ApiSearchForm(request.GET if request else None) if not form.is_valid(): raise self.form_errors(form) # Pluck out status first since it forms part of the base query, but # only for privileged users. status = form.cleaned_data['status'] if status != amo.STATUS_PUBLIC and not ( acl.action_allowed(request, 'Apps', 'Review') or acl.action_allowed(request, 'Admin', '%')): return http.HttpUnauthorized( content=json.dumps( {'reason': 'Unauthorized to filter by status.'})) # Search specific processing of the results. region = getattr(request, 'REGION', mkt.regions.WORLDWIDE) qs = _get_query(region, gaia=request.GAIA, mobile=request.MOBILE, tablet=request.TABLET, status=status) qs = _filter_search(request, qs, form.cleaned_data, region=region) paginator = self._meta.paginator_class(request.GET, qs, resource_uri=self.get_resource_list_uri(), limit=self._meta.limit) page = paginator.page() # Rehydrate the results as per tastypie. objs = [self.build_bundle(obj=obj, request=request) for obj in page['objects']] page['objects'] = [self.full_dehydrate(bundle) for bundle in objs] # This isn't as quite a full as a full TastyPie meta object, # but at least it's namespaced that way and ready to expand. return self.create_response(request, page)
def get_query(self, request, base_filters=None): region = self.get_region(request) return _get_query(request, region, gaia=request.GAIA, mobile=request.MOBILE, tablet=request.TABLET, new_idx=True, filters=base_filters)
def get_query(self, request, base_filters=None): form_data = self.get_search_data(request) if base_filters is None: base_filters = {} base_filters['status'] = form_data.get('status') region = self.get_region(request) return _get_query(request, region, gaia=None, mobile=None, tablet=None, new_idx=True, filters=base_filters)
def get_list(self, request=None, **kwargs): form = ApiSearchForm(request.GET if request else None) if not form.is_valid(): raise self.form_errors(form) # Search specific processing of the results. qs = _get_query(request, form, form.cleaned_data) qs = _filter_search(qs, form.cleaned_data) res = amo.utils.paginate(request, qs) # Rehydrate the results as per tastypie. bundles = [self.build_bundle(obj=obj, request=request) for obj in res.object_list] objs = [self.full_dehydrate(bundle) for bundle in bundles] # This isn't as quite a full as a full TastyPie meta object, # but at least it's namespaced that way and ready to expand. return self.create_response(request, {"objects": objs, "meta": {}})
def get_list(self, request=None, **kwargs): form_data = self.search_form(request) is_admin = acl.action_allowed(request, 'Admin', '%') is_reviewer = acl.action_allowed(request, 'Apps', 'Review') # Pluck out status and addon type first since it forms part of the base # query, but only for privileged users. status = form_data['status'] addon_type = form_data['type'] base_filters = { 'type': addon_type, } if status and (status == 'any' or status != amo.STATUS_PUBLIC): if is_admin or is_reviewer: base_filters['status'] = status else: return http.HttpUnauthorized(content=json.dumps( {'reason': _('Unauthorized to filter by status.')})) # Search specific processing of the results. region = getattr(request, 'REGION', mkt.regions.WORLDWIDE) qs = _get_query(region, gaia=request.GAIA, mobile=request.MOBILE, tablet=request.TABLET, filters=base_filters) qs = _filter_search(request, qs, form_data, region=region) paginator = self._meta.paginator_class( request.GET, qs, resource_uri=self.get_resource_list_uri(), limit=self._meta.limit) page = paginator.page() # Rehydrate the results as per tastypie. objs = [ self.build_bundle(obj=obj, request=request) for obj in page['objects'] ] page['objects'] = [self.full_dehydrate(bundle) for bundle in objs] # This isn't as quite a full as a full TastyPie meta object, # but at least it's namespaced that way and ready to expand. to_be_serialized = self.alter_list_data_to_serialize(request, page) return self.create_response(request, to_be_serialized)
def get_list(self, request=None, **kwargs): form = ApiSearchForm(request.GET if request else None) if not form.is_valid(): raise self.form_errors(form) # Search specific processing of the results. region = getattr(request, 'REGION', mkt.regions.WORLDWIDE) qs = _get_query(region, gaia=request.GAIA, mobile=request.MOBILE, tablet=request.TABLET) qs = _filter_search(qs, form.cleaned_data, region=region) res = amo.utils.paginate(request, qs) # Rehydrate the results as per tastypie. bundles = [self.build_bundle(obj=obj, request=request) for obj in res.object_list] objs = [self.full_dehydrate(bundle) for bundle in bundles] # This isn't as quite a full as a full TastyPie meta object, # but at least it's namespaced that way and ready to expand. return self.create_response(request, {'objects': objs, 'meta': {}})
def get_list(self, request=None, **kwargs): form = ApiSearchForm(request.GET if request else None) if not form.is_valid(): raise self.form_errors(form) # Search specific processing of the results. qs = _get_query(request, form, form.cleaned_data) qs = _filter_search(qs, form.cleaned_data) res = amo.utils.paginate(request, qs) # Rehydrate the results as per tastypie. bundles = [ self.build_bundle(obj=obj, request=request) for obj in res.object_list ] objs = [self.full_dehydrate(bundle) for bundle in bundles] # This isn't as quite a full as a full TastyPie meta object, # but at least it's namespaced that way and ready to expand. return self.create_response(request, {'objects': objs, 'meta': {}})
def get_list(self, request=None, **kwargs): form_data = self.search_form(request) is_admin = acl.action_allowed(request, 'Admin', '%') is_reviewer = acl.action_allowed(request, 'Apps', 'Review') # Pluck out status and addon type first since it forms part of the base # query, but only for privileged users. status = form_data['status'] addon_type = form_data['type'] base_filters = { 'type': addon_type, } if status and (status == 'any' or status != amo.STATUS_PUBLIC): if is_admin or is_reviewer: base_filters['status'] = status else: return http.HttpUnauthorized( content=json.dumps( {'reason': _('Unauthorized to filter by status.')})) # Search specific processing of the results. region = getattr(request, 'REGION', mkt.regions.WORLDWIDE) qs = _get_query(region, gaia=request.GAIA, mobile=request.MOBILE, tablet=request.TABLET, filters=base_filters) qs = _filter_search(request, qs, form_data, region=region) paginator = self._meta.paginator_class(request.GET, qs, resource_uri=self.get_resource_list_uri(), limit=self._meta.limit) page = paginator.page() # Rehydrate the results as per tastypie. objs = [self.build_bundle(obj=obj, request=request) for obj in page['objects']] page['objects'] = [self.full_dehydrate(bundle) for bundle in objs] # This isn't as quite a full as a full TastyPie meta object, # but at least it's namespaced that way and ready to expand. to_be_serialized = self.alter_list_data_to_serialize(request, page) return self.create_response(request, to_be_serialized)
def get_list(self, request=None, **kwargs): form = ApiSearchForm(request.GET if request else None) if not form.is_valid(): raise self.form_errors(form) is_admin = acl.action_allowed(request, "Admin", "%") is_reviewer = acl.action_allowed(request, "Apps", "Review") # Pluck out status and addon type first since it forms part of the base # query, but only for privileged users. status = form.cleaned_data["status"] addon_type = form.cleaned_data["type"] base_filters = {"type": addon_type} if status and (status == "any" or status != amo.STATUS_PUBLIC): if is_admin or is_reviewer: base_filters["status"] = status else: return http.HttpUnauthorized(content=json.dumps({"reason": _("Unauthorized to filter by status.")})) # Search specific processing of the results. region = getattr(request, "REGION", mkt.regions.WORLDWIDE) qs = _get_query(region, gaia=request.GAIA, mobile=request.MOBILE, tablet=request.TABLET, filters=base_filters) qs = _filter_search(request, qs, form.cleaned_data, region=region) paginator = self._meta.paginator_class( request.GET, qs, resource_uri=self.get_resource_list_uri(), limit=self._meta.limit ) page = paginator.page() # Rehydrate the results as per tastypie. objs = [self.build_bundle(obj=obj, request=request) for obj in page["objects"]] page["objects"] = [self.full_dehydrate(bundle) for bundle in objs] # This isn't as quite a full as a full TastyPie meta object, # but at least it's namespaced that way and ready to expand. return self.create_response(request, page)
def get_list(self, request=None, **kwargs): form_data = self.search_form(request) is_admin = acl.action_allowed(request, 'Admin', '%') is_reviewer = acl.action_allowed(request, 'Apps', 'Review') uses_es = waffle.switch_is_active('search-api-es') # Pluck out status and addon type first since it forms part of the base # query, but only for privileged users. status = form_data['status'] addon_type = form_data['type'] base_filters = { 'type': addon_type, } # Allow reviewers and admins to search by statuses other than PUBLIC. if status and (status == 'any' or status != amo.STATUS_PUBLIC): if is_admin or is_reviewer: base_filters['status'] = status else: return http.HttpUnauthorized( content=json.dumps( {'reason': _('Unauthorized to filter by status.')})) # Filter by device feature profile. profile = None # TODO: Remove uses_es conditional with 'search-api-es' waffle. if uses_es and request.GET.get('dev') in ('firefoxos', 'android'): sig = request.GET.get('pro') if sig: profile = FeatureProfile.from_signature(sig) # Filter by region. region = getattr(request, 'REGION', mkt.regions.WORLDWIDE) qs = _get_query(region, gaia=request.GAIA, mobile=request.MOBILE, tablet=request.TABLET, filters=base_filters, new_idx=True) qs = _filter_search(request, qs, form_data, region=region, profile=profile) paginator = self._meta.paginator_class(request.GET, qs, resource_uri=self.get_resource_list_uri(), limit=self._meta.limit) page = paginator.page() # Rehydrate the results as per tastypie. objs = [] for obj in page['objects']: obj.pk = obj.id objs.append(self.build_bundle(obj=obj, request=request)) if uses_es: page['objects'] = [self.full_dehydrate(bundle) for bundle in objs] else: page['objects'] = [AppResource().full_dehydrate(bundle) for bundle in objs] # This isn't as quite a full as a full TastyPie meta object, # but at least it's namespaced that way and ready to expand. to_be_serialized = self.alter_list_data_to_serialize(request, page) return self.create_response(request, to_be_serialized)
def fake_get_query(*a, **kw): qs = _get_query(*a, **kw) m = Mock(wraps=qs) queries.append(m) return m
def get_list(self, request=None, **kwargs): form_data = self.search_form(request) is_admin = acl.action_allowed(request, 'Admin', '%') is_reviewer = acl.action_allowed(request, 'Apps', 'Review') uses_es = waffle.switch_is_active('search-api-es') # Pluck out status and addon type first since it forms part of the base # query, but only for privileged users. status = form_data['status'] addon_type = form_data['type'] base_filters = { 'type': addon_type, } # Allow reviewers and admins to search by statuses other than PUBLIC. if status and (status == 'any' or status != amo.STATUS_PUBLIC): if is_admin or is_reviewer: base_filters['status'] = status else: return http.HttpUnauthorized(content=json.dumps( {'reason': _('Unauthorized to filter by status.')})) # Filter by device feature profile. profile = None # TODO: Remove uses_es conditional with 'search-api-es' waffle. if uses_es and request.GET.get('dev') in ('firefoxos', 'android'): sig = request.GET.get('pro') if sig: profile = FeatureProfile.from_signature(sig) # Filter by region. region = getattr(request, 'REGION', mkt.regions.WORLDWIDE) qs = _get_query(region, gaia=request.GAIA, mobile=request.MOBILE, tablet=request.TABLET, filters=base_filters, new_idx=True) qs = _filter_search(request, qs, form_data, region=region, profile=profile) paginator = self._meta.paginator_class( request.GET, qs, resource_uri=self.get_resource_list_uri(), limit=self._meta.limit) page = paginator.page() # Rehydrate the results as per tastypie. objs = [] for obj in page['objects']: obj.pk = obj.id objs.append(self.build_bundle(obj=obj, request=request)) if uses_es: page['objects'] = [self.full_dehydrate(bundle) for bundle in objs] else: page['objects'] = [ AppResource().full_dehydrate(bundle) for bundle in objs ] # This isn't as quite a full as a full TastyPie meta object, # but at least it's namespaced that way and ready to expand. to_be_serialized = self.alter_list_data_to_serialize(request, page) return self.create_response(request, to_be_serialized)
def get_list(self, request=None, **kwargs): form_data = self.search_form(request) is_admin = acl.action_allowed(request, 'Admin', '%') is_reviewer = acl.action_allowed(request, 'Apps', 'Review') # Pluck out status and addon type first since it forms part of the base # query, but only for privileged users. status = form_data['status'] addon_type = form_data['type'] base_filters = { 'type': addon_type, } # Allow reviewers and admins to search by statuses other than PUBLIC. if status and (status == 'any' or status != amo.STATUS_PUBLIC): if is_admin or is_reviewer: base_filters['status'] = status else: raise http_error(http.HttpUnauthorized, _('Unauthorized to filter by status.')) # Only allow reviewers and admin to search by private fields or fields # depending on the latest_version (which may or may not be public yet). restricted_data = [form_data.get('is_privileged', None), form_data.get('has_editor_comment', None), form_data.get('has_info_request', None), form_data.get('is_escalated', None)] if not (is_admin or is_reviewer) and any(f is not None for f in restricted_data): return http.HttpUnauthorized(content=json.dumps( {'reason': _('Unauthorized to filter by private fields.')})) # Filter by device feature profile. profile = None if request.GET.get('dev') in ('firefoxos', 'android'): sig = request.GET.get('pro') if sig: profile = FeatureProfile.from_signature(sig) # Filter by region. region = getattr(request, 'REGION', mkt.regions.WORLDWIDE) qs = _get_query(request, region, gaia=request.GAIA, mobile=request.MOBILE, tablet=request.TABLET, filters=base_filters, new_idx=True) qs = _filter_search(request, qs, form_data, region=region, profile=profile) paginator = self._meta.paginator_class(request.GET, qs, resource_uri=self.get_resource_list_uri(), limit=self._meta.limit) page = paginator.page() # Rehydrate the results as per tastypie. objs = [] for obj in page['objects']: obj.pk = obj.id objs.append(self.build_bundle(obj=obj, request=request)) page['objects'] = [self.full_dehydrate(bundle) for bundle in objs] # This isn't as quite a full as a full TastyPie meta object, # but at least it's namespaced that way and ready to expand. to_be_serialized = self.alter_list_data_to_serialize(request, page) return self.create_response(request, to_be_serialized)