diff --git a/proxstar/__init__.py b/proxstar/__init__.py index 0d5ae75..1682390 100644 --- a/proxstar/__init__.py +++ b/proxstar/__init__.py @@ -355,6 +355,37 @@ def delete_user(user): return '', 403 +@app.route("/settings") +@auth.oidc_auth +def settings(): + user = session['userinfo']['preferred_username'] + rtp = 'rtp' in session['userinfo']['groups'] + active = 'active' in session['userinfo']['groups'] + if rtp: + ignored_pools = get_ignored_pools(db) + return render_template( + 'settings.html', + username=user, + rtp=rtp, + active=active, + ignored_pools=ignored_pools) + else: + return '', 403 + + +@app.route("/pool//ignore", methods=['POST', 'DELETE']) +@auth.oidc_auth +def ignored_pools(pool): + if 'rtp' in session['userinfo']['groups']: + if request.method == 'POST': + add_ignored_pool(db, pool) + elif request.method == "DELETE": + delete_ignored_pool(db, pool) + return '', 200 + else: + return '', 403 + + @app.route('/vm//rrd/') @auth.oidc_auth def send_rrd(vmid, path): diff --git a/proxstar/db.py b/proxstar/db.py index 94244f8..f078621 100644 --- a/proxstar/db.py +++ b/proxstar/db.py @@ -131,3 +131,17 @@ def get_ignored_pools(db): for pool in db.query(Ignored_Pools).all(): ignored_pools.append(pool.id) return ignored_pools + + +def delete_ignored_pool(db, pool): + if db.query(exists().where(Ignored_Pools.id == pool)).scalar(): + ignored_pool = db.query(Ignored_Pools).filter(Ignored_Pools.id == pool).one() + db.delete(ignored_pool) + db.commit() + + +def add_ignored_pool(db, pool): + if not db.query(exists().where(Ignored_Pools.id == pool)).scalar(): + ignored_pool = Ignored_Pools(id=pool) + db.add(ignored_pool) + db.commit() diff --git a/proxstar/static/js/script.js b/proxstar/static/js/script.js index ad36155..2af6bcb 100644 --- a/proxstar/static/js/script.js +++ b/proxstar/static/js/script.js @@ -745,3 +745,21 @@ $(".delete-user").click(function(){ } }); }); + +$(".delete-ignored-pool").click(function(){ + const pool = $(this).data('pool') + fetch(`/pool/${pool}/ignore`, { + credentials: 'same-origin', + method: 'delete' + }); + location.reload(); +}); + +$(".add-ignored-pool").click(function(){ + const pool = document.getElementById('pool').value + fetch(`/pool/${pool}/ignore`, { + credentials: 'same-origin', + method: 'post' + }); + location.reload(); +}); diff --git a/proxstar/templates/base.html b/proxstar/templates/base.html index 90ff5da..b860279 100644 --- a/proxstar/templates/base.html +++ b/proxstar/templates/base.html @@ -40,6 +40,14 @@ Create VM + {% if rtp %} +
  • + + + Settings + +
  • + {% endif %} {% endif %}