Development
This commit is contained in:
parent
563d82daf3
commit
70ccfe2c29
48 changed files with 549 additions and 578 deletions
|
|
@ -1,16 +1,14 @@
|
|||
from pathlib import Path
|
||||
from flask import Blueprint, request, redirect, flash, session
|
||||
from auth import require_level
|
||||
from config_utils import (flush_pending_to_queue, get_dashboard_pending,
|
||||
revert_group, revert_group_chain, queued_msg,
|
||||
DASHBOARD_PENDING, _db)
|
||||
import auth
|
||||
import config_utils
|
||||
|
||||
_PAGE = Path(__file__).parent.name
|
||||
|
||||
bp = Blueprint(_PAGE, __name__)
|
||||
|
||||
@bp.route('/action/actions/pending_save', methods=['POST'])
|
||||
@require_level('administrator')
|
||||
@auth.require_level('administrator')
|
||||
def pending_save():
|
||||
session['apply_changes_immediately'] = 'apply_changes_immediately' in request.form
|
||||
flash('Preference saved.', 'success')
|
||||
|
|
@ -18,20 +16,20 @@ def pending_save():
|
|||
|
||||
|
||||
@bp.route('/action/actions/pending_apply', methods=['POST'])
|
||||
@require_level('administrator')
|
||||
@auth.require_level('administrator')
|
||||
def pending_apply():
|
||||
pending = get_dashboard_pending()
|
||||
pending = config_utils.get_dashboard_pending()
|
||||
if not pending:
|
||||
flash('No pending changes to apply.', 'info')
|
||||
return redirect(f'/{_PAGE}')
|
||||
flush_pending_to_queue()
|
||||
config_utils.flush_pending_to_queue()
|
||||
if any(cmd != 'fix problems' for _, _, cmd, _ in pending):
|
||||
flash('Changes queued.', 'success')
|
||||
return redirect(f'/{_PAGE}')
|
||||
|
||||
|
||||
@bp.route('/action/actions/history_revert', methods=['POST'])
|
||||
@require_level('administrator')
|
||||
@auth.require_level('administrator')
|
||||
def history_revert():
|
||||
selected_uuids = request.form.getlist('selected_uuids')
|
||||
if not selected_uuids:
|
||||
|
|
@ -42,7 +40,7 @@ def history_revert():
|
|||
return redirect(f'/{_PAGE}')
|
||||
|
||||
behavior = request.form.get('revert_behavior', 'revert_subsequent')
|
||||
errors, succeeded, failed = revert_group_chain(selected_uuids[0])
|
||||
errors, succeeded, failed = config_utils.revert_group_chain(selected_uuids[0])
|
||||
|
||||
for msg in errors:
|
||||
flash(msg, 'error')
|
||||
|
|
@ -56,14 +54,14 @@ def history_revert():
|
|||
|
||||
|
||||
@bp.route('/action/actions/history_clear', methods=['POST'])
|
||||
@require_level('manager')
|
||||
@auth.require_level('manager')
|
||||
def history_clear():
|
||||
selected_uuids = request.form.getlist('selected_uuids')
|
||||
if not selected_uuids:
|
||||
flash('No items selected.', 'info')
|
||||
return redirect(f'/{_PAGE}')
|
||||
count = 0
|
||||
conn = _db()
|
||||
conn = config_utils._db()
|
||||
try:
|
||||
for uid in selected_uuids:
|
||||
conn.execute('DELETE FROM changes WHERE group_id=?', (uid,))
|
||||
|
|
@ -78,15 +76,15 @@ def history_clear():
|
|||
|
||||
|
||||
@bp.route('/action/actions/pending_dismiss', methods=['POST'])
|
||||
@require_level('manager')
|
||||
@auth.require_level('manager')
|
||||
def pending_dismiss():
|
||||
pending = get_dashboard_pending()
|
||||
pending = config_utils.get_dashboard_pending()
|
||||
dismissible = [(u, t, c, usr) for u, t, c, usr in pending if c != 'fix problems']
|
||||
if not dismissible:
|
||||
flash('No pending changes to dismiss.', 'info')
|
||||
return redirect(f'/{_PAGE}')
|
||||
keep = [(u, t, c, usr) for u, t, c, usr in pending if c == 'fix problems']
|
||||
with open(DASHBOARD_PENDING, 'w') as f:
|
||||
with open(config_utils.DASHBOARD_PENDING, 'w') as f:
|
||||
for u, t, c, usr in keep:
|
||||
f.write(f'{u} {t} [{c}] ({usr})\n')
|
||||
flash('Pending changes dismissed.', 'success')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue