Skip to main content

DRF like permission system

Project description

DGP - Django graphene permissions

Permission system inspired by DRF

Installation

Install the latest release:

$ pip3 install django-graphene-permissions

Or using pipenv

$ pipenv install django-graphene-permissions

Usage

Permission definition


You can create new permissions by subclassing BasePermission e.g.

from django_graphene_permissions.permissions import BasePermission

class MyPermission(BasePermission):

	@staticmethod
	def has_permission(context):
		return context.user and context.user.is_authenticated

	@staticmethod
	def has_object_permission(context, obj):
		return True

This package provides predefined permissions :

  • AllowAny : Allow any access.
  • IsAuthenticated : Allow only authenticated users.

Node Permission


Subclass PermissionDjangoObjectType and define the permissions via the static method permission_classes which returns an iterable of permissions classes

from django_graphene_permissions import PermissionDjangoObjectType
from django_graphene_permissions.permissions import IsAuthenticated

class ExampleNode(PermissionDjangoObjectType):
	class Meta:
		model = Example
		interfaces = (relay.Node,)

	@staticmethod
	def permission_classes():
		return [IsAuthenticated]

Mutation Permission


Apply the permissions_checker([Permission,...]) decorator to mutate e.g.

from django_graphene_permissions import permissions_checker
from django_graphene_permissions.permissions import IsAuthenticated

class ExampleDeleteMutation(graphene.Mutation):
	ok = graphene.Boolean()

	class Arguments:
		id = graphene.ID()

	@permissions_checker([IsAuthenticated])
	def mutate(self, info, id):
		instance = get_instance(id)
		instance.delete()
		return ExampleDeleteMutation(ok=True)

Query Permission


Apply the permissions_checker([Permission,...]) decorator to the field resolver e.g.

from django_graphene_permissions import permissions_checker
from django_graphene_permissions.permissions import IsAuthenticated

class Query(graphene.ObjectType):
	post = relay.Node.Field(PostNode)
	posts = DjangoFilterConnectionField(PostNode)

	@permissions_checker([IsAuthenticated])
	def resolve_posts(self, info, **kwargs):
		return Post.objects.all()

TODO

  • Tests
  • Add a PermissionDjangoFilterConnectionField
  • Better docs
  • Improvement

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_graphene_permissions-0.0.3.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file django_graphene_permissions-0.0.3.tar.gz.

File metadata

  • Download URL: django_graphene_permissions-0.0.3.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for django_graphene_permissions-0.0.3.tar.gz
Algorithm Hash digest
SHA256 89e64f018d5360c7b1cd3712c7b74fff4945a6ba3f7dd02a793ddad8a4aa4a0b
MD5 f85c92a874736304cd655dc4e3a40b47
BLAKE2b-256 80431cd0cbbeed97d13f95dc09fba01cdd3900292430a6578499dff5b861d207

See more details on using hashes here.

File details

Details for the file django_graphene_permissions-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: django_graphene_permissions-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for django_graphene_permissions-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1c6a3e54b235deac20cc4e9e22a1a5e3532086c14fc88880417bbab5a7278ce5
MD5 c23910570274a6699655ededc8d3c353
BLAKE2b-256 f15cbaaee972ef11827d504abcc38898e7d75a59a0d0aadd5c5897b31656f78a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page