Changes between Version 8 and Version 9 of GenericAuthorization


Ignore:
Timestamp:
08/03/06 22:31:22 (9 years ago)
Author:
jkocherhans
Comment:

updated example code to current api

Legend:

Unmodified
Added
Removed
Modified
  • GenericAuthorization

    v8 v9  
    4545{{{
    4646#!python
    47 from django.contrib.auth.models import User
     47from django.contrib.auth.models import User, Permission
    4848from django.contrib.auth import has_permission
     49
     50class Person(models.Model)
     51    name = models.CharField(maxlength=50)
     52
     53    class Admin: pass
    4954
    5055def default_has_permission(user, permission, object=None):
    5156    return user.has_perm(permission)
    5257
    53 has_permission.register(default_has_permission, User)
     58has_permission.register(default_has_permission, User, Permission, Person)
    5459}}}
    5560
    56 This is fairly close to what it would look like to implement django's current security policy. The object isn't really important in this case since Django's permissions are based on the Model you're accessing, not the actual object (See RowLevelPermissions for object-specific permissions.) We is we pass more than just {{{User}}} to the register method, we can register different security rules for different Models.
     61Now every time has_permission is called with an instance of User, Permission, and Person, those argument will be passed into default_has_permission, and the result will be returned. This was we can use different functions for different models, custom user classes, and even custom permission types.
    5762
     63This is fairly close to what it would look like to implement django's current security policy. The object isn't really important in this case since Django's permissions are based on the Model you're accessing, not the actual object (See RowLevelPermissions for object-specific permissions.)
    5864
    5965== Implementation ==
Back to Top