1
0
mirror of https://github.com/etesync/server synced 2024-11-18 23:08:08 +00:00

Fix rust complaints.

This commit is contained in:
Tom Hacohen 2024-06-08 17:56:36 -04:00
parent 79d28586c5
commit 0cdab19308
8 changed files with 20 additions and 26 deletions

View File

@ -1 +1,3 @@
from .app_settings_inner import app_settings from .app_settings_inner import app_settings
__all__ = ["app_settings"]

View File

@ -34,11 +34,11 @@ class AppSettings:
return getattr(settings, self.prefix + name, dflt) return getattr(settings, self.prefix + name, dflt)
@cached_property @cached_property
def REDIS_URI(self) -> t.Optional[str]: # pylint: disable=invalid-name def REDIS_URI(self) -> t.Optional[str]: # noqa: N802
return self._setting("REDIS_URI", None) return self._setting("REDIS_URI", None)
@cached_property @cached_property
def API_PERMISSIONS_READ(self): # pylint: disable=invalid-name def API_PERMISSIONS_READ(self): # noqa: N802
perms = self._setting("API_PERMISSIONS_READ", tuple()) perms = self._setting("API_PERMISSIONS_READ", tuple())
ret = [] ret = []
for perm in perms: for perm in perms:
@ -46,7 +46,7 @@ class AppSettings:
return ret return ret
@cached_property @cached_property
def API_PERMISSIONS_WRITE(self): # pylint: disable=invalid-name def API_PERMISSIONS_WRITE(self): # noqa: N802
perms = self._setting("API_PERMISSIONS_WRITE", tuple()) perms = self._setting("API_PERMISSIONS_WRITE", tuple())
ret = [] ret = []
for perm in perms: for perm in perms:
@ -54,35 +54,35 @@ class AppSettings:
return ret return ret
@cached_property @cached_property
def GET_USER_QUERYSET_FUNC(self): # pylint: disable=invalid-name def GET_USER_QUERYSET_FUNC(self): # noqa: N802
get_user_queryset = self._setting("GET_USER_QUERYSET_FUNC", None) get_user_queryset = self._setting("GET_USER_QUERYSET_FUNC", None)
if get_user_queryset is not None: if get_user_queryset is not None:
return self.import_from_str(get_user_queryset) return self.import_from_str(get_user_queryset)
return None return None
@cached_property @cached_property
def CREATE_USER_FUNC(self): # pylint: disable=invalid-name def CREATE_USER_FUNC(self): # noqa: N802
func = self._setting("CREATE_USER_FUNC", None) func = self._setting("CREATE_USER_FUNC", None)
if func is not None: if func is not None:
return self.import_from_str(func) return self.import_from_str(func)
return None return None
@cached_property @cached_property
def DASHBOARD_URL_FUNC(self): # pylint: disable=invalid-name def DASHBOARD_URL_FUNC(self): # noqa: N802
func = self._setting("DASHBOARD_URL_FUNC", None) func = self._setting("DASHBOARD_URL_FUNC", None)
if func is not None: if func is not None:
return self.import_from_str(func) return self.import_from_str(func)
return None return None
@cached_property @cached_property
def CHUNK_PATH_FUNC(self): # pylint: disable=invalid-name def CHUNK_PATH_FUNC(self): # noqa: N802
func = self._setting("CHUNK_PATH_FUNC", None) func = self._setting("CHUNK_PATH_FUNC", None)
if func is not None: if func is not None:
return self.import_from_str(func) return self.import_from_str(func)
return None return None
@cached_property @cached_property
def CHALLENGE_VALID_SECONDS(self): # pylint: disable=invalid-name def CHALLENGE_VALID_SECONDS(self): # noqa: N802
return self._setting("CHALLENGE_VALID_SECONDS", 60) return self._setting("CHALLENGE_VALID_SECONDS", 60)

View File

