~homeworkprod/byceps

1fa7c946d2d676f35a37bbbc4ef1daa0c643506b — Jochen Kupperschmidt 10 months ago b3c1dd7
Move admin UI to view email configurations to brand settings
M byceps/blueprints/admin/brand/templates/admin/brand/view.html => byceps/blueprints/admin/brand/templates/admin/brand/view.html +31 -0
@@ 49,4 49,35 @@
  <div class="dimmed-box centered">Für diese Marke sind keine Einstellungen hinterlegt.</div>
  {%- endif %}

  <div class="row row--space-between">
    <div class="column-auto">
      <h2>E-Mail-Konfiguration</h2>
    </div>
    {%- if email_config and g.current_user.has_permission(EmailConfigPermission.update) %}
    <div class="column-auto">
      <div class="button-row button-row--right" style="margin-top: 2rem;">
        <a class="button button--compact" href="{{ url_for('email_admin.update_form', config_id=email_config.id) }}">{{ render_icon('edit') }} <span>Bearbeiten</span></a>
      </div>
    </div>
    {%- endif %}
  </div>
  {%- if email_config %}
  <table class="index">
    <tr>
      <th>Absender-Adresse</th>
      <td>{{ email_config.sender.address }}</td>
    </tr>
    <tr>
      <th>Absender-Name</th>
      <td>{{ email_config.sender.name|fallback }}</td>
    </tr>
    <tr>
      <th>Kontaktadresse</th>
      <td>{{ email_config.contact_address|fallback }}</td>
    </tr>
  </table>
  {%- else %}
  <div class="dimmed-box centered">Keine</div>
  {%- endif %}

{%- endblock %}

M byceps/blueprints/admin/brand/views.py => byceps/blueprints/admin/brand/views.py +4 -0
@@ 12,6 12,7 @@ from ....services.brand import (
    service as brand_service,
    settings_service as brand_settings_service,
)
from ....services.email import service as email_service
from ....services.orga import service as orga_service
from ....services.party import service as party_service
from ....util.framework.blueprint import create_blueprint


@@ 56,11 57,14 @@ def index():
def view(brand_id):
    """Show a brand."""
    brand = _get_brand_or_404(brand_id)

    settings = brand_settings_service.get_settings(brand.id)
    email_config = email_service.find_config_for_brand(brand.id)

    return {
        'brand': brand,
        'settings': settings,
        'email_config': email_config,
    }



