diff --git a/examples/check_permissions.py b/examples/check_permissions.py index 1b50250..541e418 100644 --- a/examples/check_permissions.py +++ b/examples/check_permissions.py @@ -1,5 +1,4 @@ import grainy.const - from django_grainy.util import Permissions user.grainy_permissions.add_permission_set({"a.b.c": "r"}) diff --git a/examples/custom_permission_holder.py b/examples/custom_permission_holder.py index 957bb0e..c235725 100644 --- a/examples/custom_permission_holder.py +++ b/examples/custom_permission_holder.py @@ -1,5 +1,4 @@ from django.db import models - from django_grainy.models import Permission, PermissionManager from django_grainy.util import Permissions diff --git a/examples/grainy_rest_viewset.py b/examples/grainy_rest_viewset.py index 03d5471..c08e42e 100644 --- a/examples/grainy_rest_viewset.py +++ b/examples/grainy_rest_viewset.py @@ -1,6 +1,5 @@ -from rest_framework import serializers - from django_grainy.decorators import grainy_rest_viewset +from rest_framework import serializers from .models import TestModelA diff --git a/examples/grainy_view.py b/examples/grainy_view.py index c8c1ac5..1d447e1 100644 --- a/examples/grainy_view.py +++ b/examples/grainy_view.py @@ -1,5 +1,4 @@ from django.views import View as BaseView - from django_grainy.decorators import grainy_view diff --git a/examples/grainy_view_manual_a.py b/examples/grainy_view_manual_a.py index 5a2bf47..3a96ddb 100644 --- a/examples/grainy_view_manual_a.py +++ b/examples/grainy_view_manual_a.py @@ -1,5 +1,4 @@ from django.views import BaseView - from django_grainy.decorators import grainy_view diff --git a/examples/grainy_view_manual_b.py b/examples/grainy_view_manual_b.py index 289d3a4..7293c8b 100644 --- a/examples/grainy_view_manual_b.py +++ b/examples/grainy_view_manual_b.py @@ -1,5 +1,4 @@ from django.views import BaseView - from django_grainy.decorators import grainy_view_response diff --git a/examples/grainy_view_manual_c.py b/examples/grainy_view_manual_c.py index a772fba..77ed90f 100644 --- a/examples/grainy_view_manual_c.py +++ b/examples/grainy_view_manual_c.py @@ -1,5 +1,4 @@ from django.views import BaseView - from django_grainy.decorators import grainy_view, grainy_view_response diff --git a/pyproject.toml b/pyproject.toml index 5f76ff4..c3b5106 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,6 +48,11 @@ dev = [ # .ruff.toml [tool.ruff] ignore = ["F821"] +select = [ + "I", # isort + "UP", # pyupgrade +] + [tool.hatch.metadata] allow-direct-references = true diff --git a/src/django_grainy/backends.py b/src/django_grainy/backends.py index 0ec986b..965b592 100644 --- a/src/django_grainy/backends.py +++ b/src/django_grainy/backends.py @@ -16,7 +16,6 @@ class GrainyBackend(ModelBackend): """ def has_module_perms(self, user: User, obj: str = None) -> bool: - # superusers have access to everything if user.is_superuser: return True @@ -24,7 +23,6 @@ def has_module_perms(self, user: User, obj: str = None) -> bool: return Permissions(user).check(obj, django_op_to_flag("view")) def has_perm(self, user: User, perm: str, obj: Optional[Any] = None) -> bool: - # superusers have access to everything if user.is_superuser: return True diff --git a/src/django_grainy/decorators.py b/src/django_grainy/decorators.py index 0bfe7dd..f7e57f5 100644 --- a/src/django_grainy/decorators.py +++ b/src/django_grainy/decorators.py @@ -6,7 +6,6 @@ from django.core.serializers.json import DjangoJSONEncoder from django.db.models import Model from django.http import HttpRequest, HttpResponse, JsonResponse -from django.http.response import HttpResponse, JsonResponse from django.views import View from grainy.core import Namespace from rest_framework.request import Request @@ -153,7 +152,6 @@ class grainy_view_response(grainy_decorator): view = None def __call__(self, view_function: Callable) -> Callable: - get_object = self.get_object apply_perms = self.apply_perms extra = self.extra @@ -364,7 +362,6 @@ def augment_request(self, request: Request) -> Request: perms = decorator.permissions_cls(request.user) def grainy_data(request: Request, defaults: dict): - """ Returns a cleaned up dict for request.data @@ -436,7 +433,6 @@ def __init__(self, *args: Any, **kwargs: Any): super().__init__(*args, **kwargs) def __call__(self, view: View): - view.Grainy = self.make_grainy_handler(view) if inspect.isclass(view): diff --git a/src/django_grainy/helpers.py b/src/django_grainy/helpers.py index 9dd1693..af47d91 100644 --- a/src/django_grainy/helpers.py +++ b/src/django_grainy/helpers.py @@ -1,7 +1,6 @@ import inspect from typing import Any, Union -from django.core.handlers.wsgi import WSGIRequest from grainy.core import Namespace from rest_framework.request import Request @@ -9,7 +8,6 @@ def namespace(target: Any, **kwargs: Any) -> str: - """ Convert `target` to permissioning namespace diff --git a/src/django_grainy/remote.py b/src/django_grainy/remote.py index 33072fb..c22f603 100644 --- a/src/django_grainy/remote.py +++ b/src/django_grainy/remote.py @@ -153,7 +153,6 @@ def __init__( self.cache = cache def fetch(self, url: str, cache_key: str, **params: Any) -> dict: - """ Retrieve grainy permissions from remote endpoint diff --git a/src/django_grainy/util.py b/src/django_grainy/util.py index 7188c96..3ad4655 100644 --- a/src/django_grainy/util.py +++ b/src/django_grainy/util.py @@ -1,9 +1,8 @@ -from typing import Any, List, Union +from typing import Any, Union from django.contrib.auth import get_user_model from django.contrib.auth.models import AnonymousUser, Group, User from django.db.models import Model, QuerySet -from django.db.models.base import ModelBase from grainy.core import Applicator, PermissionSet from .conf import ANONYMOUS_GROUP, ANONYMOUS_PERMS @@ -14,7 +13,7 @@ def check_permissions( obj: Union[User, AnonymousUser, Group, Model], target: Any, permissions: Union[int, str], - **kwargs: Any + **kwargs: Any, ): if not hasattr(obj, "_permissions_util"): obj._permissions_util = Permissions(obj) diff --git a/src/django_grainy_test/migrations/0001_initial.py b/src/django_grainy_test/migrations/0001_initial.py index b537bc2..1aca25a 100644 --- a/src/django_grainy_test/migrations/0001_initial.py +++ b/src/django_grainy_test/migrations/0001_initial.py @@ -2,10 +2,9 @@ import django.db.models.deletion -from django.db import migrations, models - import django_grainy.fields import django_grainy.models +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/django_grainy_test/models.py b/src/django_grainy_test/models.py index 98ab0c6..8fb22cb 100644 --- a/src/django_grainy_test/models.py +++ b/src/django_grainy_test/models.py @@ -1,5 +1,4 @@ from django.db import models - from django_grainy.decorators import grainy_model from django_grainy.handlers import GrainyMixin from django_grainy.models import Permission, PermissionManager diff --git a/src/django_grainy_test/views.py b/src/django_grainy_test/views.py index bfe6873..cd6e580 100644 --- a/src/django_grainy_test/views.py +++ b/src/django_grainy_test/views.py @@ -1,8 +1,6 @@ from django.http import HttpResponse, JsonResponse from django.utils.safestring import mark_safe from django.views import View as BaseView -from rest_framework import viewsets - from django_grainy.decorators import ( grainy_json_view, grainy_rest_viewset, @@ -10,6 +8,7 @@ grainy_view, grainy_view_response, ) +from rest_framework import viewsets from .models import ModelA from .serializers import ModelASerializer diff --git a/tests/test_backend.py b/tests/test_backend.py index 4349a42..681b5d3 100644 --- a/tests/test_backend.py +++ b/tests/test_backend.py @@ -1,8 +1,7 @@ +from django_grainy.backends import GrainyBackend from grainy.const import PERM_READ, PERM_UPDATE from grainy.core import PermissionSet -from django_grainy.backends import GrainyBackend - from .util import UserTestCase diff --git a/tests/test_fields.py b/tests/test_fields.py index a06eb24..a7fb217 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1,7 +1,6 @@ -from grainy.const import PERM_CREATE, PERM_DELETE, PERM_READ, PERM_UPDATE - from django_grainy.fields import PermissionFormField from django_grainy.models import UserPermission +from grainy.const import PERM_CREATE, PERM_DELETE, PERM_READ, PERM_UPDATE from .util import UserTestCase diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 6c99fcd..10b7f7b 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1,9 +1,6 @@ from unittest import TestCase from django.test import RequestFactory -from grainy.const import PERM_CREATE, PERM_DELETE, PERM_READ, PERM_UPDATE -from grainy.core import Namespace - from django_grainy.helpers import ( dict_get_namespace, int_flags, @@ -12,6 +9,8 @@ str_flags, ) from django_grainy_test.models import ModelA, ModelD +from grainy.const import PERM_CREATE, PERM_DELETE, PERM_READ, PERM_UPDATE +from grainy.core import Namespace class TestHelpers(TestCase): diff --git a/tests/test_manager.py b/tests/test_manager.py index 68f1976..d51d1b1 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -1,7 +1,6 @@ -from grainy.const import PERM_CREATE, PERM_DELETE, PERM_READ, PERM_UPDATE - from django_grainy.models import PermissionSet from django_grainy_test.models import ModelA, ModelB +from grainy.const import PERM_CREATE, PERM_DELETE, PERM_READ, PERM_UPDATE from .util import UserTestCase diff --git a/tests/test_permissions.py b/tests/test_permissions.py index 5d52189..819efbc 100644 --- a/tests/test_permissions.py +++ b/tests/test_permissions.py @@ -2,12 +2,11 @@ from django.contrib.auth.models import AnonymousUser from django.test import RequestFactory -from grainy.const import PERM_CREATE, PERM_DELETE, PERM_READ, PERM_UPDATE - from django_grainy.models import PermissionSet from django_grainy.util import Permissions from django_grainy_test.models import APIKey, ModelA, ModelB from django_grainy_test.views import JsonView, View, view +from grainy.const import PERM_CREATE, PERM_DELETE, PERM_READ, PERM_UPDATE from .util import UserTestCase diff --git a/tests/test_rest_framework.py b/tests/test_rest_framework.py index 5d0570d..72f7273 100644 --- a/tests/test_rest_framework.py +++ b/tests/test_rest_framework.py @@ -1,9 +1,8 @@ +from django_grainy_test.models import ModelA from grainy.const import PERM_CREATE, PERM_DELETE, PERM_READ, PERM_UPDATE from grainy.core import PermissionSet from rest_framework.test import APIClient -from django_grainy_test.models import ModelA - from .util import UserTestCase