mirror of
https://github.com/etesync/server
synced 2025-04-03 10:05:42 +00:00
Run ruff format.
This commit is contained in:
parent
df0d1596e2
commit
79d28586c5
@ -15,17 +15,16 @@
|
||||
import typing as t
|
||||
from pathlib import Path
|
||||
|
||||
from django.db import models, transaction
|
||||
from django.conf import settings
|
||||
from django.core.validators import RegexValidator
|
||||
from django.db import models, transaction
|
||||
from django.db.models import Max, Value as V
|
||||
from django.db.models.functions import Coalesce, Greatest
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.crypto import get_random_string
|
||||
from django.utils.functional import cached_property
|
||||
|
||||
from . import app_settings
|
||||
|
||||
|
||||
UidValidator = RegexValidator(regex=r"^[a-zA-Z0-9\-_]{20,}$", message="Not a valid UID")
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.crypto import get_random_string
|
||||
|
||||
from etebase_server.myauth.models import get_typed_user_model
|
||||
|
||||
User = get_typed_user_model()
|
||||
@ -15,7 +16,6 @@ def get_default_expiry():
|
||||
|
||||
|
||||
class AuthToken(models.Model):
|
||||
|
||||
key = models.CharField(max_length=40, unique=True, db_index=True, default=generate_key)
|
||||
user = models.ForeignKey(User, null=False, blank=False, related_name="auth_token_set", on_delete=models.CASCADE)
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
|
@ -1,13 +1,13 @@
|
||||
import typing as t
|
||||
from dataclasses import dataclass
|
||||
|
||||
from django.db.models import QuerySet
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db.models import QuerySet
|
||||
|
||||
from etebase_server.myauth.models import UserType, get_typed_user_model
|
||||
|
||||
from . import app_settings
|
||||
|
||||
|
||||
User = get_typed_user_model()
|
||||
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
FIXME: this whole function is a hack around the django db limitations due to how db connections are cached and cleaned.
|
||||
Essentially django assumes there's the django request dispatcher to automatically clean up after the ORM.
|
||||
"""
|
||||
|
||||
import typing as t
|
||||
from functools import wraps
|
||||
|
||||
|
@ -1,18 +1,17 @@
|
||||
import dataclasses
|
||||
|
||||
from django.db.models import QuerySet
|
||||
from django.utils import timezone
|
||||
from fastapi import Depends
|
||||
from fastapi.security import APIKeyHeader
|
||||
|
||||
from django.utils import timezone
|
||||
from django.db.models import QuerySet
|
||||
|
||||
from etebase_server.django import models
|
||||
from etebase_server.django.token_auth.models import AuthToken, get_default_expiry
|
||||
from etebase_server.myauth.models import UserType, get_typed_user_model
|
||||
|
||||
from .db_hack import django_db_cleanup_decorator
|
||||
from .exceptions import AuthenticationFailed
|
||||
from .utils import get_object_or_404
|
||||
from .db_hack import django_db_cleanup_decorator
|
||||
|
||||
|
||||
User = get_typed_user_model()
|
||||
token_scheme = APIKeyHeader(name="Authorization")
|
||||
|
@ -1,8 +1,8 @@
|
||||
from fastapi import status, HTTPException
|
||||
import typing as t
|
||||
|
||||
from pydantic import BaseModel
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from fastapi import HTTPException, status
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class HttpErrorField(BaseModel):
|
||||
|
@ -6,14 +6,12 @@ from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.middleware.trustedhost import TrustedHostMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from etebase_server.django import app_settings
|
||||
|
||||
from .exceptions import CustomHttpException
|
||||
from .msgpack import MsgpackResponse
|
||||
from .routers.authentication import authentication_router
|
||||
from .routers.collection import collection_router, item_router
|
||||
from .routers.member import member_router
|
||||
from .routers.invitation import invitation_incoming_router, invitation_outgoing_router
|
||||
from .routers.member import member_router
|
||||
from .routers.websocket import websocket_router
|
||||
|
||||
|
||||
@ -24,7 +22,7 @@ def create_application(prefix="", middlewares=[]):
|
||||
externalDocs={
|
||||
"url": "https://docs.etebase.com",
|
||||
"description": "Docs about the API specifications and clients.",
|
||||
}
|
||||
},
|
||||
# FIXME: version="2.5.0",
|
||||
)
|
||||
VERSION = "v1"
|
||||
|
@ -5,8 +5,8 @@ from pydantic import BaseModel
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import Response
|
||||
|
||||
from .utils import msgpack_encode, msgpack_decode
|
||||
from .db_hack import django_db_cleanup_decorator
|
||||
from .utils import msgpack_decode, msgpack_encode
|
||||
|
||||
|
||||
class MsgpackRequest(Request):
|
||||
@ -60,7 +60,6 @@ class MsgpackRoute(APIRoute):
|
||||
|
||||
def get_route_handler(self) -> t.Callable:
|
||||
async def custom_route_handler(request: Request) -> Response:
|
||||
|
||||
content_type = request.headers.get("Content-Type")
|
||||
try:
|
||||
request_cls = self.REQUESTS_CLASSES[content_type]
|
||||
|
@ -1,4 +1,5 @@
|
||||
import typing as t
|
||||
|
||||
from redis import asyncio as aioredis
|
||||
|
||||
from etebase_server.django import app_settings
|
||||
|
@ -1,5 +1,4 @@
|
||||
import typing as t
|
||||
from typing_extensions import Literal
|
||||
from datetime import datetime
|
||||
|
||||
import nacl
|
||||
@ -8,22 +7,24 @@ import nacl.hash
|
||||
import nacl.secret
|
||||
import nacl.signing
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import user_logged_out, user_logged_in
|
||||
from django.contrib.auth import user_logged_in, user_logged_out
|
||||
from django.core import exceptions as django_exceptions
|
||||
from django.db import transaction
|
||||
from django.utils.functional import cached_property
|
||||
from fastapi import APIRouter, Depends, status, Request
|
||||
from fastapi import APIRouter, Depends, Request, status
|
||||
from typing_extensions import Literal
|
||||
|
||||
from etebase_server.django import app_settings, models
|
||||
from etebase_server.django.token_auth.models import AuthToken
|
||||
from etebase_server.django.models import UserInfo
|
||||
from etebase_server.django.signals import user_signed_up
|
||||
from etebase_server.django.utils import create_user, get_user_queryset, CallbackContext
|
||||
from etebase_server.django.token_auth.models import AuthToken
|
||||
from etebase_server.django.utils import CallbackContext, create_user, get_user_queryset
|
||||
from etebase_server.myauth.models import UserType, get_typed_user_model
|
||||
from ..exceptions import AuthenticationFailed, transform_validation_error, HttpError
|
||||
from ..msgpack import MsgpackRoute
|
||||
from ..utils import BaseModel, permission_responses, msgpack_encode, msgpack_decode, get_user_username_email_kwargs
|
||||
|
||||
from ..dependencies import AuthData, get_auth_data, get_authenticated_user
|
||||
from ..exceptions import AuthenticationFailed, HttpError, transform_validation_error
|
||||
from ..msgpack import MsgpackRoute
|
||||
from ..utils import BaseModel, get_user_username_email_kwargs, msgpack_decode, msgpack_encode, permission_responses
|
||||
|
||||
User = get_typed_user_model()
|
||||
authentication_router = APIRouter(route_class=MsgpackRoute)
|
||||
|
@ -3,33 +3,34 @@ import typing as t
|
||||
from asgiref.sync import sync_to_async
|
||||
from django.core import exceptions as django_exceptions
|
||||
from django.core.files.base import ContentFile
|
||||
from django.db import transaction, IntegrityError
|
||||
from django.db import IntegrityError, transaction
|
||||
from django.db.models import Q, QuerySet
|
||||
from fastapi import APIRouter, Depends, status, Request, BackgroundTasks
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends, Request, status
|
||||
|
||||
from etebase_server.django import models
|
||||
from etebase_server.myauth.models import UserType
|
||||
from .authentication import get_authenticated_user
|
||||
from .websocket import get_ticket, TicketRequest, TicketOut
|
||||
from ..exceptions import HttpError, transform_validation_error, PermissionDenied, ValidationError
|
||||
|
||||
from ..db_hack import django_db_cleanup_decorator
|
||||
from ..dependencies import get_collection, get_collection_queryset, get_item_queryset
|
||||
from ..exceptions import HttpError, PermissionDenied, ValidationError, transform_validation_error
|
||||
from ..msgpack import MsgpackRoute
|
||||
from ..stoken_handler import filter_by_stoken_and_limit, filter_by_stoken, get_stoken_obj, get_queryset_stoken
|
||||
from ..redis import redisw
|
||||
from ..sendfile import sendfile
|
||||
from ..stoken_handler import filter_by_stoken, filter_by_stoken_and_limit, get_queryset_stoken, get_stoken_obj
|
||||
from ..utils import (
|
||||
get_object_or_404,
|
||||
PERMISSIONS_READ,
|
||||
PERMISSIONS_READWRITE,
|
||||
BaseModel,
|
||||
Context,
|
||||
Prefetch,
|
||||
PrefetchQuery,
|
||||
get_object_or_404,
|
||||
is_collection_admin,
|
||||
msgpack_encode,
|
||||
BaseModel,
|
||||
permission_responses,
|
||||
PERMISSIONS_READ,
|
||||
PERMISSIONS_READWRITE,
|
||||
)
|
||||
from ..dependencies import get_collection_queryset, get_item_queryset, get_collection
|
||||
from ..sendfile import sendfile
|
||||
from ..redis import redisw
|
||||
from ..db_hack import django_db_cleanup_decorator
|
||||
from .authentication import get_authenticated_user
|
||||
from .websocket import TicketOut, TicketRequest, get_ticket
|
||||
|
||||
collection_router = APIRouter(route_class=MsgpackRoute, responses=permission_responses)
|
||||
item_router = APIRouter(route_class=MsgpackRoute, responses=permission_responses)
|
||||
|
@ -1,26 +1,27 @@
|
||||
import typing as t
|
||||
|
||||
from django.db import transaction, IntegrityError
|
||||
from django.db import IntegrityError, transaction
|
||||
from django.db.models import QuerySet
|
||||
from fastapi import APIRouter, Depends, status, Request
|
||||
from fastapi import APIRouter, Depends, Request, status
|
||||
|
||||
from etebase_server.django import models
|
||||
from etebase_server.django.utils import get_user_queryset, CallbackContext
|
||||
from etebase_server.django.utils import CallbackContext, get_user_queryset
|
||||
from etebase_server.myauth.models import UserType, get_typed_user_model
|
||||
from .authentication import get_authenticated_user
|
||||
|
||||
from ..db_hack import django_db_cleanup_decorator
|
||||
from ..exceptions import HttpError, PermissionDenied
|
||||
from ..msgpack import MsgpackRoute
|
||||
from ..utils import (
|
||||
get_object_or_404,
|
||||
get_user_username_email_kwargs,
|
||||
Context,
|
||||
is_collection_admin,
|
||||
BaseModel,
|
||||
permission_responses,
|
||||
PERMISSIONS_READ,
|
||||
PERMISSIONS_READWRITE,
|
||||
BaseModel,
|
||||
Context,
|
||||
get_object_or_404,
|
||||
get_user_username_email_kwargs,
|
||||
is_collection_admin,
|
||||
permission_responses,
|
||||
)
|
||||
from ..db_hack import django_db_cleanup_decorator
|
||||
from .authentication import get_authenticated_user
|
||||
|
||||
User = get_typed_user_model()
|
||||
invitation_incoming_router = APIRouter(route_class=MsgpackRoute, responses=permission_responses)
|
||||
|
@ -6,12 +6,12 @@ from fastapi import APIRouter, Depends, status
|
||||
|
||||
from etebase_server.django import models
|
||||
from etebase_server.myauth.models import UserType, get_typed_user_model
|
||||
from .authentication import get_authenticated_user
|
||||
from ..msgpack import MsgpackRoute
|
||||
from ..utils import get_object_or_404, BaseModel, permission_responses, PERMISSIONS_READ, PERMISSIONS_READWRITE
|
||||
from ..stoken_handler import filter_by_stoken_and_limit
|
||||
from ..db_hack import django_db_cleanup_decorator
|
||||
|
||||
from ..db_hack import django_db_cleanup_decorator
|
||||
from ..msgpack import MsgpackRoute
|
||||
from ..stoken_handler import filter_by_stoken_and_limit
|
||||
from ..utils import PERMISSIONS_READ, PERMISSIONS_READWRITE, BaseModel, get_object_or_404, permission_responses
|
||||
from .authentication import get_authenticated_user
|
||||
from .collection import get_collection, verify_collection_admin
|
||||
|
||||
User = get_typed_user_model()
|
||||
|
@ -3,12 +3,13 @@ from django.db import transaction
|
||||
from django.shortcuts import get_object_or_404
|
||||
from fastapi import APIRouter, Request, status
|
||||
|
||||
from etebase_server.django.utils import get_user_queryset, CallbackContext
|
||||
from .authentication import SignupIn, signup_save
|
||||
from ..msgpack import MsgpackRoute
|
||||
from ..exceptions import HttpError
|
||||
from etebase_server.django.utils import CallbackContext, get_user_queryset
|
||||
from etebase_server.myauth.models import get_typed_user_model
|
||||
|
||||
from ..exceptions import HttpError
|
||||
from ..msgpack import MsgpackRoute
|
||||
from .authentication import SignupIn, signup_save
|
||||
|
||||
test_reset_view_router = APIRouter(route_class=MsgpackRoute, tags=["test helpers"])
|
||||
User = get_typed_user_model()
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
import asyncio
|
||||
import typing as t
|
||||
|
||||
from redis import asyncio as aioredis
|
||||
from redis.exceptions import ConnectionError
|
||||
import nacl.encoding
|
||||
import nacl.utils
|
||||
from asgiref.sync import sync_to_async
|
||||
from django.db.models import QuerySet
|
||||
from fastapi import APIRouter, Depends, WebSocket, WebSocketDisconnect, status
|
||||
import nacl.encoding
|
||||
import nacl.utils
|
||||
from redis import asyncio as aioredis
|
||||
from redis.exceptions import ConnectionError
|
||||
|
||||
from etebase_server.django import models
|
||||
from etebase_server.django.utils import CallbackContext, get_user_queryset
|
||||
@ -19,7 +19,6 @@ from ..msgpack import MsgpackRoute, msgpack_decode, msgpack_encode
|
||||
from ..redis import redisw
|
||||
from ..utils import BaseModel, permission_responses
|
||||
|
||||
|
||||
User = get_typed_user_model()
|
||||
websocket_router = APIRouter(route_class=MsgpackRoute, responses=permission_responses)
|
||||
CollectionQuerySet = QuerySet[models.Collection]
|
||||
|
@ -1,14 +1,14 @@
|
||||
import logging
|
||||
from functools import lru_cache
|
||||
from importlib import import_module
|
||||
from pathlib import Path, PurePath
|
||||
from urllib.parse import quote
|
||||
import logging
|
||||
|
||||
from fastapi import status
|
||||
from ..exceptions import HttpError
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from fastapi import status
|
||||
|
||||
from ..exceptions import HttpError
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -47,7 +47,6 @@ def get_queryset_stoken(queryset: t.Iterable[t.Any]) -> t.Optional[Stoken]:
|
||||
def filter_by_stoken_and_limit(
|
||||
stoken: t.Optional[str], limit: int, queryset: QuerySet, stoken_annotation: StokenAnnotation
|
||||
) -> t.Tuple[list, t.Optional[Stoken], bool]:
|
||||
|
||||
queryset, stoken_rev = filter_by_stoken(stoken=stoken, queryset=queryset, stoken_annotation=stoken_annotation)
|
||||
|
||||
result = list(queryset[: limit + 1])
|
||||
|
@ -1,14 +1,13 @@
|
||||
import base64
|
||||
import dataclasses
|
||||
import typing as t
|
||||
from typing_extensions import Literal
|
||||
|
||||
import msgpack
|
||||
import base64
|
||||
|
||||
from fastapi import status, Query, Depends
|
||||
from pydantic import BaseModel as PyBaseModel
|
||||
|
||||
from django.db.models import Model, QuerySet
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db.models import Model, QuerySet
|
||||
from fastapi import Depends, Query, status
|
||||
from pydantic import BaseModel as PyBaseModel
|
||||
from typing_extensions import Literal
|
||||
|
||||
from etebase_server.django import app_settings
|
||||
from etebase_server.django.models import AccessLevels
|
||||
|
@ -1,12 +1,21 @@
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin as DjangoUserAdmin
|
||||
from .models import User
|
||||
|
||||
from .forms import AdminUserCreationForm
|
||||
from .models import User
|
||||
|
||||
|
||||
class UserAdmin(DjangoUserAdmin):
|
||||
add_form = AdminUserCreationForm
|
||||
add_fieldsets = ((None, {"classes": ("wide",), "fields": ("username",),}),)
|
||||
add_fieldsets = (
|
||||
(
|
||||
None,
|
||||
{
|
||||
"classes": ("wide",),
|
||||
"fields": ("username",),
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
admin.site.register(User, UserAdmin)
|
||||
|
@ -1,5 +1,6 @@
|
||||
from django import forms
|
||||
from django.contrib.auth.forms import UsernameField
|
||||
|
||||
from etebase_server.myauth.models import get_typed_user_model
|
||||
|
||||
User = get_typed_user_model()
|
||||
|
@ -1,15 +1,15 @@
|
||||
import logging
|
||||
|
||||
from django.utils import timezone
|
||||
import ldap
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import PermissionDenied as DjangoPermissionDenied
|
||||
from etebase_server.django.utils import CallbackContext
|
||||
from etebase_server.myauth.models import get_typed_user_model, UserType
|
||||
from etebase_server.fastapi.dependencies import get_authenticated_user
|
||||
from etebase_server.fastapi.exceptions import PermissionDenied as FastAPIPermissionDenied
|
||||
from django.utils import timezone
|
||||
from fastapi import Depends
|
||||
|
||||
import ldap
|
||||
from etebase_server.django.utils import CallbackContext
|
||||
from etebase_server.fastapi.dependencies import get_authenticated_user
|
||||
from etebase_server.fastapi.exceptions import PermissionDenied as FastAPIPermissionDenied
|
||||
from etebase_server.myauth.models import UserType, get_typed_user_model
|
||||
|
||||
User = get_typed_user_model()
|
||||
|
||||
|
@ -1,3 +1 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
|
@ -1,3 +1 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
|
@ -10,8 +10,9 @@ For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/3.0/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
import configparser
|
||||
import os
|
||||
|
||||
from .utils import get_secret_from_file
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
@ -44,7 +45,7 @@ DATABASES = {
|
||||
}
|
||||
}
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
||||
|
||||
# Application definition
|
||||
|
||||
|
@ -1,11 +1,6 @@
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from django.views.generic import TemplateView
|
||||
from django.views.static import serve
|
||||
from django.contrib.staticfiles import finders
|
||||
|
||||
urlpatterns = [
|
||||
path("admin/", admin.site.urls),
|
||||
|
@ -12,10 +12,11 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.core.management import utils
|
||||
import os
|
||||
import stat
|
||||
|
||||
from django.core.management import utils
|
||||
|
||||
|
||||
def get_secret_from_file(path):
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user