🚨(linter) add missing docstrings

Title says all there is to say…
This commit is contained in:
Laurent Bossavit
2024-10-25 14:59:02 +02:00
committed by Laurent Bossavit
parent 3934a0bc28
commit 1d1f5cfbb6
32 changed files with 38 additions and 4 deletions

View File

@@ -0,0 +1 @@
"""Root module."""

View File

@@ -0,0 +1 @@
"""Core root module."""

View File

@@ -148,8 +148,8 @@ class InvitationAdmin(admin.ModelAdmin):
) )
def get_readonly_fields(self, request, obj=None): def get_readonly_fields(self, request, obj=None):
"""Mark all fields read only, i.e. disable update."""
if obj: if obj:
# all fields read only = disable update
return self.fields return self.fields
return self.readonly_fields return self.readonly_fields
@@ -162,5 +162,6 @@ class InvitationAdmin(admin.ModelAdmin):
return super().change_view(request, object_id, extra_context=extra_context) return super().change_view(request, object_id, extra_context=extra_context)
def save_model(self, request, obj, form, change): def save_model(self, request, obj, form, change):
"""Fill in current logged-in user as issuer."""
obj.issuer = request.user obj.issuer = request.user
obj.save() obj.save()

View File

@@ -12,13 +12,13 @@ class IsAuthenticated(permissions.BasePermission):
""" """
def has_permission(self, request, view): def has_permission(self, request, view):
"""Check auth token first."""
return bool(request.auth) if request.auth else request.user.is_authenticated return bool(request.auth) if request.auth else request.user.is_authenticated
class IsSelf(IsAuthenticated): class IsSelf(IsAuthenticated):
""" """
Allows access only to authenticated users. Alternative method checking the presence Allows access only to user's own data.
of the auth token to avoid hitting the database.
""" """
def has_object_permission(self, request, view, obj): def has_object_permission(self, request, view, obj):

View File

@@ -34,6 +34,8 @@ class DynamicFieldsModelSerializer(serializers.ModelSerializer):
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
"""Pass arguments to superclass except 'fields', then drop fields not listed therein."""
# Don't pass the 'fields' arg up to the superclass # Don't pass the 'fields' arg up to the superclass
fields = kwargs.pop("fields", None) fields = kwargs.pop("fields", None)

View File

