~homeworkprod/byceps

e2eeb934cb6d8070d906bddc07f930a15e4e3ae2 — Jochen Kupperschmidt 8 months ago fe254e5
Replace current user flags `is_active`, `(not) is_anonymous` with `authenticated`
M byceps/blueprints/admin/authentication/login/views.py => byceps/blueprints/admin/authentication/login/views.py +2 -2
@@ 32,7 32,7 @@ blueprint = create_blueprint('authentication.login_admin', __name__)
@templated
def login_form():
    """Show login form."""
    if g.user.is_active:
    if g.user.authenticated:
        flash_notice(
            gettext(
                'You are already logged in as "%(screen_name)s".',


@@ 50,7 50,7 @@ def login_form():
@respond_no_content
def login():
    """Allow the user to authenticate with e-mail address and password."""
    if g.user.is_active:
    if g.user.authenticated:
        return

    form = LoginForm(request.form)

M byceps/blueprints/admin/core/templates/layout/admin/_current_user.html => byceps/blueprints/admin/core/templates/layout/admin/_current_user.html +1 -1
@@ 4,7 4,7 @@


<div class="current-user">
  {%- if g.user.is_active %}
  {%- if g.user.authenticated %}
  <div class="dropdown">
    <a href="{{ url_for('user_admin.view', user_id=g.user.id) }}" class="dropdown-toggle button button--clear">
      {{ render_user_avatar_32(g.user) }}

M byceps/blueprints/common/authentication/password/views.py => byceps/blueprints/common/authentication/password/views.py +1 -1
@@ 221,7 221,7 @@ def _is_verification_token_valid(token: Optional[VerificationToken]) -> bool:

def _get_current_user_or_404():
    user = g.user
    if not user.is_active:
    if not user.authenticated:
        abort(404)

    return user

M byceps/blueprints/common/core/templates/layout/_current_user.html => byceps/blueprints/common/core/templates/layout/_current_user.html +1 -1
@@ 4,7 4,7 @@


<div class="current-user">
  {%- if g.user.is_active %}
  {%- if g.user.authenticated %}
  <div class="dropdown">
    <a href="{{ url_for('user_settings.view') }}" class="dropdown-toggle">
      {{ render_user_avatar_32(g.user) }}

M byceps/blueprints/site/authentication/login/views.py => byceps/blueprints/site/authentication/login/views.py +2 -2
@@ 42,7 42,7 @@ blueprint = create_blueprint('authentication.login', __name__)
@templated
def login_form():
    """Show login form."""
    if g.user.is_active:
    if g.user.authenticated:
        flash_notice(
            gettext(
                'You are already logged in as "%(screen_name)s".',


@@ 71,7 71,7 @@ def login_form():
@respond_no_content
def login():
    """Allow the user to authenticate with e-mail address and password."""
    if g.user.is_active:
    if g.user.authenticated:
        return

    if not _is_site_login_enabled():

M byceps/blueprints/site/board/service.py => byceps/blueprints/site/board/service.py +2 -2
@@ 44,7 44,7 @@ def add_unseen_postings_flag_to_categories(

    for category in categories:
        contains_unseen_postings = (
            not user.is_anonymous
            user.authenticated
            and board_last_view_service.contains_category_unseen_postings(
                category, user.id
            )


@@ 75,7 75,7 @@ def add_topic_unseen_flag(topics: Sequence[DbTopic], user: CurrentUser) -> None:
    """Add `unseen` flag to topics."""
    for topic in topics:
        topic.contains_unseen_postings = (
            not user.is_anonymous
            user.authenticated
            and board_last_view_service.contains_topic_unseen_postings(
                topic, user.id
            )

M byceps/blueprints/site/board/templates/site/board/category_view.html => byceps/blueprints/site/board/templates/site/board/category_view.html +1 -1
@@ 66,7 66,7 @@
    <span class="button button--disabled">{{ render_icon('add') }} <span>Thema hinzufügen</span></span>
    {%- endif %}

    {%- if not g.user.is_anonymous %}
    {%- if g.user.authenticated %}
    <button class="button" data-action="mark-all-topics-in-category-as-viewed" href="{{ url_for('.mark_all_topics_in_category_as_viewed', category_id=category.id) }}" title="Alle Themen in dieser Kategorie als gelesen markieren">{{ render_icon('view') }}</button>
    {%- endif %}


M byceps/blueprints/site/board/views_category.py => byceps/blueprints/site/board/views_category.py +1 -1
@@ 64,7 64,7 @@ def category_view(slug, page):
    if category.hidden:
        abort(404)

    if not user.is_anonymous:
    if user.authenticated:
        board_last_view_service.mark_category_as_just_viewed(
            category.id, user.id
        )

M byceps/blueprints/site/board/views_posting.py => byceps/blueprints/site/board/views_posting.py +1 -1
@@ 111,7 111,7 @@ def posting_create(topic_id):
        topic.id, creator.id, body
    )

    if not g.user.is_anonymous:
    if g.user.authenticated:
        board_last_view_service.mark_category_as_just_viewed(
            topic.category.id, g.user.id
        )

M byceps/blueprints/site/board/views_topic.py => byceps/blueprints/site/board/views_topic.py +1 -1
@@ 96,7 96,7 @@ def topic_view(topic_id, page):
            url = h.build_url_for_posting_in_topic_view(posting, page)
            return redirect(url, code=307)

    if not user.is_anonymous:
    if user.authenticated:
        # Mark as viewed before aborting so a user can itself remove the
        # 'new' tag from a locked topic.
        board_last_view_service.mark_topic_as_just_viewed(topic.id, user.id)

M byceps/blueprints/site/seating/templates/site/seating/view_area.html => byceps/blueprints/site/seating/templates/site/seating/view_area.html +1 -1
@@ 28,7 28,7 @@

{%- if seat_management_enabled %}

  {%- if not g.user.is_anonymous %}
  {%- if g.user.authenticated %}
    {%- if manage_mode %}
{%- include 'site/seating/_ticket_selector.html' %}
    {%- else %}

M byceps/blueprints/site/seating/views.py => byceps/blueprints/site/seating/views.py +1 -1
@@ 294,7 294,7 @@ def release_seat(ticket_id):


def _is_seat_management_enabled():
    if g.user.is_anonymous:
    if not g.user.authenticated:
        return False

    if g.party_id is None:

M byceps/blueprints/site/shop/order/views.py => byceps/blueprints/site/shop/order/views.py +1 -2
@@ 60,8 60,7 @@ def order_form(erroneous_form=None):
        flash_error(gettext('No articles are available.'))
        return {'article_compilation': None}

    is_logged_in = g.user.is_active
    if not is_logged_in:
    if not g.user.authenticated:
        return list_articles(article_compilation)

    user = user_service.find_user_with_details(g.user.id)

M byceps/blueprints/site/ticketing/views.py => byceps/blueprints/site/ticketing/views.py +1 -1
@@ 384,7 384,7 @@ def _abort_if_ticket_management_disabled():


def _is_ticket_management_enabled():
    if g.user.is_anonymous:
    if not g.user.authenticated:
        return False

    if g.party_id is None:

M byceps/blueprints/site/user/avatar/views.py => byceps/blueprints/site/user/avatar/views.py +1 -1
@@ 110,7 110,7 @@ def delete():
def _get_current_user_or_404():
    user = g.user

    if not user.is_active:
    if not user.authenticated:
        abort(404)

    return user

M byceps/blueprints/site/user/current/views.py => byceps/blueprints/site/user/current/views.py +1 -1
@@ 20,7 20,7 @@ def view_as_json():
    """Show selected attributes of the current user's profile as JSON."""
    user = g.user

    if not user.is_active:
    if not user.authenticated:
        # Return empty response.
        return Response(status=403)


M byceps/blueprints/site/user_group/templates/site/user_group/index.html => byceps/blueprints/site/user_group/templates/site/user_group/index.html +1 -1
@@ 34,7 34,7 @@
    </tbody>
  </table>

  {%- if g.user.is_active %}
  {%- if g.user.authenticated %}
  <div class="button-row">
    <a class="button" href="{{ url_for('.create_form') }}">{{ render_icon('add') }} <span>Gruppe erstellen</span></a>
  </div>

M byceps/blueprints/site/user_group/views.py => byceps/blueprints/site/user_group/views.py +2 -2
@@ 36,7 36,7 @@ def index():
@templated
def create_form(erroneous_form=None):
    """Show a form to create a group."""
    if not g.user.is_active:
    if not g.user.authenticated:
        flash_error(gettext('You have to be logged in to create a user group.'))
        return redirect_to('.index')



@@ 50,7 50,7 @@ def create_form(erroneous_form=None):
@blueprint.route('/', methods=['POST'])
def create():
    """Create a group."""
    if not g.user.is_active:
    if not g.user.authenticated:
        flash_error(gettext('You have to be logged in to create a user group.'))
        return redirect_to('.index')


M byceps/services/authentication/session/models/current_user.py => byceps/services/authentication/session/models/current_user.py +1 -2
@@ 17,8 17,7 @@ from .....services.user.transfer.models import User
class CurrentUser(User):
    """The current user, anonymous or logged in."""

    is_active: bool
    is_anonymous: bool
    authenticated: bool
    permissions: Set[Enum]

    def has_permission(self, permission: Enum) -> bool:

M byceps/services/authentication/session/service.py => byceps/services/authentication/session/service.py +2 -4
@@ 156,8 156,7 @@ def get_anonymous_current_user() -> CurrentUser:
        deleted=False,
        avatar_url=None,
        is_orga=False,
        is_active=False,
        is_anonymous=True,
        authenticated=False,
        permissions=frozenset(),
    )



@@ 173,7 172,6 @@ def get_authenticated_current_user(
        deleted=False,  # Current user cannot be deleted.
        avatar_url=user.avatar_url,
        is_orga=user.is_orga,
        is_active=True,
        is_anonymous=False,
        authenticated=True,
        permissions=permissions,
    )

M byceps/services/board/models/posting.py => byceps/services/board/models/posting.py +1 -1
@@ 85,7 85,7 @@ class Posting(db.Model):

    def is_unseen(self, user: CurrentUser, last_viewed_at: datetime) -> bool:
        # Don't display any posting as new to a guest.
        if user.is_anonymous:
        if not user.authenticated:
            return False

        # Don't display the author's own posting as new to him/her.

M byceps/services/board/topic_query_service.py => byceps/services/board/topic_query_service.py +1 -1
@@ 121,7 121,7 @@ def find_default_posting_to_jump_to(
    topic_id: TopicID, user: CurrentUser, last_viewed_at: Optional[datetime]
) -> Optional[DbPosting]:
    """Return the posting of the topic to show by default, or `None`."""
    if user.is_anonymous:
    if not user.authenticated:
        # All postings are potentially new to a guest, so start on
        # the first page.
        return None

M byceps/util/views.py => byceps/util/views.py +1 -1
@@ 29,7 29,7 @@ def login_required(func):

    @wraps(func)
    def wrapper(*args, **kwargs):
        if not g.user.is_active:
        if not g.user.authenticated:
            flash_notice(gettext('Please log in.'))
            return redirect_to('authentication.login.login_form')
        return func(*args, **kwargs)

M tests/integration/services/authentication/test_current_user.py => tests/integration/services/authentication/test_current_user.py +2 -4
@@ 18,8 18,7 @@ def test_get_anonymous_current_user():
    assert not current_user.deleted
    assert current_user.avatar_url is None
    assert not current_user.is_orga
    assert not current_user.is_active
    assert current_user.is_anonymous
    assert not current_user.authenticated
    assert len(current_user.permissions) == 0




@@ 40,6 39,5 @@ def test_get_authenticated_current_user(user):
    assert not current_user.deleted
    assert current_user.avatar_url is None
    assert not current_user.is_orga
    assert current_user.is_active
    assert not current_user.is_anonymous
    assert current_user.authenticated
    assert current_user.permissions == permissions