summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--python-djangorestframework-guardian.spec591
-rw-r--r--sources1
3 files changed, 593 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index e69de29..2b4b6fb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/djangorestframework-guardian-0.3.0.tar.gz
diff --git a/python-djangorestframework-guardian.spec b/python-djangorestframework-guardian.spec
new file mode 100644
index 0000000..acec089
--- /dev/null
+++ b/python-djangorestframework-guardian.spec
@@ -0,0 +1,591 @@
+%global _empty_manifest_terminate_build 0
+Name: python-djangorestframework-guardian
+Version: 0.3.0
+Release: 1
+Summary: django-guardian support for Django REST Framework
+License: BSD
+URL: https://github.com/rpkilby/django-rest-framework-guardian
+Source0: https://mirrors.nju.edu.cn/pypi/web/packages/e5/80/0f2190bacfe7c7b2e22d0e1e695882ec3123f9e58817c8392a258cd46442/djangorestframework-guardian-0.3.0.tar.gz
+BuildArch: noarch
+
+Requires: python3-django
+Requires: python3-djangorestframework
+Requires: python3-django-guardian
+
+%description
+# django-rest-framework-guardian
+
+[![CircleCI](https://circleci.com/gh/rpkilby/django-rest-framework-guardian.svg?style=shield)](https://circleci.com/gh/rpkilby/django-rest-framework-guardian)
+[![Codecov](https://codecov.io/gh/rpkilby/django-rest-framework-guardian/branch/master/graph/badge.svg)](https://codecov.io/gh/rpkilby/django-rest-framework-guardian)
+[![License](https://img.shields.io/pypi/l/djangorestframework-guardian.svg)](https://pypi.org/project/djangorestframework-guardian)
+[![Version](https://img.shields.io/pypi/v/djangorestframework-guardian.svg)](https://pypi.org/project/djangorestframework-guardian)
+[![Python](https://img.shields.io/pypi/pyversions/djangorestframework-guardian.svg)](https://pypi.org/project/djangorestframework-guardian/)
+
+django-rest-framework-guardian provides django-guardian integrations for Django REST Framework.
+Currently, this only includes the `ObjectPermissionsFilter`.
+
+
+## Installation & Setup
+
+To use django-rest-framework-guardian, install it into your environment.
+
+```sh
+$ pip install djangorestframework-guardian
+```
+
+Ensure both Django REST Framework and django-guardian are configured and added to your `INSTALLED_APPS` setting.
+
+```python
+INSTALLED_APPS = [
+ 'rest_framework',
+ 'guardian',
+]
+
+AUTHENTICATION_BACKENDS = [
+ 'django.contrib.auth.backends.ModelBackend',
+ 'guardian.backends.ObjectPermissionBackend',
+]
+```
+
+
+## ObjectPermissionsFilter
+
+The filter will ensure that querysets only returns objects for which the user has the appropriate view permission.
+
+If you're using `ObjectPermissionsFilter`, you'll probably also want to add an appropriate object permissions
+class, to ensure that users can only operate on instances if they have the appropriate object permissions. The easiest
+way to do this is to subclass `DjangoObjectPermissions` and add `'view'` permissions to the `perms_map` attribute.
+
+An example using both `ObjectPermissionsFilter` and `DjangoObjectPermissions` might look like the following:
+
+**permissions.py**:
+
+```python
+from rest_framework import permissions
+
+
+class CustomObjectPermissions(permissions.DjangoObjectPermissions):
+ """
+ Similar to `DjangoObjectPermissions`, but adding 'view' permissions.
+ """
+ perms_map = {
+ 'GET': ['%(app_label)s.view_%(model_name)s'],
+ 'OPTIONS': ['%(app_label)s.view_%(model_name)s'],
+ 'HEAD': ['%(app_label)s.view_%(model_name)s'],
+ 'POST': ['%(app_label)s.add_%(model_name)s'],
+ 'PUT': ['%(app_label)s.change_%(model_name)s'],
+ 'PATCH': ['%(app_label)s.change_%(model_name)s'],
+ 'DELETE': ['%(app_label)s.delete_%(model_name)s'],
+ }
+```
+
+**views.py**:
+
+```python
+from rest_framework import viewsets
+from rest_framework_guardian import filters
+
+from myapp.models import Event
+from myapp.permissions import CustomObjectPermissions
+from myapp.serializers import EventSerializer
+
+
+class EventViewSet(viewsets.ModelViewSet):
+ """
+ Viewset that only lists events if user has 'view' permissions, and only
+ allows operations on individual events if user has appropriate 'view', 'add',
+ 'change' or 'delete' permissions.
+ """
+ queryset = Event.objects.all()
+ serializer_class = EventSerializer
+ permission_classes = [CustomObjectPermissions]
+ filter_backends = [filters.ObjectPermissionsFilter]
+```
+
+
+## ObjectPermissionsAssignmentMixin
+
+A serializer mixin that allows permissions to be easily assigned to users and/or groups.
+So each time an object is created or updated, the `permissions_map` returned by `Serializer.get_permissions_map` will be used to assign permission(s) to that object.
+
+Please note that the existing permissions will remain intact.
+
+A usage example might look like the following:
+
+```python
+from rest_framework_guardian.serializers import ObjectPermissionsAssignmentMixin
+
+from blog.models import Post
+
+
+class PostSerializer(ObjectPermissionsAssignmentMixin, serializers.ModelSerializer):
+ class Meta:
+ model = Post
+ fields = '__all__'
+
+ def get_permissions_map(self, created):
+ current_user = self.context['request'].user
+ readers = Group.objects.get(name='readers')
+ supervisors = Group.objects.get(name='supervisors')
+
+ return {
+ 'view_post': [current_user, readers],
+ 'change_post': [current_user],
+ 'delete_post': [current_user, supervisors]
+ }
+
+```
+
+
+## Release Process
+
+- Update changelog
+- Update package version in setup.py
+- Create git tag for version
+- Build & upload release to PyPI
+ ```bash
+ $ pip install -U pip setuptools wheel twine
+ $ rm -rf dist/ build/
+ $ python setup.py bdist_wheel
+ $ twine upload dist/*
+ ```
+
+## License
+
+See: [LICENSE](https://github.com/rpkilby/django-rest-framework-guardian/blob/master/LICENSE)
+
+BSD 3-Clause License
+
+Copyright (c) 2018, Ryan P Kilby
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+* Neither the name of the copyright holder nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+
+
+%package -n python3-djangorestframework-guardian
+Summary: django-guardian support for Django REST Framework
+Provides: python-djangorestframework-guardian
+BuildRequires: python3-devel
+BuildRequires: python3-setuptools
+BuildRequires: python3-pip
+%description -n python3-djangorestframework-guardian
+# django-rest-framework-guardian
+
+[![CircleCI](https://circleci.com/gh/rpkilby/django-rest-framework-guardian.svg?style=shield)](https://circleci.com/gh/rpkilby/django-rest-framework-guardian)
+[![Codecov](https://codecov.io/gh/rpkilby/django-rest-framework-guardian/branch/master/graph/badge.svg)](https://codecov.io/gh/rpkilby/django-rest-framework-guardian)
+[![License](https://img.shields.io/pypi/l/djangorestframework-guardian.svg)](https://pypi.org/project/djangorestframework-guardian)
+[![Version](https://img.shields.io/pypi/v/djangorestframework-guardian.svg)](https://pypi.org/project/djangorestframework-guardian)
+[![Python](https://img.shields.io/pypi/pyversions/djangorestframework-guardian.svg)](https://pypi.org/project/djangorestframework-guardian/)
+
+django-rest-framework-guardian provides django-guardian integrations for Django REST Framework.
+Currently, this only includes the `ObjectPermissionsFilter`.
+
+
+## Installation & Setup
+
+To use django-rest-framework-guardian, install it into your environment.
+
+```sh
+$ pip install djangorestframework-guardian
+```
+
+Ensure both Django REST Framework and django-guardian are configured and added to your `INSTALLED_APPS` setting.
+
+```python
+INSTALLED_APPS = [
+ 'rest_framework',
+ 'guardian',
+]
+
+AUTHENTICATION_BACKENDS = [
+ 'django.contrib.auth.backends.ModelBackend',
+ 'guardian.backends.ObjectPermissionBackend',
+]
+```
+
+
+## ObjectPermissionsFilter
+
+The filter will ensure that querysets only returns objects for which the user has the appropriate view permission.
+
+If you're using `ObjectPermissionsFilter`, you'll probably also want to add an appropriate object permissions
+class, to ensure that users can only operate on instances if they have the appropriate object permissions. The easiest
+way to do this is to subclass `DjangoObjectPermissions` and add `'view'` permissions to the `perms_map` attribute.
+
+An example using both `ObjectPermissionsFilter` and `DjangoObjectPermissions` might look like the following:
+
+**permissions.py**:
+
+```python
+from rest_framework import permissions
+
+
+class CustomObjectPermissions(permissions.DjangoObjectPermissions):
+ """
+ Similar to `DjangoObjectPermissions`, but adding 'view' permissions.
+ """
+ perms_map = {
+ 'GET': ['%(app_label)s.view_%(model_name)s'],
+ 'OPTIONS': ['%(app_label)s.view_%(model_name)s'],
+ 'HEAD': ['%(app_label)s.view_%(model_name)s'],
+ 'POST': ['%(app_label)s.add_%(model_name)s'],
+ 'PUT': ['%(app_label)s.change_%(model_name)s'],
+ 'PATCH': ['%(app_label)s.change_%(model_name)s'],
+ 'DELETE': ['%(app_label)s.delete_%(model_name)s'],
+ }
+```
+
+**views.py**:
+
+```python
+from rest_framework import viewsets
+from rest_framework_guardian import filters
+
+from myapp.models import Event
+from myapp.permissions import CustomObjectPermissions
+from myapp.serializers import EventSerializer
+
+
+class EventViewSet(viewsets.ModelViewSet):
+ """
+ Viewset that only lists events if user has 'view' permissions, and only
+ allows operations on individual events if user has appropriate 'view', 'add',
+ 'change' or 'delete' permissions.
+ """
+ queryset = Event.objects.all()
+ serializer_class = EventSerializer
+ permission_classes = [CustomObjectPermissions]
+ filter_backends = [filters.ObjectPermissionsFilter]
+```
+
+
+## ObjectPermissionsAssignmentMixin
+
+A serializer mixin that allows permissions to be easily assigned to users and/or groups.
+So each time an object is created or updated, the `permissions_map` returned by `Serializer.get_permissions_map` will be used to assign permission(s) to that object.
+
+Please note that the existing permissions will remain intact.
+
+A usage example might look like the following:
+
+```python
+from rest_framework_guardian.serializers import ObjectPermissionsAssignmentMixin
+
+from blog.models import Post
+
+
+class PostSerializer(ObjectPermissionsAssignmentMixin, serializers.ModelSerializer):
+ class Meta:
+ model = Post
+ fields = '__all__'
+
+ def get_permissions_map(self, created):
+ current_user = self.context['request'].user
+ readers = Group.objects.get(name='readers')
+ supervisors = Group.objects.get(name='supervisors')
+
+ return {
+ 'view_post': [current_user, readers],
+ 'change_post': [current_user],
+ 'delete_post': [current_user, supervisors]
+ }
+
+```
+
+
+## Release Process
+
+- Update changelog
+- Update package version in setup.py
+- Create git tag for version
+- Build & upload release to PyPI
+ ```bash
+ $ pip install -U pip setuptools wheel twine
+ $ rm -rf dist/ build/
+ $ python setup.py bdist_wheel
+ $ twine upload dist/*
+ ```
+
+## License
+
+See: [LICENSE](https://github.com/rpkilby/django-rest-framework-guardian/blob/master/LICENSE)
+
+BSD 3-Clause License
+
+Copyright (c) 2018, Ryan P Kilby
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+* Neither the name of the copyright holder nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+
+
+%package help
+Summary: Development documents and examples for djangorestframework-guardian
+Provides: python3-djangorestframework-guardian-doc
+%description help
+# django-rest-framework-guardian
+
+[![CircleCI](https://circleci.com/gh/rpkilby/django-rest-framework-guardian.svg?style=shield)](https://circleci.com/gh/rpkilby/django-rest-framework-guardian)
+[![Codecov](https://codecov.io/gh/rpkilby/django-rest-framework-guardian/branch/master/graph/badge.svg)](https://codecov.io/gh/rpkilby/django-rest-framework-guardian)
+[![License](https://img.shields.io/pypi/l/djangorestframework-guardian.svg)](https://pypi.org/project/djangorestframework-guardian)
+[![Version](https://img.shields.io/pypi/v/djangorestframework-guardian.svg)](https://pypi.org/project/djangorestframework-guardian)
+[![Python](https://img.shields.io/pypi/pyversions/djangorestframework-guardian.svg)](https://pypi.org/project/djangorestframework-guardian/)
+
+django-rest-framework-guardian provides django-guardian integrations for Django REST Framework.
+Currently, this only includes the `ObjectPermissionsFilter`.
+
+
+## Installation & Setup
+
+To use django-rest-framework-guardian, install it into your environment.
+
+```sh
+$ pip install djangorestframework-guardian
+```
+
+Ensure both Django REST Framework and django-guardian are configured and added to your `INSTALLED_APPS` setting.
+
+```python
+INSTALLED_APPS = [
+ 'rest_framework',
+ 'guardian',
+]
+
+AUTHENTICATION_BACKENDS = [
+ 'django.contrib.auth.backends.ModelBackend',
+ 'guardian.backends.ObjectPermissionBackend',
+]
+```
+
+
+## ObjectPermissionsFilter
+
+The filter will ensure that querysets only returns objects for which the user has the appropriate view permission.
+
+If you're using `ObjectPermissionsFilter`, you'll probably also want to add an appropriate object permissions
+class, to ensure that users can only operate on instances if they have the appropriate object permissions. The easiest
+way to do this is to subclass `DjangoObjectPermissions` and add `'view'` permissions to the `perms_map` attribute.
+
+An example using both `ObjectPermissionsFilter` and `DjangoObjectPermissions` might look like the following:
+
+**permissions.py**:
+
+```python
+from rest_framework import permissions
+
+
+class CustomObjectPermissions(permissions.DjangoObjectPermissions):
+ """
+ Similar to `DjangoObjectPermissions`, but adding 'view' permissions.
+ """
+ perms_map = {
+ 'GET': ['%(app_label)s.view_%(model_name)s'],
+ 'OPTIONS': ['%(app_label)s.view_%(model_name)s'],
+ 'HEAD': ['%(app_label)s.view_%(model_name)s'],
+ 'POST': ['%(app_label)s.add_%(model_name)s'],
+ 'PUT': ['%(app_label)s.change_%(model_name)s'],
+ 'PATCH': ['%(app_label)s.change_%(model_name)s'],
+ 'DELETE': ['%(app_label)s.delete_%(model_name)s'],
+ }
+```
+
+**views.py**:
+
+```python
+from rest_framework import viewsets
+from rest_framework_guardian import filters
+
+from myapp.models import Event
+from myapp.permissions import CustomObjectPermissions
+from myapp.serializers import EventSerializer
+
+
+class EventViewSet(viewsets.ModelViewSet):
+ """
+ Viewset that only lists events if user has 'view' permissions, and only
+ allows operations on individual events if user has appropriate 'view', 'add',
+ 'change' or 'delete' permissions.
+ """
+ queryset = Event.objects.all()
+ serializer_class = EventSerializer
+ permission_classes = [CustomObjectPermissions]
+ filter_backends = [filters.ObjectPermissionsFilter]
+```
+
+
+## ObjectPermissionsAssignmentMixin
+
+A serializer mixin that allows permissions to be easily assigned to users and/or groups.
+So each time an object is created or updated, the `permissions_map` returned by `Serializer.get_permissions_map` will be used to assign permission(s) to that object.
+
+Please note that the existing permissions will remain intact.
+
+A usage example might look like the following:
+
+```python
+from rest_framework_guardian.serializers import ObjectPermissionsAssignmentMixin
+
+from blog.models import Post
+
+
+class PostSerializer(ObjectPermissionsAssignmentMixin, serializers.ModelSerializer):
+ class Meta:
+ model = Post
+ fields = '__all__'
+
+ def get_permissions_map(self, created):
+ current_user = self.context['request'].user
+ readers = Group.objects.get(name='readers')
+ supervisors = Group.objects.get(name='supervisors')
+
+ return {
+ 'view_post': [current_user, readers],
+ 'change_post': [current_user],
+ 'delete_post': [current_user, supervisors]
+ }
+
+```
+
+
+## Release Process
+
+- Update changelog
+- Update package version in setup.py
+- Create git tag for version
+- Build & upload release to PyPI
+ ```bash
+ $ pip install -U pip setuptools wheel twine
+ $ rm -rf dist/ build/
+ $ python setup.py bdist_wheel
+ $ twine upload dist/*
+ ```
+
+## License
+
+See: [LICENSE](https://github.com/rpkilby/django-rest-framework-guardian/blob/master/LICENSE)
+
+BSD 3-Clause License
+
+Copyright (c) 2018, Ryan P Kilby
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+* Neither the name of the copyright holder nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+
+
+%prep
+%autosetup -n djangorestframework-guardian-0.3.0
+
+%build
+%py3_build
+
+%install
+%py3_install
+install -d -m755 %{buildroot}/%{_pkgdocdir}
+if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
+if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
+if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
+if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
+pushd %{buildroot}
+if [ -d usr/lib ]; then
+ find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/lib64 ]; then
+ find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/bin ]; then
+ find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/sbin ]; then
+ find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+touch doclist.lst
+if [ -d usr/share/man ]; then
+ find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
+fi
+popd
+mv %{buildroot}/filelist.lst .
+mv %{buildroot}/doclist.lst .
+
+%files -n python3-djangorestframework-guardian -f filelist.lst
+%dir %{python3_sitelib}/*
+
+%files help -f doclist.lst
+%{_docdir}/*
+
+%changelog
+* Tue Apr 11 2023 Python_Bot <Python_Bot@openeuler.org> - 0.3.0-1
+- Package Spec generated
diff --git a/sources b/sources
new file mode 100644
index 0000000..e66d06a
--- /dev/null
+++ b/sources
@@ -0,0 +1 @@
+094e87bbeb9c28878636f5452980fd1e djangorestframework-guardian-0.3.0.tar.gz