Code Monkey home page Code Monkey logo

Comments (5)

alk3mist avatar alk3mist commented on July 17, 2024

How about that: https://docs.djangoproject.com/en/2.0/topics/auth/default/#the-permissionrequiredmixin-mixin

from aiohttp-security.

alk3mist avatar alk3mist commented on July 17, 2024

There's also method_decorator https://stackoverflow.com/questions/29673549/method-decorator-with-login-required-and-permission-required#29673627

from aiohttp-security.

Maillol avatar Maillol commented on July 17, 2024

Hello @alk3mist

1) About method_decorator and has_permission:

Currently we can use aiohttp-security.has_permission decorator with function or method, but we cannot use this decorator with aiohttp.View.

@has_permission('read')  # works
def my_view(request):
    ...

class View:
    @has_permission('read')   # works 
    def read(request):
        ...

class View(aiohttp.web.View):
    @has_permission('read')   # doesn't work. 
    def read(self):
        ...

I don't think that need to add a method_decorator dedicated to the aiohttp.View because currently this decorator works with method except method of aiohttp.web.View.

2) About PermissionRequiredMixin and have a has_permission class decorator (PEP3129):

Django PermissionRequiredMixin use the same permission for all methods, but I would like have a mixin that set various permissions for each page.

We can have Mixin where each method matches a permission name with a suffix according to the CRUD/REST semantics (i.e post => create, get => read, put/patch => update, delete => delete)

class BookingView(HasPermissionMixin, web.View):

    # Define a common prefix of permission for all methods of the View.
    permission_prefix = 'booking'  
    permission_context = None  # Define context used by `has_permission`. 

    # post method needs permission suffixed by '.create' and starts with  `permission_prefix`
    def post(self):
         """
         Require `booking.create` permission
         """

    def get(self):
         """
         Require `booking.read` permission
         """

I think I prefer use Mixin for class instead of class decorator, thanks for your idea.

I would like to know the opinion of @asvetlov

from aiohttp-security.

asvetlov avatar asvetlov commented on July 17, 2024

The issue is in my todo list but I have no estimation for review, sorry.

from aiohttp-security.

asvetlov avatar asvetlov commented on July 17, 2024

Decorators should go away.
Use check_permission explicit call instead.

from aiohttp-security.

Related Issues (20)

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.