remove can_receive

This commit is contained in:
Finn Stutzenstein 2022-03-06 11:14:19 +01:00
parent 8f623a264d
commit 818a43202a
14 changed files with 19 additions and 112 deletions

View File

@ -12,7 +12,6 @@ class Alias(NoteLinesMixin):
email: str email: str
destination_user_id: int destination_user_id: int
enabled: bool enabled: bool
can_receive: bool
note: str note: str
@ -36,9 +35,8 @@ def get_aliases(cur, user_id):
def get_alias_with_user_by_id(cur, alias_id): def get_alias_with_user_by_id(cur, alias_id):
cur.execute( cur.execute(
"""\ """\
SELECT a.id, a.source_email_id, ea.email, a.destination_user_id, a.enabled, SELECT a.id, a.source_email_id, ea.email, a.destination_user_id, a.enabled, a.note,
a.can_receive, a.note, u.id, u.email_id, eu.email, u.passwordhash, u.enabled, u.is_admin, u.note
u.id, u.email_id, eu.email, u.passwordhash, u.enabled, u.can_receive, u.is_admin, u.note
FROM aliases a FROM aliases a
INNER JOIN emails ea ON a.source_email_id=ea.id INNER JOIN emails ea ON a.source_email_id=ea.id
INNER JOIN users u ON a.destination_user_id=u.id INNER JOIN users u ON a.destination_user_id=u.id
@ -49,23 +47,23 @@ def get_alias_with_user_by_id(cur, alias_id):
row = cur.fetchone() row = cur.fetchone()
if not row: if not row:
return None return None
return Alias(*row[:7]), User(*row[7:]) return Alias(*row[:6]), User(*row[6:])
@with_cursor @with_cursor
def create_alias(cur, email, user, enabled, can_receive, note): def create_alias(cur, email, user, enabled, note):
email_id = create_email(cur, email) email_id = create_email(cur, email)
cur.execute( cur.execute(
""" """
INSERT INTO aliases (source_email_id, destination_user_id, enabled, can_receive, note) INSERT INTO aliases (source_email_id, destination_user_id, enabled, note)
VALUES (%s, %s, %s, %s, %s)""", VALUES (%s, %s, %s, %s, %s)""",
[email_id, user.id, enabled, can_receive, note], [email_id, user.id, enabled, note],
) )
@with_cursor @with_cursor
def update_alias(cur, id, **fields): def update_alias(cur, id, **fields):
"""updates enabled, can_receive and note""" """updates enabled and note"""
cur.execute( cur.execute(
"UPDATE aliases SET " "UPDATE aliases SET "
+ ", ".join(f"{field}=%s" for field in fields.keys()) + ", ".join(f"{field}=%s" for field in fields.keys())

View File

@ -15,7 +15,6 @@ CREATE TABLE IF NOT EXISTS users (
email_id integer REFERENCES emails(id) ON DELETE RESTRICT NOT NULL UNIQUE, email_id integer REFERENCES emails(id) ON DELETE RESTRICT NOT NULL UNIQUE,
passwordhash varchar(255) NOT NULL, passwordhash varchar(255) NOT NULL,
enabled boolean NOT NULL DEFAULT TRUE, enabled boolean NOT NULL DEFAULT TRUE,
can_receive boolean NOT NULL DEFAULT TRUE,
is_admin boolean NOT NULL DEFAULT FALSE, is_admin boolean NOT NULL DEFAULT FALSE,
note text NOT NULL DEFAULT '' note text NOT NULL DEFAULT ''
); );
@ -26,7 +25,6 @@ CREATE TABLE IF NOT EXISTS aliases (
source_email_id integer REFERENCES emails(id) ON DELETE RESTRICT NOT NULL, source_email_id integer REFERENCES emails(id) ON DELETE RESTRICT NOT NULL,
destination_user_id integer REFERENCES users(id) ON DELETE RESTRICT NOT NULL, destination_user_id integer REFERENCES users(id) ON DELETE RESTRICT NOT NULL,
enabled boolean NOT NULL DEFAULT TRUE, enabled boolean NOT NULL DEFAULT TRUE,
can_receive boolean NOT NULL DEFAULT TRUE,
note text, note text,
UNIQUE(source_email_id, destination_user_id) UNIQUE(source_email_id, destination_user_id)
); );

View File

@ -11,7 +11,6 @@ class User(NoteLinesMixin):
email: str email: str
passwordhash: str passwordhash: str
enabled: bool enabled: bool
can_receive: bool
is_admin: bool is_admin: bool
note: str note: str
@ -53,7 +52,7 @@ def get_users(cur):
@with_cursor @with_cursor
def update_user(cur, id, **fields): def update_user(cur, id, **fields):
"""only pwhash, enabled, can_receive, is_admin, note""" """only pwhash, enabled, is_admin, note"""
cur.execute( cur.execute(
"UPDATE users SET " "UPDATE users SET "
+ ", ".join(f"{field}=%s" for field in fields.keys()) + ", ".join(f"{field}=%s" for field in fields.keys())
@ -63,13 +62,13 @@ def update_user(cur, id, **fields):
@with_cursor @with_cursor
def create_user(cur, email, passwordhash, enabled, can_receive, is_admin, note): def create_user(cur, email, passwordhash, enabled, is_admin, note):
email_id = create_email(cur, email) email_id = create_email(cur, email)
cur.execute( cur.execute(
"""\ """\
INSERT INTO users (email_id, passwordhash, enabled, can_receive, is_admin, note) INSERT INTO users (email_id, passwordhash, enabled, is_admin, note)
VALUES (%s, %s, %s, %s, %s, %s)""", VALUES (%s, %s, %s, %s, %s, %s)""",
[email_id, passwordhash, enabled, can_receive, is_admin, note], [email_id, passwordhash, enabled, is_admin, note],
) )
@ -93,8 +92,8 @@ def reset_or_create_user(cur, email, hash, is_admin):
user_id = user_id[0] user_id = user_id[0]
# update User # update User
cur.execute( cur.execute(
"UPDATE users SET passwordhash=%s, is_admin=%s, enabled=%s, can_receive=%s WHERE id=%s", # noqa "UPDATE users SET passwordhash=%s, is_admin=%s, enabled=%s WHERE id=%s",
[hash, is_admin, True, True, user_id], [hash, is_admin, True, user_id],
) )
print( print(
f"reset password for {email}. Set admin={is_admin} and enabled the user." f"reset password for {email}. Set admin={is_admin} and enabled the user."
@ -106,8 +105,8 @@ def reset_or_create_user(cur, email, hash, is_admin):
cur.execute("INSERT INTO emails (email) VALUES (%s) RETURNING id", [email]) cur.execute("INSERT INTO emails (email) VALUES (%s) RETURNING id", [email])
email_id = cur.fetchone()[0] email_id = cur.fetchone()[0]
cur.execute( cur.execute(
"INSERT INTO users (email_id, passwordhash, enabled, can_receive, is_admin, note) VALUES (%s, %s, %s, %s, %s, %s)", # noqa "INSERT INTO users (email_id, passwordhash, enabled, is_admin, note) VALUES (%s, %s, %s, %s, %s)", # noqa
[email_id, hash, True, True, is_admin, "Created by commandline"], [email_id, hash, True, is_admin, "Created by commandline"],
) )
user_type = "admin" if is_admin else "user" user_type = "admin" if is_admin else "user"
print(f"Created {user_type} {email}") print(f"Created {user_type} {email}")

View File

@ -19,7 +19,6 @@
"Create new user": "Neuen Nutzer erstellen", "Create new user": "Neuen Nutzer erstellen",
"Create": "Erstellen", "Create": "Erstellen",
"Enabled": "Aktiviert", "Enabled": "Aktiviert",
"Can receive emails": "Kann Emails empfangen",
"Admin": "Admin", "Admin": "Admin",
"Note": "Notiz", "Note": "Notiz",
"Delete {user}?": "{user} löschen?", "Delete {user}?": "{user} löschen?",
@ -48,7 +47,6 @@
"The domain is invalid. Must be one of: {domains}": "Die Domain ist nacht valide. Dies sind die erlaubten Domains: {domains}", "The domain is invalid. Must be one of: {domains}": "Die Domain ist nacht valide. Dies sind die erlaubten Domains: {domains}",
"Email must be given": "Die Email muss gegeben sein", "Email must be given": "Die Email muss gegeben sein",
"Enabled is not set": "Aktiviert ist nicht gesetzt", "Enabled is not set": "Aktiviert ist nicht gesetzt",
"Can receive is not set": "Kann empfangen ist nicht gesetzt",
"Note must be a string": "Die Notiz muss eine Zeichenkette sein", "Note must be a string": "Die Notiz muss eine Zeichenkette sein",
"Creation of alias {email} was successful!": "Erstellen des Alias {email} war erfolgreich!", "Creation of alias {email} was successful!": "Erstellen des Alias {email} war erfolgreich!",
"Alias {email} was deleted successfully": "Alias {email} wurde erfolgreich gelöscht", "Alias {email} was deleted successfully": "Alias {email} wurde erfolgreich gelöscht",

View File

@ -5,7 +5,6 @@ from .alias.create import AliasCreate
from .alias.delete import AliasDelete from .alias.delete import AliasDelete
from .alias.detail import AliasDetail from .alias.detail import AliasDetail
from .alias.edit_note import AliasEditNote from .alias.edit_note import AliasEditNote
from .alias.toggle_can_receive import AliasToggleCanReceive
from .alias.toggle_enabled import AliasToggleEnabled from .alias.toggle_enabled import AliasToggleEnabled
from .favicon import Favicon from .favicon import Favicon
from .robots import RobotsTXT from .robots import RobotsTXT
@ -16,7 +15,6 @@ from .user.detail import UserDetail
from .user.edit_note import UserEditNote from .user.edit_note import UserEditNote
from .user.list import UserList from .user.list import UserList
from .user.toggle_admin import UserToggleAdmin from .user.toggle_admin import UserToggleAdmin
from .user.toggle_can_receive import UserToggleCanReceive
from .user.toggle_enabled import UserToggleEnabled from .user.toggle_enabled import UserToggleEnabled
@ -38,11 +36,6 @@ def init_routes(app):
"user-toggle-enabled", "user-toggle-enabled",
UserToggleEnabled.as_view(), UserToggleEnabled.as_view(),
) )
app.add_url_rule(
"/user/<int:user_id>/toggle-can-receive",
"user-toggle-can-receive",
UserToggleCanReceive.as_view(),
)
app.add_url_rule( app.add_url_rule(
"/user/<int:user_id>/toggle-admin", "/user/<int:user_id>/toggle-admin",
"user-toggle-admin", "user-toggle-admin",
@ -64,11 +57,6 @@ def init_routes(app):
"alias-toggle-enabled", "alias-toggle-enabled",
AliasToggleEnabled.as_view(), AliasToggleEnabled.as_view(),
) )
app.add_url_rule(
"/alias/<int:alias_id>/toggle-can-receive",
"alias-toggle-can-receive",
AliasToggleCanReceive.as_view(),
)
app.add_url_rule( app.add_url_rule(
"/robots.txt", "/robots.txt",

View File

@ -38,15 +38,6 @@ class AliasCreate(
flash(t("Enabled is not set"), category="error") flash(t("Enabled is not set"), category="error")
error = True error = True
can_receive = self.request.form.get("can_receive")
if can_receive == "on":
self.can_receive = True
elif can_receive is None:
self.can_receive = False
else:
flash(t("Can receive is not set"), category="error")
error = True
note = self.request.form.get("note", "") note = self.request.form.get("note", "")
if not isinstance(note, str): if not isinstance(note, str):
flash(t("Note must be a string"), category="error") flash(t("Note must be a string"), category="error")
@ -59,7 +50,7 @@ class AliasCreate(
try: try:
create_alias( create_alias(
self.email, self.user, self.enabled, self.can_receive, self.note self.email, self.user, self.enabled, self.note
) )
except EmailAlreadyExists as e: except EmailAlreadyExists as e:
if self.auth_user.is_admin: if self.auth_user.is_admin:
@ -79,7 +70,7 @@ class AliasCreate(
def get_context(self): def get_context(self):
context = super().get_context() context = super().get_context()
for key in ("email", "enabled", "can_receive", "note"): for key in ("email", "enabled", "note"):
if hasattr(self, key): if hasattr(self, key):
context[key] = getattr(self, key) context[key] = getattr(self, key)
return context return context

View File

@ -1,14 +0,0 @@
from max.db import update_alias
from max.permissions import AllowAdminOrSelf
from max.views import BaseView
from ..base_alias_views import BackToAliasesMixin, FetchAliasMixin
class AliasToggleCanReceive(
AllowAdminOrSelf, FetchAliasMixin, BackToAliasesMixin, BaseView
):
def post(self):
update_alias(self.alias.id, can_receive=(not self.alias.can_receive))
_, back_url = self.get_back_text_and_url()
return self.redirect(back_url)

View File

@ -48,15 +48,6 @@ class UserCreate(AllowAdmin, CheckEmailMixin, BackToUsersMixin, BaseTemplateGetV
flash(t("Enabled is not set"), category="error") flash(t("Enabled is not set"), category="error")
error = True error = True
can_receive = self.request.form.get("can_receive")
if can_receive == "on":
self.can_receive = True
elif can_receive is None:
self.can_receive = False
else:
flash(t("Can receive is not set"), category="error")
error = True
is_admin = self.request.form.get("is_admin") is_admin = self.request.form.get("is_admin")
if is_admin == "on": if is_admin == "on":
self.is_admin = True self.is_admin = True
@ -79,7 +70,7 @@ class UserCreate(AllowAdmin, CheckEmailMixin, BackToUsersMixin, BaseTemplateGetV
passwordhash = hash_password(self.password) passwordhash = hash_password(self.password)
try: try:
create_user( create_user(
self.email, passwordhash, self.enabled, self.can_receive, self.is_admin, self.note self.email, passwordhash, self.enabled, self.is_admin, self.note
) )
except EmailAlreadyExists as e: except EmailAlreadyExists as e:
if self.auth_user.is_admin: if self.auth_user.is_admin:
@ -96,7 +87,7 @@ class UserCreate(AllowAdmin, CheckEmailMixin, BackToUsersMixin, BaseTemplateGetV
def get_context(self): def get_context(self):
context = super().get_context() context = super().get_context()
for key in ("email", "password", "enabled", "can_receive", "is_admin", "note"): for key in ("email", "password", "enabled", "is_admin", "note"):
if hasattr(self, key): if hasattr(self, key):
context[key] = getattr(self, key) context[key] = getattr(self, key)
return context return context

View File

@ -1,12 +0,0 @@
from max.db import update_user
from max.permissions import AllowAdmin
from max.views import BaseView
from ..base_user_views import BackToUsersMixin, FetchUserMixin
class UserToggleCanReceive(AllowAdmin, FetchUserMixin, BackToUsersMixin, BaseView):
def post(self):
update_user(self.user.id, can_receive=(not self.user.can_receive))
_, back_url = self.get_back_text_and_url()
return self.redirect(back_url)

View File

@ -17,13 +17,6 @@
</label> </label>
</div> </div>
<div class="pure-controls checkbox">
<label for="can_receive">
<input id="can_receive" type="checkbox" name="can_receive" {% if can_receive %}checked{% endif %}>
{{ t("Can receive emails") }}
</label>
</div>
<div class="pure-control-group"> <div class="pure-control-group">
<label for="note">{{ t("Note") }}</label> <label for="note">{{ t("Note") }}</label>
<textarea id="note" name="note" form="form">{% if note is defined %}{{ note }}{% endif %}</textarea> <textarea id="note" name="note" form="form">{% if note is defined %}{{ note }}{% endif %}</textarea>

View File

@ -9,10 +9,6 @@
<b>{{ t("Enabled") }}:</b> <b>{{ t("Enabled") }}:</b>
{{ macros.checkbox(alias, "enabled", url_for('alias-toggle-enabled', alias_id=alias.id, return='detail')) }} {{ macros.checkbox(alias, "enabled", url_for('alias-toggle-enabled', alias_id=alias.id, return='detail')) }}
</div> </div>
<div>
<b>{{ t("Can receive emails") }}:</b>
{{ macros.checkbox(alias, "can_receive", url_for('alias-toggle-can-receive', alias_id=alias.id, return='detail')) }}
</div>
<div class="note"> <div class="note">
<b>{{ t("Note") }}:</b><div>{{ macros.format_note(alias) }}</div> <b>{{ t("Note") }}:</b><div>{{ macros.format_note(alias) }}</div>
<a href="{{ url_for('alias-edit-note', alias_id=alias.id, return='detail') }}" class="button-small pure-button optional"> <a href="{{ url_for('alias-edit-note', alias_id=alias.id, return='detail') }}" class="button-small pure-button optional">

View File

@ -27,13 +27,6 @@
</label> </label>
</div> </div>
<div class="pure-controls checkbox">
<label for="can_receive">
<input id="can_receive" type="checkbox" name="can_receive" {% if can_receive %}checked{% endif %}>
{{ t("Can receive emails") }}
</label>
</div>
<div class="pure-controls checkbox"> <div class="pure-controls checkbox">
<label for="is_admin"> <label for="is_admin">
<input id="is_admin" type="checkbox" name="is_admin" {% if is_admin %}checked{% endif %}> <input id="is_admin" type="checkbox" name="is_admin" {% if is_admin %}checked{% endif %}>

View File

@ -20,10 +20,6 @@
<b>{{ t("Enabled") }}:</b> <b>{{ t("Enabled") }}:</b>
{{ macros.checkbox(user, "enabled", url_for('user-toggle-enabled', user_id=user.id, return='detail')) }} {{ macros.checkbox(user, "enabled", url_for('user-toggle-enabled', user_id=user.id, return='detail')) }}
</div> </div>
<div>
<b>{{ t("Can receive emails") }}:</b>
{{ macros.checkbox(user, "can_receive", url_for('user-toggle-can-receive', user_id=user.id, return='detail')) }}
</div>
<div> <div>
<b>{{ t("Admin") }}:</b> <b>{{ t("Admin") }}:</b>
{{ macros.checkbox(user, "is_admin", url_for('user-toggle-admin', user_id=user.id, return='detail')) }} {{ macros.checkbox(user, "is_admin", url_for('user-toggle-admin', user_id=user.id, return='detail')) }}
@ -74,7 +70,6 @@
<tr> <tr>
<th>{{ t("Email") }}</th> <th>{{ t("Email") }}</th>
<th>{{ t("Enabled") }}</th> <th>{{ t("Enabled") }}</th>
<th>{{ t("Can receive emails") }}</th>
<th>{{ t("Note") }}</th> <th>{{ t("Note") }}</th>
<th class="optional">{{ t("Actions") }}</th> <th class="optional">{{ t("Actions") }}</th>
</tr> </tr>
@ -89,9 +84,6 @@
<td> <td>
{{ macros.checkbox(alias, "enabled", url_for('alias-toggle-enabled', alias_id=alias.id)) }} {{ macros.checkbox(alias, "enabled", url_for('alias-toggle-enabled', alias_id=alias.id)) }}
</td> </td>
<td>
{{ macros.checkbox(alias, "can_receive", url_for('alias-toggle-can-receive', alias_id=alias.id)) }}
</td>
<td> <td>
{{ macros.format_note(alias) }} {{ macros.format_note(alias) }}
<a href="{{ url_for('alias-edit-note', alias_id=alias.id) }}" class="button-small pure-button optional"> <a href="{{ url_for('alias-edit-note', alias_id=alias.id) }}" class="button-small pure-button optional">

View File

@ -20,7 +20,6 @@
<tr> <tr>
<th>{{ t("Email") }}</th> <th>{{ t("Email") }}</th>
<th>{{ t("Enabled") }}</th> <th>{{ t("Enabled") }}</th>
<th>{{ t("Can receive emails") }}</th>
<th>{{ t("Admin") }}</th> <th>{{ t("Admin") }}</th>
<th>{{ t("Note") }}</th> <th>{{ t("Note") }}</th>
<th class="optional">{{ t("Actions") }}</th> <th class="optional">{{ t("Actions") }}</th>
@ -36,9 +35,6 @@
<td> <td>
{{ macros.checkbox(user, "enabled", url_for('user-toggle-enabled', user_id=user.id)) }} {{ macros.checkbox(user, "enabled", url_for('user-toggle-enabled', user_id=user.id)) }}
</td> </td>
<td>
{{ macros.checkbox(user, "can_receive", url_for('user-toggle-can-receive', user_id=user.id)) }}
</td>
<td> <td>
{{ macros.checkbox(user, "is_admin", url_for('user-toggle-admin', user_id=user.id)) }} {{ macros.checkbox(user, "is_admin", url_for('user-toggle-admin', user_id=user.id)) }}
</td> </td>