diff --git a/amanuensis/cli/lexicon.py b/amanuensis/cli/lexicon.py index d0e21ba..ba414dd 100644 --- a/amanuensis/cli/lexicon.py +++ b/amanuensis/cli/lexicon.py @@ -134,7 +134,7 @@ def command_player_add(args): from amanuensis.lexicon.manage import add_player # Verify arguments - if args.user.id in args.lexicon.join.joined: + if args.user.in_lexicon(args.lexicon): logger.error('"{0.username}" is already a player in "{1.name}"'.format( args.user, args.lexicon)) return -1 @@ -163,7 +163,7 @@ def command_player_remove(args): from amanuensis.lexicon.manage import remove_player # Verify arguments - if args.user.id not in args.lexicon.join.joined: + if not args.user.in_lexicon(args.lexicon): logger.error('"{0.username}" is not a player in lexicon "{1.name}"' ''.format(args.user, args.lexicon)) return -1 @@ -218,7 +218,7 @@ def command_char_create(args): from amanuensis.user import UserModel # Verify arguments - if args.user.id not in args.lexicon.join.joined: + if not args.user.in_lexicon(args.lexicon): logger.error('"{0.username}" is not a player in lexicon "{1.name}"' ''.format(args.user, args.lexicon)) return -1 diff --git a/amanuensis/lexicon/manage.py b/amanuensis/lexicon/manage.py index 1394a12..fa62d24 100644 --- a/amanuensis/lexicon/manage.py +++ b/amanuensis/lexicon/manage.py @@ -125,7 +125,7 @@ def get_user_lexicons(user): return [ lexicon for lexicon in get_all_lexicons() - if user.id in lexicon.join.joined] + if user.in_lexicon(lexicon)] def valid_add(lex, player, password=None): diff --git a/amanuensis/server/__init__.py b/amanuensis/server/__init__.py index f9f144d..1df4a2a 100644 --- a/amanuensis/server/__init__.py +++ b/amanuensis/server/__init__.py @@ -8,6 +8,7 @@ from amanuensis.server.auth import get_bp as get_auth_bp from amanuensis.server.home import get_bp as get_home_bp from amanuensis.server.helpers import register_custom_filters from amanuensis.server.lexicon import get_bp as get_lex_bp +from amanuensis.user import AnonymousUserModel # Flask app init static_root = os.path.abspath(get("static_root")) @@ -23,6 +24,7 @@ register_custom_filters(app) # Flask-Login init login = LoginManager(app) login.login_view = 'auth.login' +login.anonymous_user = AnonymousUserModel # Blueprint inits auth_bp = get_auth_bp(login) diff --git a/amanuensis/server/helpers.py b/amanuensis/server/helpers.py index e404a14..1772f11 100644 --- a/amanuensis/server/helpers.py +++ b/amanuensis/server/helpers.py @@ -59,7 +59,7 @@ def player_required(route): """ @wraps(route) def player_route(*args, **kwargs): - if current_user.id not in g.lexicon.join.joined: + if not current_user.in_lexicon(g.lexicon): flash("You must be a player to view this page") return (redirect(url_for('lexicon.contents', name=g.lexicon.name)) if g.lexicon.join.public @@ -76,7 +76,7 @@ def player_required_if_not_public(route): @wraps(route) def player_route(*args, **kwargs): if ((not g.lexicon.join.public) - and current_user.id not in g.lexicon.join.joined): + and not current_user.in_lexicon(g.lexicon)): flash("You must be a player to view this page") return redirect(url_for('home.home')) return route(*args, **kwargs) diff --git a/amanuensis/templates/home/admin.html b/amanuensis/templates/home/admin.html index c564161..dbf8eda 100644 --- a/amanuensis/templates/home/admin.html +++ b/amanuensis/templates/home/admin.html @@ -1,5 +1,5 @@ {% extends "page_2col.html" %} -{% import 'macros.html' as macros %} +{% import 'macros.html' as macros with context %} {% block title %}Admin | Amanuensis{% endblock %} {% block header %}
@@ -8,19 +8,28 @@ [{{ lexicon.status().capitalize() }}]
{{ lexicon.prompt }}
+ {% if current_user.is_authenticated %}- {% if anonymize %} - Players: {{ lexicon.join.joined|count }}/{{ lexicon.join.max_players }} - {% else %} - Editor: - {{ lexicon.editor|user_attr('username') }} / Players: - {% for uid in lexicon.join.joined[:-1] %} - {{ uid|user_attr('username') }}, + {% + if current_user.in_lexicon(lexicon) + or current_user.is_admin + %} + Editor: {{ lexicon.editor|user_attr('username') }} / + Players: + {% for uid in lexicon.join.joined %} + {{ uid|user_attr('username') }}{% if not loop.last %}, {% endif %} {% endfor %} - {{ lexicon.join.joined[-1]|user_attr('username') }} ({{ lexicon.join.joined|count }}/{{ lexicon.join.max_players }}) + {% else %} + Players: {{ lexicon.join.joined|count }}/{{ lexicon.join.max_players }} + {% if lexicon.join.public and lexicon.join.open %} + / + Join game + + {% endif %} {% endif %}
+ {% endif %}