dashboard: fix views when dashboard cell does not exist (#63233)
This commit is contained in:
parent
0be1356882
commit
db8c99228d
|
@ -55,7 +55,9 @@ class DashboardAddTileView(View):
|
|||
if not request.user.is_authenticated:
|
||||
raise PermissionDenied()
|
||||
|
||||
dashboard = DashboardCell.objects.filter(page__snapshot__isnull=True)[0]
|
||||
dashboard = DashboardCell.objects.filter(page__snapshot__isnull=True).first()
|
||||
if dashboard is None:
|
||||
raise Http404()
|
||||
cell = CellBase.get_cell(kwargs['cell_reference'])
|
||||
if not cell.page.is_visible(request.user):
|
||||
raise PermissionDenied()
|
||||
|
@ -128,7 +130,9 @@ def dashboard_auto_tile(request, *args, **kwargs):
|
|||
except json.JSONDecodeError:
|
||||
return HttpResponseBadRequest('bad json request: "%s"' % request.body)
|
||||
|
||||
dashboard = DashboardCell.objects.filter(page__snapshot__isnull=True)[0]
|
||||
dashboard = DashboardCell.objects.filter(page__snapshot__isnull=True).first()
|
||||
if dashboard is None:
|
||||
raise Http404()
|
||||
cell = ConfigJsonCell(key=kwargs.get('key'), order=1, page_id=dashboard.page_id, placeholder='_auto_tile')
|
||||
|
||||
if cell.key not in settings.JSON_CELL_TYPES:
|
||||
|
|
|
@ -269,7 +269,7 @@ LINGO_NO_ONLINE_PAYMENT_REASONS = {}
|
|||
JSON_CELL_TYPES = {}
|
||||
|
||||
# dashboard support
|
||||
COMBO_DASHBOARD_ENABLED = False
|
||||
COMBO_DASHBOARD_ENABLED = True
|
||||
|
||||
COMBO_DASHBOARD_NEW_TILE_POSITION = 'last'
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ def test_empty_dashboard(app, site):
|
|||
resp = app.get('/', status=200)
|
||||
assert 'hello world' in resp.text
|
||||
resp = app.get('/two/', status=200)
|
||||
assert not 'dashboardcell' in resp.text
|
||||
assert 'dashboardcell' not in resp.text
|
||||
app = login(app)
|
||||
resp = app.get('/two/', status=200)
|
||||
assert 'dashboardcell' in resp.text
|
||||
|
@ -58,13 +58,21 @@ def test_add_to_dashboard(app, site):
|
|||
assert Tile.objects.all()[0].user_id == user.id
|
||||
assert Tile.objects.all()[0].order == 0
|
||||
|
||||
app = login(app)
|
||||
resp = app.get('/two/', status=200)
|
||||
assert 'hello world' in resp.text
|
||||
|
||||
# missing dashboard cell
|
||||
dashboard.delete()
|
||||
app.get(reverse('combo-dashboard-add-tile', kwargs={'cell_reference': cell.get_reference()}), status=404)
|
||||
|
||||
|
||||
def test_add_to_dashboard_order(app, site):
|
||||
test_add_to_dashboard(app, site)
|
||||
app = login(app)
|
||||
|
||||
cell = TextCell.objects.get(order=100)
|
||||
app.get(reverse('combo-dashboard-add-tile', kwargs={'cell_reference': cell.get_reference()}))
|
||||
assert Tile.objects.count() == 1
|
||||
|
||||
cell = TextCell.objects.get(order=101)
|
||||
app.get(reverse('combo-dashboard-add-tile', kwargs={'cell_reference': cell.get_reference()}))
|
||||
assert Tile.objects.count() == 2
|
||||
|
@ -117,7 +125,11 @@ def test_ajax_add_to_dashboard(app, site):
|
|||
|
||||
|
||||
def test_ajax_render(app, site):
|
||||
test_add_to_dashboard(app, site)
|
||||
app = login(app)
|
||||
cell = TextCell.objects.get(order=100)
|
||||
app.get(reverse('combo-dashboard-add-tile', kwargs={'cell_reference': cell.get_reference()}))
|
||||
assert Tile.objects.count() == 1
|
||||
|
||||
app.reset() # logout
|
||||
tile = Tile.objects.all()[0]
|
||||
page = Page.objects.get(slug='two')
|
||||
|
@ -150,7 +162,11 @@ def test_ajax_render(app, site):
|
|||
|
||||
|
||||
def test_remove_from_dashboard(app, site):
|
||||
test_add_to_dashboard(app, site)
|
||||
app = login(app)
|
||||
cell = TextCell.objects.get(order=100)
|
||||
app.get(reverse('combo-dashboard-add-tile', kwargs={'cell_reference': cell.get_reference()}))
|
||||
assert Tile.objects.count() == 1
|
||||
|
||||
app.reset() # logout
|
||||
tile = Tile.objects.all()[0]
|
||||
app.get(
|
||||
|
@ -168,10 +184,12 @@ def test_remove_from_dashboard(app, site):
|
|||
|
||||
|
||||
def test_ajax_remove_from_dashboard(app, site):
|
||||
test_add_to_dashboard(app, site)
|
||||
tile = Tile.objects.all()[0]
|
||||
|
||||
app = login(app)
|
||||
cell = TextCell.objects.get(order=100)
|
||||
app.get(reverse('combo-dashboard-add-tile', kwargs={'cell_reference': cell.get_reference()}))
|
||||
assert Tile.objects.count() == 1
|
||||
|
||||
tile = Tile.objects.all()[0]
|
||||
resp = app.get(
|
||||
reverse('combo-dashboard-remove-tile', kwargs={'cell_reference': tile.cell.get_reference()}),
|
||||
headers={'x-requested-with': 'XMLHttpRequest'},
|
||||
|
@ -280,6 +298,15 @@ def test_auto_tile(app, site):
|
|||
status=400,
|
||||
)
|
||||
|
||||
# missing dashboard cell
|
||||
DashboardCell.objects.all().delete()
|
||||
app.post(
|
||||
reverse('combo-dashboard-auto-tile', kwargs={'key': 'test-config-json-cell'}),
|
||||
params=json.dumps({'var1': 'one', 'var2': 'two'}),
|
||||
content_type='application/json',
|
||||
status=404,
|
||||
)
|
||||
|
||||
|
||||
def test_clean_autotiles(app, site):
|
||||
appconfig = apps.get_app_config('dashboard')
|
||||
|
|
Loading…
Reference in New Issue