Skip to content

Commit

Permalink
ruff isort/pyup
Browse files Browse the repository at this point in the history
  • Loading branch information
grizz committed Oct 5, 2024
1 parent 1f65523 commit a5fba73
Show file tree
Hide file tree
Showing 22 changed files with 17 additions and 38 deletions.
1 change: 0 additions & 1 deletion examples/check_permissions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import grainy.const

from django_grainy.util import Permissions

user.grainy_permissions.add_permission_set({"a.b.c": "r"})
Expand Down
1 change: 0 additions & 1 deletion examples/custom_permission_holder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import models

from django_grainy.models import Permission, PermissionManager
from django_grainy.util import Permissions

Expand Down
3 changes: 1 addition & 2 deletions examples/grainy_rest_viewset.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 0 additions & 1 deletion examples/grainy_view.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.views import View as BaseView

from django_grainy.decorators import grainy_view


Expand Down
1 change: 0 additions & 1 deletion examples/grainy_view_manual_a.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.views import BaseView

from django_grainy.decorators import grainy_view


Expand Down
1 change: 0 additions & 1 deletion examples/grainy_view_manual_b.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.views import BaseView

from django_grainy.decorators import grainy_view_response


Expand Down
1 change: 0 additions & 1 deletion examples/grainy_view_manual_c.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.views import BaseView

from django_grainy.decorators import grainy_view, grainy_view_response


Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ dev = [
# .ruff.toml
[tool.ruff]
ignore = ["F821"]
select = [
"I", # isort
"UP", # pyupgrade
]


[tool.hatch.metadata]
allow-direct-references = true
Expand Down
2 changes: 0 additions & 2 deletions src/django_grainy/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ 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

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
Expand Down
4 changes: 0 additions & 4 deletions src/django_grainy/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions src/django_grainy/helpers.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
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

from .conf import DJANGO_OP_TO_FLAG, PERM_CHOICES, REQUEST_METHOD_TO_FLAG


def namespace(target: Any, **kwargs: Any) -> str:

"""
Convert `target` to permissioning namespace
Expand Down
1 change: 0 additions & 1 deletion src/django_grainy/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ def __init__(
self.cache = cache

def fetch(self, url: str, cache_key: str, **params: Any) -> dict:

Check warning on line 155 in src/django_grainy/remote.py

View check run for this annotation

Codecov / codecov/patch

src/django_grainy/remote.py#L155

Added line #L155 was not covered by tests

"""
Retrieve grainy permissions from remote endpoint
Expand Down
5 changes: 2 additions & 3 deletions src/django_grainy/util.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/django_grainy_test/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion src/django_grainy_test/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/django_grainy_test/views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
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,
grainy_rest_viewset_response,
grainy_view,
grainy_view_response,
)
from rest_framework import viewsets

from .models import ModelA
from .serializers import ModelASerializer
Expand Down
3 changes: 1 addition & 2 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
3 changes: 1 addition & 2 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 2 additions & 3 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions tests/test_manager.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 1 addition & 2 deletions tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions tests/test_rest_framework.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down

0 comments on commit a5fba73

Please sign in to comment.