New flag AdminUnit.incoming_reference_requests_allowed #91

This commit is contained in:
Daniel Grams 2021-01-25 12:56:00 +01:00
parent d87b788e64
commit bc923ebde3
10 changed files with 149 additions and 14 deletions

View File

@ -0,0 +1,33 @@
"""empty message
Revision ID: b1a6e7630185
Revises: 35a6577b6af8
Create Date: 2021-01-25 11:38:36.483434
"""
from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils
from project import dbtypes
# revision identifiers, used by Alembic.
revision = "b1a6e7630185"
down_revision = "35a6577b6af8"
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"adminunit",
sa.Column("incoming_reference_requests_allowed", sa.Boolean(), nullable=True),
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("adminunit", "incoming_reference_requests_allowed")
# ### end Alembic commands ###

View File

@ -4,6 +4,7 @@ from flask_security.utils import FsPermNeed
from flask_principal import Permission
from project.models import AdminUnitMember, AdminUnit
from project.services.admin_unit import get_member_for_admin_unit_by_user_id
from sqlalchemy import and_
def has_current_user_permission(permission):
@ -101,7 +102,12 @@ def can_request_event_reference(event):
def get_admin_units_for_event_reference_request(event):
return AdminUnit.query.filter(AdminUnit.id != event.admin_unit_id).all()
return AdminUnit.query.filter(
and_(
AdminUnit.id != event.admin_unit_id,
AdminUnit.incoming_reference_requests_allowed,
)
).all()
def admin_units_the_current_user_is_member_of():

View File

@ -1,6 +1,6 @@
from flask_wtf import FlaskForm
from flask_babelex import lazy_gettext
from wtforms import TextAreaField, SubmitField
from wtforms import TextAreaField, SubmitField, BooleanField
from wtforms.validators import Optional
from project.forms.widgets import MultiCheckboxField
@ -17,3 +17,14 @@ class AdminSettingsForm(FlaskForm):
class UpdateUserForm(FlaskForm):
roles = MultiCheckboxField(lazy_gettext("Roles"))
submit = SubmitField(lazy_gettext("Update user"))
class UpdateAdminUnitForm(FlaskForm):
incoming_reference_requests_allowed = BooleanField(
lazy_gettext("Incoming reference requests allowed"),
description=lazy_gettext(
"If set, other admin units can ask this admin unit to reference their event."
),
validators=[Optional()],
)
submit = SubmitField(lazy_gettext("Update admin unit"))

View File

@ -210,6 +210,7 @@ class AdminUnit(db.Model, TrackableMixin):
widget_background_color = Column(ColorType)
widget_primary_color = Column(ColorType)
widget_link_color = Column(ColorType)
incoming_reference_requests_allowed = Column(Boolean())
@listens_for(AdminUnit, "before_insert")

View File

