New fixes

This commit is contained in:
Antoine Nguyen
2025-02-18 15:11:18 +01:00
parent 01fb00c38c
commit f202b702df
11 changed files with 34 additions and 18 deletions
+9 -5
View File
@@ -79,7 +79,7 @@ def create_ldap_account(user, dn, conn):
try:
conn.add_s(dn, ldif)
except ldap.LDAPError as e:
raise InternalError(_("Failed to create LDAP account: {}").format(e))
raise InternalError(_("Failed to create LDAP account: {}").format(e)) from None
def check_if_dn_exists(conn, dn):
@@ -118,7 +118,7 @@ def update_ldap_account(user, config):
try:
conn.modify_s(dn, ldif)
except ldap.LDAPError as e:
raise InternalError(_("Failed to update LDAP account: {}").format(e))
raise InternalError(_("Failed to update LDAP account: {}").format(e)) from None
def delete_ldap_account(user, config):
@@ -131,14 +131,18 @@ def delete_ldap_account(user, config):
try:
conn.delete_s(dn)
except ldap.LDAPError as e:
raise InternalError(_("Failed to delete LDAP account: {}").format(e))
raise InternalError(
_("Failed to delete LDAP account: {}").format(e)
) from None
else:
password = get_user_password(user, True)
ldif = [(ldap.MOD_REPLACE, "userPassword", password)]
try:
conn.modify_s(dn, ldif)
except ldap.LDAPError as e:
raise InternalError(_("Failed to disable LDAP account: {}").format(e))
raise InternalError(
_("Failed to disable LDAP account: {}").format(e)
) from None
def find_user_groups(conn, config, dn, entry):
@@ -154,7 +158,7 @@ def find_user_groups(conn, config, dn, entry):
result = conn.search_s(config["ldap_groups_search_base"], ldap.SCOPE_SUBTREE, flt)
groups = []
for dn, entry in result:
for dn, _entry in result:
if not dn:
continue
groups.append(dn.split(",")[0].split("=")[1])
+3 -1
View File
@@ -4,6 +4,8 @@
"""
from typing import Optional
from django.utils.translation import gettext as _
@@ -12,7 +14,7 @@ class ModoboaException(Exception):
Base class for Modoboa custom exceptions.
"""
http_code = None
http_code: Optional[int] = None
def __init__(self, *args, **kwargs):
if "http_code" in kwargs:
+2 -2
View File
@@ -42,7 +42,7 @@ from modoboa.lib.exceptions import InternalError
from modoboa.parameters import tools as param_tools
class LDAPAuthBackend(object):
class LDAPAuthBackend:
"""LDAP authentication backend."""
def __init__(self):
@@ -123,4 +123,4 @@ class LDAPAuthBackend(object):
try:
self.conn.modify_s(force_str(user_dn), ldif)
except ldap.LDAPError as e:
raise InternalError(_("Failed to update password: {}").format(e))
raise InternalError(_("Failed to update password: {}").format(e)) from None
+1 -1
View File
@@ -52,7 +52,7 @@ class Graphic:
"""Constructor."""
self._curves = []
try:
order = getattr(self, "order")
order = self.order
except AttributeError:
for member in inspect.getmembers(self):
if isinstance(member[1], Curve):
@@ -276,7 +276,7 @@ class LogParser:
# Est ce vraiment nécessaire... ?
if m > self.lupdates[fname] + rrdstep:
values = ""
for v in variables:
for _v in variables:
if values != "":
values += ":"
values += "0"
+1 -1
View File
@@ -124,7 +124,7 @@ class Registry:
if for_app and for_app != app:
continue
serializer = fields["serializer_class"]()
for section, sconfig in list(fields["structure"].items()):
for _section, sconfig in list(fields["structure"].items()):
item = {
"label": sconfig["label"],
"display": sconfig.get("display", ""),
+1 -1
View File
@@ -33,7 +33,7 @@ def init_storage_dir():
raise InternalError(
_("Failed to create the directory that will contain " "PDF documents (%s)")
% inst
)
) from None
def get_creds_filename(account):
+6 -2
View File
@@ -15,7 +15,11 @@ from rest_framework.decorators import action
from modoboa.lib.viewsets import HasMailbox
from modoboa.sievefilters import constants
from modoboa.sievefilters.lib import SieveClient, SieveClientError, SieveActionTemplateNotFound
from modoboa.sievefilters.lib import (
SieveClient,
SieveClientError,
SieveActionTemplateNotFound,
)
from modoboa.sievefilters.rfc6266 import build_header
from modoboa.sievefilters.api.v2 import serializers
@@ -184,7 +188,7 @@ class FilterSetViewSet(viewsets.ViewSet):
except FilterAlreadyExists:
raise serializers.ValidationError(
{"name": _("Filter %s already exists") % fltname}
)
) from None
sclient.pushscript(fset.name, str(fset))
return response.Response(serializer.validated_data, status=201)
+3 -3
View File
@@ -60,9 +60,9 @@ class IMAPconnector:
try:
typ, data = self.m._simple_command(name, *args)
except imaplib.IMAP4.error as e:
raise ImapError(e)
raise ImapError(e) from None
if typ == "NO":
raise ImapError(data)
raise ImapError(data) from None
if "responses" not in kwargs:
if name not in self.m.untagged_responses:
return None
@@ -104,7 +104,7 @@ class IMAPconnector:
else:
self.m = imaplib.IMAP4(self.address, self.port)
except (socket.error, imaplib.IMAP4.error, ssl.SSLError) as error:
raise ImapError(_("Connection to IMAP server failed: %s" % error))
raise ImapError(_("Connection to IMAP server failed: %s" % error)) from None
token = (
b"n,a="
+1 -1
View File
@@ -33,7 +33,7 @@ class SieveClient:
try:
ret, msg = self.login(user, password)
except (managesieve.Error, ConnectionError) as e:
raise SieveClientError(str(e))
raise SieveClientError(str(e)) from None
if not ret:
raise SieveClientError(msg)
+6
View File
@@ -115,3 +115,9 @@ Issues = "https://github.com/modoboa/modoboa/issues"
[tool.setuptools.dynamic]
version = {attr = "modoboa.version.get_version"}
[tool.ruff]
exclude = ["migrations"]
[tool.ruff.lint]
select = ["E4", "E7", "E9", "F", "B", "Q"]