|
@@ 394-416 (lines=23) @@
|
| 391 |
|
date=dt.now(), |
| 392 |
|
id=new_id, |
| 393 |
|
) |
| 394 |
|
d.update(**metadata()) |
| 395 |
|
# Possibly override global user, if configured and valid. |
| 396 |
|
d.update(**check_global()) |
| 397 |
|
# Add to DB |
| 398 |
|
adapter.create(data=d) |
| 399 |
|
flash('Created new dashboard "{}"'.format(data['name'])) |
| 400 |
|
return redirect(url_for('jsondash.view', c_id=new_id)) |
| 401 |
|
|
| 402 |
|
|
| 403 |
|
@charts.route('/charts/<c_id>/clone', methods=['POST']) |
| 404 |
|
def clone(c_id): |
| 405 |
|
"""Clone a json view config from the DB.""" |
| 406 |
|
if not auth(authtype='clone'): |
| 407 |
|
flash('You do not have access to clone dashboards.', 'error') |
| 408 |
|
return redirect(url_for('jsondash.dashboard')) |
| 409 |
|
viewjson = adapter.read(c_id=c_id) |
| 410 |
|
if not viewjson: |
| 411 |
|
flash('Could not find view: {}'.format(c_id), 'error') |
| 412 |
|
return redirect(url_for('jsondash.dashboard')) |
| 413 |
|
# Update some fields. |
| 414 |
|
newname = 'Clone of {}'.format(viewjson['name']) |
| 415 |
|
data = dict( |
| 416 |
|
name=newname, |
| 417 |
|
modules=viewjson['modules'], |
| 418 |
|
date=str(dt.now()), |
| 419 |
|
id=str(uuid.uuid1()), |
|
@@ 371-391 (lines=21) @@
|
| 368 |
|
"""Allow overriding of the user by making it global. |
| 369 |
|
This also checks if the setting is enabled for the app, |
| 370 |
|
otherwise it will not allow it. |
| 371 |
|
""" |
| 372 |
|
global_enabled = setting('JSONDASH_GLOBALDASH') |
| 373 |
|
global_flag = request.form.get('is_global', '') == 'on' |
| 374 |
|
can_make_global = auth(authtype='edit_global') |
| 375 |
|
if all([global_flag, global_enabled, can_make_global]): |
| 376 |
|
return dict(created_by=setting('JSONDASH_GLOBAL_USER')) |
| 377 |
|
return dict() |
| 378 |
|
|
| 379 |
|
|
| 380 |
|
@charts.route('/charts/create', methods=['POST']) |
| 381 |
|
def create(): |
| 382 |
|
"""Normalize the form POST and setup the json view config object.""" |
| 383 |
|
if not auth(authtype='create'): |
| 384 |
|
flash('You do not have access to create dashboards.', 'error') |
| 385 |
|
return redirect(url_for('jsondash.dashboard')) |
| 386 |
|
data = request.form |
| 387 |
|
new_id = str(uuid.uuid1()) |
| 388 |
|
d = dict( |
| 389 |
|
name=data['name'], |
| 390 |
|
modules=adapter._format_modules(data), |
| 391 |
|
date=dt.now(), |
| 392 |
|
id=new_id, |
| 393 |
|
) |
| 394 |
|
d.update(**metadata()) |