M byceps/blueprints/admin/core/templates/layout/admin/_navigation_global.html => byceps/blueprints/admin/core/templates/layout/admin/_navigation_global.html +0 -6
@@ 46,12 46,6 @@
        required_permission=SnippetPermission.view,
        icon='snippet')
      .add_item(
        url_for('email_admin.index'),
        'E-Mail',
        id='email_admin',
        required_permission=EmailConfigPermission.view,
        icon='email')
      .add_item(
        url_for('brand_admin.index'),
        'Marken',
        id='brands_admin',

M byceps/blueprints/admin/email/authorization.py => byceps/blueprints/admin/email/authorization.py +0 -1
@@ 11,5 11,4 @@ from byceps.util.authorization import create_permission_enum

EmailConfigPermission = create_permission_enum('email_config', [
    'update',
    'view',
])

D byceps/blueprints/admin/email/templates/admin/email/index.html => byceps/blueprints/admin/email/templates/admin/email/index.html +0 -55
@@ 1,55 0,0 @@
{% extends 'layout/admin/base.html' %}
{% from 'macros/admin.html' import render_extra_in_heading %}
{% from 'macros/icons.html' import render_icon %}
{% set current_page = 'email_admin' %}
{% set title = 'E-Mail-Konfigurationen' %}

{% block body %}

  <h1>{{ title }} {{ render_extra_in_heading(configs|length) }}</h1>

  {%- if configs %}
  <table class="index wide">
    <thead>
      <tr>
        <th>ID</th>
        <th colspan="2">Absender</th>
        <th>Kontaktadresse</th>
        <th></th>
      </tr>
      <tr>
        <th></th>
        <th>Adresse</th>
        <th>Name</th>
        <th></th>
        <th></th>
      </tr>
    </thead>
    <tbody>
    {%- for config in configs|sort(attribute='id') %}
      <tr>
        <td class="monospace">{{ config.id }}</td>
        <td>{{ config.sender.address }}</td>
        <td>{{ config.sender.name|fallback }}</td>
        <td>{{ config.contact_address|fallback }}</td>
        <td>
          {%- if g.current_user.has_any_permission(EmailConfigPermission.update, EmailConfigPermission.delete) %}
          <div class="dropdown">
            <button class="dropdown-toggle button button--compact"><span>{{ render_icon('chevron-down') }}</span></button>
            <ol class="dropdown-menu dropdown-menu--right">
            {%- if g.current_user.has_permission(EmailConfigPermission.update) %}
              <li><a class="dropdown-item" href="{{ url_for('.update_form', config_id=config.id) }}">{{ render_icon('edit') }} Bearbeiten</a></li>
            {%- endif %}
            </ol>
          </div>
          {%- endif %}
        </td>
      </tr>
    {%- endfor %}
    </tbody>
  </table>
  {%- else %}
  <div class="dimmed-box centered">Es sind keine E-Mail-Konfigurationen hinterlegt.</div>
  {%- endif %}

{%- endblock %}

M byceps/blueprints/admin/email/templates/admin/email/update_form.html => byceps/blueprints/admin/email/templates/admin/email/update_form.html +2 -2
@@ 9,7 9,7 @@

  <nav class="breadcrumbs">
    <ol>
      <li><a href="{{ url_for('.index') }}">Konfigurationen</a></li>
      <li><a href="{{ url_for('brand_admin.view', brand_id=config.brand_id) }}">Konfigurationen</a></li>
    </ol>
  </nav>
  <h1>{{ render_icon('edit') }} {{ title }}</h1>


@@ 22,7 22,7 @@
      {{ form_field(form.contact_address) }}
    {% endcall %}

    {{ form_buttons('Speichern', cancel_url=url_for('.index')) }}
    {{ form_buttons('Speichern', cancel_url=url_for('brand_admin.view', brand_id=config.brand_id)) }}
  </form>

{%- endblock %}

M byceps/blueprints/admin/email/views.py => byceps/blueprints/admin/email/views.py +2 -14
@@ 27,18 27,6 @@ blueprint = create_blueprint('email_admin', __name__)
permission_registry.register_enum(EmailConfigPermission)


@blueprint.route('/configs')
@permission_required(EmailConfigPermission.view)
@templated
def index():
    """List all e-mail configs."""
    configs = email_service.get_all_configs()

    return {
        'configs': configs,
    }


@blueprint.route('/configs/<config_id>/update')
@permission_required(EmailConfigPermission.update)
@templated


@@ 81,8 69,8 @@ def update(config_id):
        config.id, sender_address, sender_name, contact_address
    )

    flash_success(f'Die Konfiguration "{config.id}" wurde aktualisiert.')
    return redirect_to('.index')
    flash_success(f'Die E-Mail-Konfiguration wurde aktualisiert.')
    return redirect_to('brand_admin.view', brand_id=config.brand_id)


def _get_config_or_404(config_id):

M scripts/data/permissions_and_roles.toml => scripts/data/permissions_and_roles.toml +0 -5
@@ 95,10 95,6 @@ id = 'email_config.update'
title = 'E-Mail-Konfigurationen bearbeiten'

[[permissions]]
id = 'email_config.view'
title = 'E-Mail-Konfigurationen anzeigen'

[[permissions]]
id = 'jobs.view'
title = 'Jobs anzeigen'



@@ 410,7 406,6 @@ id = 'email_admin'
title = 'E-Mail-Konfigurationen verwalten'
assigned_permissions = [
    'email_config.update',
    'email_config.view',
]

[[roles]]

M tests/integration/blueprints/admin/email/conftest.py => tests/integration/blueprints/admin/email/conftest.py +0 -1
@@ 13,7 13,6 @@ def email_admin(make_admin):
    permission_ids = {
        'admin.access',
        'email_config.update',
        'email_config.view',
    }
    admin = make_admin('EmailAdmin', permission_ids)
    login_user(admin.id)

M tests/integration/blueprints/admin/email/test_views.py => tests/integration/blueprints/admin/email/test_views.py +0 -6
@@ 6,12 6,6 @@
import byceps.services.email.service as email_service


def test_index(email_admin_client, site):
    url = '/admin/email/configs'
    response = email_admin_client.get(url)
    assert response.status_code == 200


def test_update_form(email_admin_client, email_config):
    url = f'/admin/email/configs/{email_config.id}/update'
    response = email_admin_client.get(url)