Skip to content

Commit

Permalink
simplify/remove god_required decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
ericoc committed Nov 27, 2022
1 parent e01f1e7 commit 2a3b828
Showing 1 changed file with 11 additions and 31 deletions.
42 changes: 11 additions & 31 deletions admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Admin"""
import os
from datetime import datetime
from functools import wraps
from flask import abort, Blueprint, flash, render_template, url_for
from flask_login import current_user, fresh_login_required
from mud_secret import PODIR, IMM_LEVELS
Expand All @@ -11,31 +10,26 @@
from sentry import sentry_sdk


def god_required(func):
"""Decorator to allow access only to Gods"""
@wraps(func)
def decorated_function(*args, **kwargs):
if not current_user.is_god:
flash('Sorry, but you are not godly enough!', 'error')
abort(401)
return func(*args, **kwargs)
return decorated_function
admin = Blueprint('admin', __name__, url_prefix='/admin')


admin = Blueprint('admin', __name__, url_prefix='/admin')
@admin.before_request
@fresh_login_required
def before_request():
"""Only Gods can access /admin"""
if not current_user.is_god:
flash('Sorry, but you are not godly enough!', 'error')
abort(401)


@admin.route('/', methods=['GET', 'POST'])
@fresh_login_required
@god_required
def index():
"""Administration portal main page for Gods"""
return render_template('admin/portal.html.j2')


@admin.route('/news/', methods=['GET', 'POST'])
@admin.route('/news', methods=['GET', 'POST'])
@fresh_login_required
@god_required
def news():
"""Administration portal to allow Gods to post news
/admin/news"""
Expand Down Expand Up @@ -68,8 +62,6 @@ def news():

@admin.route('/news/edit/<int:edit_news_id>/', methods=['GET', 'POST'])
@admin.route('/news/edit/<int:edit_news_id>', methods=['GET', 'POST'])
@fresh_login_required
@god_required
def edit_news(edit_news_id=None):
"""Administration portal to allow Gods to edit news posts
/admin/news/edit"""
Expand All @@ -96,8 +88,6 @@ def edit_news(edit_news_id=None):

@admin.route('/news/delete/<int:delete_news_id>/', methods=['GET'])
@admin.route('/news/delete/<int:delete_news_id>', methods=['GET'])
@fresh_login_required
@god_required
def delete_news(delete_news_id=None):
"""Administration portal to allow Gods to edit news posts
/admin/news/edit"""
Expand All @@ -119,9 +109,8 @@ def delete_news(delete_news_id=None):
)


@admin.route('/account/<int:manage_account_id>/', methods=['GET'])
@admin.route('/account/<int:manage_account_id>', methods=['GET'])
@fresh_login_required
@god_required
def manage_account(manage_account_id=None):
"""Administration portal to allow Gods to view accounts
/admin/account"""
Expand All @@ -136,8 +125,6 @@ def manage_account(manage_account_id=None):

@admin.route('/account/edit/<int:edit_account_id>/', methods=['GET', 'POST'])
@admin.route('/account/edit/<int:edit_account_id>', methods=['GET', 'POST'])
@fresh_login_required
@god_required
def edit_account(edit_account_id=None):
"""Administration portal to allow Gods to edit accounts
/admin/account/edit"""
Expand Down Expand Up @@ -174,9 +161,8 @@ def edit_account(edit_account_id=None):
)


@admin.route('/accounts/', methods=['GET'])
@admin.route('/accounts', methods=['GET'])
@fresh_login_required
@god_required
def accounts():
"""Administration portal to allow Gods to view accounts
/admin/accounts"""
Expand All @@ -185,8 +171,6 @@ def accounts():

@admin.route('/player/edit/<int:edit_player_id>/', methods=['GET', 'POST'])
@admin.route('/player/edit/<int:edit_player_id>', methods=['GET', 'POST'])
@fresh_login_required
@god_required
def edit_player(edit_player_id=None):
"""Administration portal to allow Gods to edit player characters
/admin/player/edit"""
Expand Down Expand Up @@ -217,8 +201,6 @@ def edit_player(edit_player_id=None):

@admin.route('/season/', methods=['GET'])
@admin.route('/season', methods=['GET'])
@fresh_login_required
@god_required
def season():
"""Administration portal to allow Gods to view/manage seasons
/admin/season"""
Expand All @@ -229,8 +211,6 @@ def season():

@admin.route('/season/cycle/', methods=['GET', 'POST'])
@admin.route('/season/cycle', methods=['GET', 'POST'])
@fresh_login_required
@god_required
def season_cycle():
"""Administration portal to allow Gods to cycle seasons, while wiping players
/admin/season/cycle"""
Expand Down

0 comments on commit 2a3b828

Please sign in to comment.