@@ -340,6 +340,7 @@ class TeamAccessViewSet(
return context return context
def get_serializer_class(self): def get_serializer_class(self):
"""Chooses list or detail serializer according to the action."""
if self.action in {"list", "retrieve"}: if self.action in {"list", "retrieve"}:
return self.list_serializer_class return self.list_serializer_class
return self.detail_serializer_class return self.detail_serializer_class

View File

@@ -0,0 +1 @@
"""Authentication module."""

View File

@@ -0,0 +1 @@
"""Backend resource server module."""

View File

@@ -19,6 +19,7 @@ class ResourceServerAuthentication(OIDCAuthentication):
"""Authenticate clients using the token received from the authorization server.""" """Authenticate clients using the token received from the authorization server."""
def __init__(self): def __init__(self):
"""Require authentication to be configured in order to instantiate."""
super().__init__() super().__init__()
try: try:
@@ -40,7 +41,7 @@ class ResourceServerAuthentication(OIDCAuthentication):
def get_access_token(self, request): def get_access_token(self, request):
"""Retrieve and decode the access token from the request. """Retrieve and decode the access token from the request.
This method overcharges the 'get_access_token' method from the parent class, This method overrides the 'get_access_token' method from the parent class,
to support service providers that would base64 encode the bearer token. to support service providers that would base64 encode the bearer token.
""" """

View File

@@ -33,6 +33,7 @@ class ResourceServerBackend:
# pylint: disable=too-many-instance-attributes # pylint: disable=too-many-instance-attributes
def __init__(self, authorization_server_client): def __init__(self, authorization_server_client):
"""Require client_id, client_secret set and authorization_server_client provided."""
# pylint: disable=invalid-name # pylint: disable=invalid-name
self.UserModel = auth.get_user_model() self.UserModel = auth.get_user_model()

View File

@@ -31,6 +31,8 @@ class AuthorizationServerClient:
timeout, timeout,
proxy, proxy,
): ):
"""Require at a minimum url, url_jwks and url_introspection."""
if not url or not url_jwks or not url_introspection: if not url or not url_jwks or not url_introspection:
raise ImproperlyConfigured( raise ImproperlyConfigured(
"Could not instantiate AuthorizationServerClient, some parameters are missing." "Could not instantiate AuthorizationServerClient, some parameters are missing."

View File

@@ -0,0 +1 @@
"""Core template tags module."""

View File

@@ -0,0 +1 @@
"""Core tests."""

View File

@@ -0,0 +1 @@
"""Core authentication tests."""

View File

@@ -0,0 +1 @@
"""Core resource server tests."""

View File

@@ -0,0 +1 @@
"""Core Swagger tests."""

View File

@@ -0,0 +1 @@
"""Core utils module."""

View File

@@ -33,6 +33,7 @@ class DebugViewNewMailboxHtml(DebugBaseView):
template_name = "mail/html/new_mailbox.html" template_name = "mail/html/new_mailbox.html"
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
"""Hardcode user credentials for debug setting."""
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context["mailbox_data"] = { context["mailbox_data"] = {
"email": "john.doe@example.com", "email": "john.doe@example.com",

View File

@@ -0,0 +1 @@
"""Demo module."""

View File

@@ -0,0 +1 @@
"""Demo management module."""

View File

@@ -0,0 +1 @@
"Demo management commands module."

View File

@@ -0,0 +1 @@
"""Demo tests."""

View File

@@ -0,0 +1 @@
"""Mailbox manager module."""

View File

@@ -0,0 +1 @@
"""Mailbox manager API module."""

View File

@@ -18,6 +18,7 @@ class MailBoxPermission(core_permissions.IsAuthenticated):
"""Permission class to manage mailboxes for a mail domain""" """Permission class to manage mailboxes for a mail domain"""
def has_permission(self, request, view): def has_permission(self, request, view):
"""Check permission based on domain."""
domain = models.MailDomain.objects.get(slug=view.kwargs.get("domain_slug", "")) domain = models.MailDomain.objects.get(slug=view.kwargs.get("domain_slug", ""))
abilities = domain.get_abilities(request.user) abilities = domain.get_abilities(request.user)
return abilities.get(request.method.lower(), False) return abilities.get(request.method.lower(), False)

View File

@@ -40,6 +40,7 @@ class MailDomainViewSet(
queryset = models.MailDomain.objects.all() queryset = models.MailDomain.objects.all()
def get_queryset(self): def get_queryset(self):
"""Restrict results to the current user's team."""
return self.queryset.filter(accesses__user=self.request.user) return self.queryset.filter(accesses__user=self.request.user)
def perform_create(self, serializer): def perform_create(self, serializer):
@@ -100,6 +101,7 @@ class MailDomainAccessViewSet(
detail_serializer_class = serializers.MailDomainAccessSerializer detail_serializer_class = serializers.MailDomainAccessSerializer
def get_serializer_class(self): def get_serializer_class(self):
"""Chooses list or detail serializer according to the action."""
if self.action in {"list", "retrieve"}: if self.action in {"list", "retrieve"}:
return self.list_serializer_class return self.list_serializer_class
return self.detail_serializer_class return self.detail_serializer_class

View File

@@ -0,0 +1 @@
"Mailbox manager management module."

View File

@@ -0,0 +1 @@
"""Mailbox manager management commands module."""

View File

@@ -0,0 +1 @@
"""Mailbox manager tests."""

View File

@@ -0,0 +1 @@
"""Mailbox manager utils."""

View File

@@ -0,0 +1 @@
"""People module."""

View File

@@ -555,6 +555,7 @@ class Development(Base):
) )
def __init__(self): def __init__(self):
"""In dev, force installs needed for Swagger API."""
# pylint: disable=invalid-name # pylint: disable=invalid-name
self.INSTALLED_APPS += ["django_extensions", "drf_spectacular_sidecar"] self.INSTALLED_APPS += ["django_extensions", "drf_spectacular_sidecar"]