swath of changes to remove hidden "id" implementation in favor of hidden "role" RBAC implement

This commit is contained in:
Xevion
2019-12-23 21:48:11 -06:00
parent 99c702c306
commit c1aa3b2272
6 changed files with 24 additions and 37 deletions

View File

@@ -18,5 +18,3 @@ migrate = Migrate(app, db)
from app import models from app import models
from app import routes, simple_routes, hidden, dashboard from app import routes, simple_routes, hidden, dashboard
from app import ftbhot, custom, spotify, panzer, sound from app import ftbhot, custom, spotify, panzer, sound
app.jinja_env.globals.update(get_hidden=routes.get_hidden)

View File

@@ -8,11 +8,18 @@ import xmltodict
import base64 import base64
import json import json
# The only implementation I could get to work @app.route('/hidden/history')
def validate_id(id): @login_required
id = str(id).strip() @require_role(roles=['Hidden', 'Admin'])
val = str(app.config['HIDDEN_NUMBER']).strip() def hidden_history():
return id == val return render_template('hidden_history.html')
@app.route('/hidden/help')
@login_required
@require_role(roles=['Hidden'])
def hidden_help():
return render_template('hidden_help.html')
# Parses strings to test for "boolean-ness" # Parses strings to test for "boolean-ness"
def boolparse(string, default=False): def boolparse(string, default=False):
@@ -23,12 +30,10 @@ def boolparse(string, default=False):
return True return True
return False return False
@app.route('/hidden<id>/') @app.route('/hidden/')
@login_required @login_required
@require_role(roles=['Hidden']) @require_role(roles=['Hidden'])
def hidden(id): def hidden():
if not validate_id(id):
return '<span style="color: red;">error:</span> bad id'
# Handled within request # Handled within request
tags = request.args.get('tags') or 'trap' tags = request.args.get('tags') or 'trap'
try: try:
@@ -81,7 +86,7 @@ def build_data(tags, page, count, base64, showfull):
'index' : str(index + 1), 'index' : str(index + 1),
'real_url' : element['@file_url'], 'real_url' : element['@file_url'],
'sample_url' : element['@preview_url'], 'sample_url' : element['@preview_url'],
# strips tags, ensures no empty tags (may be unnescary) # strips tags, ensures no empty tags (may be unnecessary)
'tags' : list(filter(lambda tag : tag != '', [tag.strip() for tag in element['@tags'].split(' ')])), 'tags' : list(filter(lambda tag : tag != '', [tag.strip() for tag in element['@tags'].split(' ')])),
'view' : gelbooru_view_url.format(element['@id']) 'view' : gelbooru_view_url.format(element['@id'])
} }

View File

@@ -102,7 +102,6 @@ class Search(db.Model):
def __repr__(self): def __repr__(self):
return '<Search by {} @ {}>'.format(User.query.filter_by(id=self.user_id).first().username, self.timestamp) return '<Search by {} @ {}>'.format(User.query.filter_by(id=self.user_id).first().username, self.timestamp)
class Post(db.Model): class Post(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
body = db.Column(db.String(140)) body = db.Column(db.String(140))

View File

@@ -147,23 +147,3 @@ def login():
def logout(): def logout():
logout_user() logout_user()
return redirect(url_for('index')) return redirect(url_for('index'))
def get_hidden():
return "/hidden{}/".format(app.config['HIDDEN_NUMBER'])
@app.route('/hidden<id>/history')
@login_required
@require_role(roles=['Hidden', 'Admin'])
def hidden_history(id):
if not validate_id(id):
return '<span style="color: red;">error:</span> bad id'
return render_template('hidden_history.html')
@app.route('/hidden<id>/help')
@login_required
@require_role(roles=['Hidden'])
def hidden_help(id):
if not validate_id(id):
return '<span style="color: red;">error:</span> bad id'
return render_template('hidden_help.html')

View File

@@ -117,7 +117,7 @@ Color = Bulma Color Type of the Message Box
</a> </a>
<hr class="navbar-divider"> <hr class="navbar-divider">
{% if current_user.has_roles(['Hidden']) %} {% if current_user.has_roles(['Hidden']) %}
<a class="navbar-item" href="{{ get_hidden() }}"> <a class="navbar-item" href="{{ url_for('hidden') }}">
<span class="navbar-fa-icon fas fa-user-ninja"></span> <span class="navbar-fa-icon fas fa-user-ninja"></span>
Hidden Hidden
</a> </a>

View File

@@ -1,5 +1,10 @@
{% extends '/dashboard/dashboard_base.html' %} {% extends '/dashboard/dashboard_base.html' %}
{% set dashboard_home_active = True %} {% set dashboard_home_active = True %}
{% block dashboard_body %} {% block dashboard_body %}
<section></section> <section>
<h1>Roles</h1>
{% for role in current_user.get_roles() %}
<b>{{ role }}</b><br>
{% endfor %}
</section>
{% endblock dashboard_body %} {% endblock dashboard_body %}