mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
New fixes
This commit is contained in:
@@ -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])
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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", ""),
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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="
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user