@ -1,4 +1,5 @@
{% extends "layout.html" %}
{% from "_macros.html" import render_pagination %}
{% block title %}
{{ _('Admin Units') }}
{% endblock %}
@ -16,16 +17,20 @@
<thead>
<tr>
<th>{{ _('Name') }}</th>
<th></th>
</tr>
</thead>
<tbody>
{% for admin_unit in admin_units %}
<tr>
<td>{{ admin_unit.name }}</td>
<td><a href="{{ url_for('admin_admin_unit_update', id=admin_unit.id) }}">{{ _('Edit') }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="my-4">{{ render_pagination(pagination) }}</div>
{% endblock %}

View File

@ -0,0 +1,25 @@
{% extends "layout.html" %}
{% from "_macros.html" import render_field_with_errors, render_field %}
{% block title %}
{{ _('Update admin unit') }}
{% endblock %}
{% block content %}
<h1>{{ _('Update admin unit') }}</h1>
<form action="" method="POST">
{{ form.hidden_tag() }}
<div class="card mb-4">
<div class="card-header">
{{ admin_unit.name }}
</div>
<div class="card-body">
{{ render_field_with_errors(form.incoming_reference_requests_allowed, style="width: fit-content; flex: initial;") }}
</div>
</div>
{{ render_field(form.submit) }}
</form>
{% endblock %}

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2021-01-25 10:17+0100\n"
"POT-Creation-Date: 2021-01-25 11:56+0100\n"
"PO-Revision-Date: 2020-06-07 18:51+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: de\n"
@ -158,6 +158,21 @@ msgstr "Rollen"
msgid "Update user"
msgstr "Nutzer aktualisieren"
#: project/forms/admin.py:24
msgid "Incoming reference requests allowed"
msgstr "Eingehende Empfehlungsanfragen erlauben"
#: project/forms/admin.py:25
msgid ""
"If set, other admin units can ask this admin unit to reference their "
"event."
msgstr "Wenn gesetzt, können andere Organisationen diese Organisation bitten, deren Veranstaltungen zu empfehlen."
#: project/forms/admin.py:30 project/templates/admin/update_admin_unit.html:4
#: project/templates/admin/update_admin_unit.html:8
msgid "Update admin unit"
msgstr "Organisation aktualisieren"
#: project/forms/admin_unit.py:17 project/forms/event.py:32
#: project/forms/event_place.py:17 project/forms/organizer.py:16
msgid "Street"
@ -194,7 +209,7 @@ msgstr "Längengrad"
#: project/forms/event_suggestion.py:25 project/forms/organizer.py:29
#: project/forms/organizer.py:56 project/forms/reference.py:39
#: project/forms/reference_request.py:21 project/templates/_macros.html:115
#: project/templates/admin/admin_units.html:18
#: project/templates/admin/admin_units.html:19
#: project/templates/event_place/list.html:19 project/templates/profile.html:19
#: project/templates/profile.html:39
msgid "Name"
@ -1099,7 +1114,7 @@ msgid "Profile"
msgstr "Profil"
#: project/templates/admin/admin.html:3 project/templates/admin/admin.html:9
#: project/templates/admin/admin_units.html:9
#: project/templates/admin/admin_units.html:10
#: project/templates/admin/users.html:10 project/templates/layout.html:130
msgid "Admin"
msgstr "Administration"
@ -1182,8 +1197,8 @@ msgid "Invitations"
msgstr "Einladungen"
#: project/templates/admin/admin.html:19
#: project/templates/admin/admin_units.html:3
#: project/templates/admin/admin_units.html:10
#: project/templates/admin/admin_units.html:4
#: project/templates/admin/admin_units.html:11
#: project/templates/manage/admin_units.html:3
#: project/templates/manage/admin_units.html:16
#: project/templates/profile.html:34
@ -1195,6 +1210,7 @@ msgstr "Organisationen"
msgid "Users"
msgstr "Benutzer"
#: project/templates/admin/admin_units.html:27
#: project/templates/admin/users.html:27
#: project/templates/manage/events.html:27
#: project/templates/manage/members.html:35
@ -1485,11 +1501,16 @@ msgstr "Optionale Details"
msgid "Preview"
msgstr "Vorschau"
#: project/views/admin.py:41 project/views/manage.py:247
#: project/views/admin.py:45
#, fuzzy
msgid "Admin unit successfully updated"
msgstr "Organisation erfolgreich aktualisiert"
#: project/views/admin.py:68 project/views/manage.py:247
msgid "Settings successfully updated"
msgstr "Einstellungen erfolgreich aktualisiert"
#: project/views/admin.py:76
#: project/views/admin.py:103
msgid "User successfully updated"
msgstr "Nutzer erfolgreich aktualisiert"
@ -1638,14 +1659,16 @@ msgstr "Empfehlungsanfrage erfolgreich aktualisiert"
msgid ""
"An entry with the entered values already exists. Duplicate entries are "
"not allowed."
msgstr "Ein Eintrag mit den eingegebenen Werten existiert bereits. Doppelte Einträge sind nicht erlaubt."
msgstr ""
"Ein Eintrag mit den eingegebenen Werten existiert bereits. Doppelte "
"Einträge sind nicht erlaubt."
#: project/views/utils.py:61
#: project/views/utils.py:63
#, python-format
msgid "Error in the %s field - %s"
msgstr "Fehler im Feld %s: %s"
#: project/views/utils.py:69
#: project/views/utils.py:71
msgid "Show"
msgstr "Anzeigen"

View File

@ -3,7 +3,7 @@ from project.models import AdminUnit, User, Role
from flask import render_template, flash, url_for, redirect
from flask_babelex import gettext
from flask_security import roles_required
from project.forms.admin import AdminSettingsForm, UpdateUserForm
from project.forms.admin import AdminSettingsForm, UpdateUserForm, UpdateAdminUnitForm
from project.services.admin import upsert_settings
from project.services.user import set_roles_for_user
from project.views.utils import (
@ -24,7 +24,37 @@ def admin():
@app.route("/admin/admin_units")
@roles_required("admin")
def admin_admin_units():
return render_template("admin/admin_units.html", admin_units=AdminUnit.query.all())
admin_units = AdminUnit.query.order_by(func.lower(AdminUnit.name)).paginate()
return render_template(
"admin/admin_units.html",
admin_units=admin_units.items,
pagination=get_pagination_urls(admin_units),
)
@app.route("/admin/admin_unit/<int:id>/update", methods=("GET", "POST"))
@roles_required("admin")
def admin_admin_unit_update(id):
admin_unit = AdminUnit.query.get_or_404(id)
form = UpdateAdminUnitForm(obj=admin_unit)
if form.validate_on_submit():
form.populate_obj(admin_unit)
try:
db.session.commit()
flash(gettext("Admin unit successfully updated"), "success")
return redirect(url_for("admin_admin_units"))
except SQLAlchemyError as e:
db.session.rollback()
flash(handleSqlError(e), "danger")
else:
flash_errors(form)
return render_template(
"admin/update_admin_unit.html", admin_unit=admin_unit, form=form
)
@app.route("/admin/settings", methods=("GET", "POST"))

View File

@ -50,6 +50,7 @@ class Seeder(object):
admin_unit = AdminUnit()
admin_unit.name = name
admin_unit.short_name = name.lower().replace(" ", "")
admin_unit.incoming_reference_requests_allowed = True
insert_admin_unit_for_user(admin_unit, user)
self._db.session.commit()
admin_unit_id = admin_unit.id