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
destination_user_id: int
enabled: bool
can_receive: bool
note: str
@ -36,9 +35,8 @@ def get_aliases(cur, user_id):
def get_alias_with_user_by_id(cur, alias_id):
cur.execute(
"""\
SELECT a.id, a.source_email_id, ea.email, a.destination_user_id, a.enabled,
a.can_receive, a.note,
u.id, u.email_id, eu.email, u.passwordhash, u.enabled, u.can_receive, u.is_admin, u.note
SELECT a.id, a.source_email_id, ea.email, a.destination_user_id, a.enabled, a.note,
u.id, u.email_id, eu.email, u.passwordhash, u.enabled, u.is_admin, u.note
FROM aliases a
INNER JOIN emails ea ON a.source_email_id=ea.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()
if not row:
return None
return Alias(*row[:7]), User(*row[7:])
return Alias(*row[:6]), User(*row[6:])
@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)
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)""",
[email_id, user.id, enabled, can_receive, note],
[email_id, user.id, enabled, note],
)
@with_cursor
def update_alias(cur, id, **fields):
"""updates enabled, can_receive and note"""
"""updates enabled and note"""
cur.execute(
"UPDATE aliases SET "
+ ", ".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,
passwordhash varchar(255) NOT NULL,
enabled boolean NOT NULL DEFAULT TRUE,
can_receive boolean NOT NULL DEFAULT TRUE,
is_admin boolean NOT NULL DEFAULT FALSE,
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,
destination_user_id integer REFERENCES users(id) ON DELETE RESTRICT NOT NULL,
enabled boolean NOT NULL DEFAULT TRUE,
can_receive boolean NOT NULL DEFAULT TRUE,
note text,
UNIQUE(source_email_id, destination_user_id)
);

View File

@ -11,7 +11,6 @@ class User(NoteLinesMixin):
email: str
passwordhash: str
enabled: bool
can_receive: bool
is_admin: bool
note: str
@ -53,7 +52,7 @@ def get_users(cur):
@with_cursor
def update_user(cur, id, **fields):
"""only pwhash, enabled, can_receive, is_admin, note"""
"""only pwhash, enabled, is_admin, note"""
cur.execute(
"UPDATE users SET "
+ ", ".join(f"{field}=%s" for field in fields.keys())
@ -63,13 +62,13 @@ def update_user(cur, id, **fields):
@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)
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)""",
[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]
# update User
cur.execute(
"UPDATE users SET passwordhash=%s, is_admin=%s, enabled=%s, can_receive=%s WHERE id=%s", # noqa
[hash, is_admin, True, True, user_id],
"UPDATE users SET passwordhash=%s, is_admin=%s, enabled=%s WHERE id=%s",
[hash, is_admin, True, user_id],
)
print(
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])
email_id = cur.fetchone()[0]
cur.execute(
"INSERT INTO users (email_id, passwordhash, enabled, can_receive, is_admin, note) VALUES (%s, %s, %s, %s, %s, %s)", # noqa
[email_id, hash, True, True, is_admin, "Created by commandline"],
"INSERT INTO users (email_id, passwordhash, enabled, is_admin, note) VALUES (%s, %s, %s, %s, %s)", # noqa
[email_id, hash, True, is_admin, "Created by commandline"],
)
user_type = "admin" if is_admin else "user"
print(f"Created {user_type} {email}")

View File

@ -19,7 +19,6 @@
"Create new user": "Neuen Nutzer erstellen",
"Create": "Erstellen",
"Enabled": "Aktiviert",
"Can receive emails": "Kann Emails empfangen",
"Admin": "Admin",
"Note": "Notiz",
"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}",
"Email must be given": "Die Email muss gegeben sein",
"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",
"Creation of alias {email} was successful!": "Erstellen des Alias {email} war erfolgreich!",
"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.detail import AliasDetail
from .alias.edit_note import AliasEditNote
from .alias.toggle_can_receive import AliasToggleCanReceive
from .alias.toggle_enabled import AliasToggleEnabled
from .favicon import Favicon
from .robots import RobotsTXT
@ -16,7 +15,6 @@ from .user.detail import UserDetail
from .user.edit_note import UserEditNote
from .user.list import UserList
from .user.toggle_admin import UserToggleAdmin
from .user.toggle_can_receive import UserToggleCanReceive
from .user.toggle_enabled import UserToggleEnabled
@ -38,11 +36,6 @@ def init_routes(app):
"user-toggle-enabled",
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(
"/user/<int:user_id>/toggle-admin",
"user-toggle-admin",
@ -64,11 +57,6 @@ def init_routes(app):
"alias-toggle-enabled",
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(
"/robots.txt",

View File

@ -38,15 +38,6 @@ class AliasCreate(
flash(t("Enabled is not set"), category="error")
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", "")
if not isinstance(note, str):
flash(t("Note must be a string"), category="error")
@ -59,7 +50,7 @@ class AliasCreate(
try:
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:
if self.auth_user.is_admin:
@ -79,7 +70,7 @@ class AliasCreate(
def get_context(self):
context = super().get_context()
for key in ("email", "enabled", "can_receive", "note"):
for key in ("email", "enabled", "note"):
if hasattr(self, key):
context[key] = getattr(self, key)
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")
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")
if is_admin == "on":
self.is_admin = True
@ -79,7 +70,7 @@ class UserCreate(AllowAdmin, CheckEmailMixin, BackToUsersMixin, BaseTemplateGetV
passwordhash = hash_password(self.password)
try:
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:
if self.auth_user.is_admin:
@ -96,7 +87,7 @@ class UserCreate(AllowAdmin, CheckEmailMixin, BackToUsersMixin, BaseTemplateGetV
def get_context(self):
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):
context[key] = getattr(self, key)
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>
</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">
<label for="note">{{ t("Note") }}</label>
<textarea id="note" name="note" form="form">{% if note is defined %}{{ note }}{% endif %}</textarea>

View File

@ -9,10 +9,6 @@
<b>{{ t("Enabled") }}:</b>
{{ macros.checkbox(alias, "enabled", url_for('alias-toggle-enabled', alias_id=alias.id, return='detail')) }}
</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">
<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">

View File

@ -27,13 +27,6 @@
</label>
</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">
<label for="is_admin">
<input id="is_admin" type="checkbox" name="is_admin" {% if is_admin %}checked{% endif %}>

View File

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

View File

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