Git Product home page Git Product logo

django-rest-serializer-field-permissions's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-rest-serializer-field-permissions's Issues

Improve documentation

  • Make it clear that this module only governs retrieve access
  • Elaborate on creating new permissions
  • Add doc strings to everything in preparation for Sphinx
  • Build docs with sphinx
  • Host on read-the-docs

KeyError raised when using nested serializers

Hi, first of all, great work on this package!

I'm trying to use it along with DRF's nested serializers feature.
My code looks something like this:

class AccountSerializer(serializers.ModelSerializer):
    email = fields.EmailField(permission_classes=(IsAuthenticated(), ))

    class Meta:
         model = Account

class ContactSerializer(serializers.ModelSerializer):
    account = AccountSerializer(read_only=True)

    class Meta:
        model = Contact
        fields = (..., 'account', )

Unfortunately I'm getting the following error when calling the endpoint:

File ".../rest_framework_serializer_field_permissions/serializers.py", line 24, in fields
    request = self._context["request"]
KeyError: 'request'

Looks like the context is not passed to the nested serializer, so we can't access the request.

I used the workaround suggested here encode/django-rest-framework#2555 (comment) and it works but is there a nicer way to solve this?
I can help out and open a PR if you have an idea.

FieldPermissionSerializerMixin does not find "check_permission" on serializers with "many=True"

After trying to set up field based permissions with this library, I discovered I was unable to use permission on serializers with many=True. I believe this is likely because when you create a serializer with many=True DRF creates a ListSerializer to stand in for the serializer a user is creating.

I think a way to solve this problem would be to find some way to get the check_permission attribute to be on the ListSerializer, possibly by creating a custom list serializer.

What are your thoughts on this? If I can get some feedback I'll look into it more, implement the changes, and submit a PR.

[Feature] Support for RelatedFields

I have a use case where I am using DRF field permissions with django-rest-framework-json-api, which uses RelatedFields in favor of Serializer fields. The current SerializerPermissionMixin is not compatible with RelatedFields - but I'm looking for something very similar to that mixin.

[Feature] Support for object-level field permissions

For more complex object-level field permissions, I think it could be beneficial to pass the instance that is currently being checked to the FieldPermission. This is pretty simply achieved by wrapping Serializer.to_representation(instance) and keeping track of this instance in a Serializer.current_instance variable. (This is necessary for ListSerializers, as the Serializer.instance field contains the entire list in that case).

I have tested/implemented this in a branch on my fork, and will be opening a PR for review.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.