@ -18,7 +18,7 @@ from pathlib import Path
from django.conf import settings from django.conf import settings
from django.core.validators import RegexValidator from django.core.validators import RegexValidator
from django.db import models, transaction from django.db import models, transaction
from django.db.models import Max, Value as V from django.db.models import Max, Value as Val
from django.db.models.functions import Coalesce, Greatest from django.db.models.functions import Coalesce, Greatest
from django.utils.crypto import get_random_string from django.utils.crypto import get_random_string
from django.utils.functional import cached_property from django.utils.functional import cached_property
@ -29,7 +29,7 @@ UidValidator = RegexValidator(regex=r"^[a-zA-Z0-9\-_]{20,}$", message="Not a val
def stoken_annotation_builder(stoken_id_fields: t.List[str]): def stoken_annotation_builder(stoken_id_fields: t.List[str]):
aggr_fields = [Coalesce(Max(field), V(0)) for field in stoken_id_fields] aggr_fields = [Coalesce(Max(field), Val(0)) for field in stoken_id_fields]
return Greatest(*aggr_fields) if len(aggr_fields) > 1 else aggr_fields[0] return Greatest(*aggr_fields) if len(aggr_fields) > 1 else aggr_fields[0]

View File

@ -25,9 +25,9 @@ def create_application(prefix="", middlewares=[]):
}, },
# FIXME: version="2.5.0", # FIXME: version="2.5.0",
) )
VERSION = "v1" VERSION = "v1" # noqa: N806
BASE_PATH = f"{prefix}/api/{VERSION}" BASE_PATH = f"{prefix}/api/{VERSION}" # noqa: N806
COLLECTION_UID_MARKER = "{collection_uid}" COLLECTION_UID_MARKER = "{collection_uid}" # noqa: N806
app.include_router(authentication_router, prefix=f"{BASE_PATH}/authentication", tags=["authentication"]) app.include_router(authentication_router, prefix=f"{BASE_PATH}/authentication", tags=["authentication"])
app.include_router(collection_router, prefix=f"{BASE_PATH}/collection", tags=["collection"]) app.include_router(collection_router, prefix=f"{BASE_PATH}/collection", tags=["collection"])
app.include_router(item_router, prefix=f"{BASE_PATH}/collection/{COLLECTION_UID_MARKER}", tags=["item"]) app.include_router(item_router, prefix=f"{BASE_PATH}/collection/{COLLECTION_UID_MARKER}", tags=["item"])

View File

@ -374,7 +374,7 @@ def item_create(item_model: CollectionItemIn, collection: models.Collection, val
revision_data = item_model.content revision_data = item_model.content
uid = item_model.uid uid = item_model.uid
Model = models.CollectionItem Model = models.CollectionItem # noqa: N806
with transaction.atomic(): with transaction.atomic():
instance, created = Model.objects.get_or_create( instance, created = Model.objects.get_or_create(

View File

@ -1,21 +1,13 @@
import typing as t import typing as t
from django.contrib.auth.models import AbstractUser, UserManager as DjangoUserManager from django.contrib.auth.models import AbstractUser, UserManager as DjangoUserManager
from django.core import validators from django.contrib.auth.validators import UnicodeUsernameValidator
from django.db import models from django.db import models
from django.utils.deconstruct import deconstructible
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@deconstructible
class UnicodeUsernameValidator(validators.RegexValidator):
regex = r"^[\w.-]+\Z"
message = _("Enter a valid username. This value may contain only letters, " "numbers, and ./-/_ characters.")
flags = 0
class UserManager(DjangoUserManager): class UserManager(DjangoUserManager):
def get_by_natural_key(self, username: str): def get_by_natural_key(self, username: t.Optional[str]):
return self.get(**{self.model.USERNAME_FIELD + "__iexact": username}) return self.get(**{self.model.USERNAME_FIELD + "__iexact": username})

View File

@ -201,7 +201,7 @@ if "DJANGO_MEDIA_ROOT" in os.environ:
# Make an `etebase_server_settings` module available to override settings. # Make an `etebase_server_settings` module available to override settings.
try: try:
from etebase_server_settings import * from etebase_server_settings import * # noqa: F403
except ImportError: except ImportError:
pass pass

View File

@ -22,7 +22,7 @@ exclude = [
[tool.ruff.lint] [tool.ruff.lint]
select = ["E", "F", "I", "N", "T20", "W"] select = ["E", "F", "I", "N", "T20", "W"]
ignore = ["E203", "E501", "E711", "E712", "N803", "N818", "T201"] ignore = ["E203", "E501", "E711", "E712", "N803", "N815", "N818", "T201"]
[tool.ruff.lint.isort] [tool.ruff.lint.isort]
combine-as-imports = true combine-as-imports = true