def test_missing_fields(self): data = { 'date_range': 'range', 'start_date': '1992-01-30', } form = DashboardFeedFilterForm(DomainObject([], 'my-domain'), data=data) self.assertFalse(form.is_valid())
def test_good_data(self): data = { 'date_range': 'range', 'start_date': '1992-01-30', 'end_date': '2016-10-01', } form = DashboardFeedFilterForm(DomainObject([], 'my-domain'), data=data) self.assertTrue(form.is_valid())
def test_bad_dates(self): data = { 'date_range': 'range', 'start_date': '1992-01-30', 'end_date': 'banana', } form = DashboardFeedFilterForm(FakeDomainObject([], 'my-domain'), data=data) self.assertFalse(form.is_valid())
def commit_filters(request, domain): permissions = ExportsPermissionsManager(request.POST.get('model_type'), domain, request.couch_user) if not permissions.has_edit_permissions: raise Http404 export_id = request.POST.get('export_id') form_data = json.loads(request.POST.get('form_data')) export = get_properly_wrapped_export_instance(export_id) if export.is_daily_saved_export and not domain_has_privilege( domain, DAILY_SAVED_EXPORT): raise Http404 if export.export_format == "html" and not domain_has_privilege( domain, EXCEL_DASHBOARD): raise Http404 if export.is_odata_config and not domain_has_privilege(domain, ODATA_FEED): raise Http404 if not export.filters.is_location_safe_for_user(request): return location_restricted_response(request) domain_object = Domain.get_by_name(domain) filter_form = DashboardFeedFilterForm(domain_object, form_data, couch_user=request.couch_user) if filter_form.is_valid(): old_can_access_all_locations = export.filters.can_access_all_locations old_accessible_location_ids = export.filters.accessible_location_ids filters = filter_form.to_export_instance_filters( # using existing location restrictions prevents a less restricted user from modifying # restrictions on an export that a more restricted user created (which would mean the more # restricted user would lose access to the export) old_can_access_all_locations, old_accessible_location_ids, export.type) if export.filters != filters: export.filters = filters export.save() if export.is_daily_saved_export: rebuild_saved_export(export_id, manual=True) return json_response({ 'success': True, 'locationRestrictions': ExportListHelper.get_location_restriction_names( export.filters.accessible_location_ids), }) else: return json_response({ 'success': False, 'error': _("Problem saving dashboard feed filters: Invalid form"), })
def commit_filters(request, domain): permissions = ExportsPermissionsManager(request.POST.get('model_type'), domain, request.couch_user) if not permissions.has_edit_permissions: raise Http404 export_id = request.POST.get('export_id') form_data = json.loads(request.POST.get('form_data')) export = get_properly_wrapped_export_instance(export_id) if export.is_daily_saved_export and not domain_has_privilege(domain, DAILY_SAVED_EXPORT): raise Http404 if export.export_format == "html" and not domain_has_privilege(domain, EXCEL_DASHBOARD): raise Http404 if not export.filters.is_location_safe_for_user(request): return location_restricted_response(request) domain_object = Domain.get_by_name(domain) filter_form = DashboardFeedFilterForm(domain_object, form_data) if filter_form.is_valid(): old_can_access_all_locations = export.filters.can_access_all_locations old_accessible_location_ids = export.filters.accessible_location_ids filters = filter_form.to_export_instance_filters( # using existing location restrictions prevents a less restricted user from modifying # restrictions on an export that a more restricted user created (which would mean the more # restricted user would lose access to the export) old_can_access_all_locations, old_accessible_location_ids, export.type ) if export.filters != filters: export.filters = filters export.save() rebuild_saved_export(export_id, manual=True) return json_response({ 'success': True, }) else: return json_response({ 'success': False, 'error': _("Problem saving dashboard feed filters: Invalid form"), })