diff --git a/max/db/aliases.py b/max/db/aliases.py index 15792db..c22a449 100644 --- a/max/db/aliases.py +++ b/max/db/aliases.py @@ -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()) diff --git a/max/db/schema.sql b/max/db/schema.sql index 9dbe970..ef1d0e3 100644 --- a/max/db/schema.sql +++ b/max/db/schema.sql @@ -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) ); diff --git a/max/db/users.py b/max/db/users.py index b30c0db..0ce8c47 100644 --- a/max/db/users.py +++ b/max/db/users.py @@ -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}") diff --git a/max/private_static/i18n/de.json b/max/private_static/i18n/de.json index 892857e..20463e1 100644 --- a/max/private_static/i18n/de.json +++ b/max/private_static/i18n/de.json @@ -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", diff --git a/max/routes/__init__.py b/max/routes/__init__.py index e79e2e1..bd76a20 100644 --- a/max/routes/__init__.py +++ b/max/routes/__init__.py @@ -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//toggle-can-receive", - "user-toggle-can-receive", - UserToggleCanReceive.as_view(), - ) app.add_url_rule( "/user//toggle-admin", "user-toggle-admin", @@ -64,11 +57,6 @@ def init_routes(app): "alias-toggle-enabled", AliasToggleEnabled.as_view(), ) - app.add_url_rule( - "/alias//toggle-can-receive", - "alias-toggle-can-receive", - AliasToggleCanReceive.as_view(), - ) app.add_url_rule( "/robots.txt", diff --git a/max/routes/alias/create.py b/max/routes/alias/create.py index f87695c..398440d 100644 --- a/max/routes/alias/create.py +++ b/max/routes/alias/create.py @@ -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 diff --git a/max/routes/alias/toggle_can_receive.py b/max/routes/alias/toggle_can_receive.py deleted file mode 100644 index 4bad750..0000000 --- a/max/routes/alias/toggle_can_receive.py +++ /dev/null @@ -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) diff --git a/max/routes/user/create.py b/max/routes/user/create.py index 36aad8a..ac2cce3 100644 --- a/max/routes/user/create.py +++ b/max/routes/user/create.py @@ -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 diff --git a/max/routes/user/toggle_can_receive.py b/max/routes/user/toggle_can_receive.py deleted file mode 100644 index edb0bf3..0000000 --- a/max/routes/user/toggle_can_receive.py +++ /dev/null @@ -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) diff --git a/max/templates/alias/create.html b/max/templates/alias/create.html index 5800897..5945607 100644 --- a/max/templates/alias/create.html +++ b/max/templates/alias/create.html @@ -17,13 +17,6 @@ -
- -
-
diff --git a/max/templates/alias/detail.html b/max/templates/alias/detail.html index 7640707..b753401 100644 --- a/max/templates/alias/detail.html +++ b/max/templates/alias/detail.html @@ -9,10 +9,6 @@ {{ t("Enabled") }}: {{ macros.checkbox(alias, "enabled", url_for('alias-toggle-enabled', alias_id=alias.id, return='detail')) }}
-
- {{ t("Can receive emails") }}: - {{ macros.checkbox(alias, "can_receive", url_for('alias-toggle-can-receive', alias_id=alias.id, return='detail')) }} -
-
- -
-
-
- {{ t("Can receive emails") }}: - {{ macros.checkbox(user, "can_receive", url_for('user-toggle-can-receive', user_id=user.id, return='detail')) }} -
{{ t("Admin") }}: {{ macros.checkbox(user, "is_admin", url_for('user-toggle-admin', user_id=user.id, return='detail')) }} @@ -74,7 +70,6 @@ {{ t("Email") }} {{ t("Enabled") }} - {{ t("Can receive emails") }} {{ t("Note") }} {{ t("Actions") }} @@ -89,9 +84,6 @@ {{ macros.checkbox(alias, "enabled", url_for('alias-toggle-enabled', alias_id=alias.id)) }} - - {{ macros.checkbox(alias, "can_receive", url_for('alias-toggle-can-receive', alias_id=alias.id)) }} - {{ macros.format_note(alias) }} diff --git a/max/templates/user/list.html b/max/templates/user/list.html index cd748e7..64bf1dc 100644 --- a/max/templates/user/list.html +++ b/max/templates/user/list.html @@ -20,7 +20,6 @@ {{ t("Email") }} {{ t("Enabled") }} - {{ t("Can receive emails") }} {{ t("Admin") }} {{ t("Note") }} {{ t("Actions") }} @@ -36,9 +35,6 @@ {{ macros.checkbox(user, "enabled", url_for('user-toggle-enabled', user_id=user.id)) }} - - {{ macros.checkbox(user, "can_receive", url_for('user-toggle-can-receive', user_id=user.id)) }} - {{ macros.checkbox(user, "is_admin", url_for('user-toggle-admin', user_id=user.id)) }}