Changes between Initial Version and Version 1 of RowLevelPermissionsDeveloper


Ignore:
Timestamp:
Jul 13, 2006, 6:30:24 PM (18 years ago)
Author:
Chris Long <indirecthit@…>
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • RowLevelPermissionsDeveloper

    v1 v1  
     1[[TOC(inline)]]
     2
     3== Row Level Permissions Model ==
     4
     5Row Level Permissions uses generic relations to decrease the number of tables to only one. The generic relations allow us to create row level permissions with any instance of any model and connect it to an "owner" object. To allow more freedom, the owner object is also a generic relation. This means that you can use your own models as an owner of a row level permission. The actual model code is below:
     6
     7{{{
     8#!python
     9class RowLevelPermission(models.Model):
     10    type_id = models.PositiveIntegerField("'Type' ID")
     11    type_ct = models.ForeignKey(ContentType, verbose_name="'Type' content type", related_name="type_ct")
     12    owner_id = models.PositiveIntegerField("'Owner' ID")
     13    owner_ct = models.ForeignKey(ContentType, verbose_name="'Owner' content type", related_name="owner_ct")
     14    negative = models.BooleanField()
     15    permission = models.ForeignKey(Permission)
     16   
     17    type = models.GenericForeignKey(fk_field='type_id', ct_field='type_ct')
     18    owner = models.GenericForeignKey(fk_field='owner_id', ct_field='owner_ct')
     19   
     20    objects = RowLevelPermissionManager()
     21   
     22    class Meta:
     23        verbose_name = _('row level permission')
     24        verbose_name_plural = _('row level permissions')
     25        unique_together = (('type_ct', 'type_id', 'owner_id', 'owner_ct', 'permission'),)       
     26}}}
     27
     28This does not modify the current permissions table at all, and can be layered ontop of it if the developer wishes to but it can be ignored easily.
     29
     30== How Row Permissions Are Enabled ==
     31
     32Row permissions are enabled using the meta class, please see RowLevelPermissions for more information on how to enable them. How this is done is in django.db.models.base.ModelBase under __new__ is the following snippet:
     33
     34{{{
     35#!python
     36        if getattr(new_class._meta, 'row_level_permissions', None):
     37            from django.contrib.auth.models import RowLevelPermission
     38            gen_rel = django.db.models.GenericRelation(RowLevelPermission, object_id_field="type_id", content_type_field="type_ct")
     39            new_class.add_to_class("row_level_permissions", gen_rel)
     40}}}
     41
     42In django.db.models.options.Options it has been modified to set row_level_permissions as disabled by default.
     43
     44== Owner Objects ==
     45
     46At this current point of time, you can set up an owner by including the following relation:
     47{{{
     48#!python
     49...
     50row_level_permissions_owned = models.GenericRelation(RowLevelPermission, object_id_field="owner_id", content_type_field="owner_ct", related_name="owner")
     51...
     52}}}
     53
     54I might be changing this around in the near future, but I only expect it to be used a few times I don't see a large need to make this a similiar process to the enabling of row level permissions on objects. Please give feedback if you think otherwise.
     55
     56== Checking of Row Level Permissions ==
     57
     58To be added soon.
     59
     60== Integration into Administration Application ==
     61
     62Being worked on. Will post when it is complete or near enough to have a better idea.
Back to Top