def test_has_perm_add_with_obj_collaborators(self):
     permission_logic = CollaboratorsPermissionLogic()
     add_permission_logic(self.article.__class__, permission_logic)
     self.assertTrue(
             permission_logic.has_perm(self.user2, self.perm1, self.article))
 def test_has_perm_delete_with_obj_collaborators(self):
     permission_logic = CollaboratorsPermissionLogic()
     self.assertTrue(
             permission_logic.has_perm(self.user2, self.perm3, self.article))
 def test_has_perm_add_with_obj_collaborators_diff_field_name(self):
     permission_logic = CollaboratorsPermissionLogic(field_name='editors')
     self.assertFalse(
             permission_logic.has_perm(self.user2, self.perm1, self.article))
Exemplo n.º 4
0
 def test_has_perm_delete_with_obj_with_anonymous(self):
     permission_logic = CollaboratorsPermissionLogic()
     add_permission_logic(self.article.__class__, permission_logic)
     self.assertFalse(
         permission_logic.has_perm(self.anonymous, self.perm3, self.article))
 def test_has_perm_change_with_obj(self):
     permission_logic = CollaboratorsPermissionLogic()
     self.assertFalse(
             permission_logic.has_perm(self.user1, self.perm2, self.article))
 def test_has_perm_delete_with_obj_non_any_no_delete(self):
     permission_logic = CollaboratorsPermissionLogic(any_permission=False,
                                              delete_permission=False)
     add_permission_logic(self.article.__class__, permission_logic)
     self.assertFalse(
             permission_logic.has_perm(self.user2, self.perm3, self.article))
 def test_has_perm_delete_with_obj(self):
     permission_logic = CollaboratorsPermissionLogic()
     add_permission_logic(self.article.__class__, permission_logic)
     self.assertFalse(
             permission_logic.has_perm(self.user1, self.perm3, self.article))
Exemplo n.º 8
0
 def test_constructor_with_specifing_delete_permission(self):
     permission_logic = CollaboratorsPermissionLogic(delete_permission=False)
     add_permission_logic(self.article.__class__, permission_logic)
     self.assertTrue(isinstance(permission_logic, CollaboratorsPermissionLogic))
     self.assertEqual(permission_logic.delete_permission, False)
Exemplo n.º 9
0
 def test_has_perm_change_without_obj(self):
     permission_logic = CollaboratorsPermissionLogic()
     add_permission_logic(self.article.__class__, permission_logic)
     self.assertTrue(permission_logic.has_perm(self.user1, self.perm2))
Exemplo n.º 10
0
 def test_has_perm_delete_with_obj_non_any_no_delete(self):
     permission_logic = CollaboratorsPermissionLogic(any_permission=False,
                                              delete_permission=False)
     add_permission_logic(self.article.__class__, permission_logic)
     self.assertFalse(
             permission_logic.has_perm(self.user2, self.perm3, self.article))
Exemplo n.º 11
0
 def test_constructor_with_specifing_field_name(self):
     permission_logic = CollaboratorsPermissionLogic(field_name='specified')
     add_permission_logic(self.article.__class__, permission_logic)
     self.assertTrue(isinstance(permission_logic, CollaboratorsPermissionLogic))
     self.assertEqual(permission_logic.field_name, 'specified')
Exemplo n.º 12
0
 def test_has_perm_add_with_obj_collaborators_non_any_no_change(self):
     permission_logic = CollaboratorsPermissionLogic(any_permission=False,
                                              change_permission=False)
     add_permission_logic(self.article.__class__, permission_logic)
     self.assertFalse(
             permission_logic.has_perm(self.user2, self.perm1, self.article))
Exemplo n.º 13
0
 def test_has_perm_delete_with_obj_collaborators_diff_field_name(self):
     permission_logic = CollaboratorsPermissionLogic(field_name='editors')
     add_permission_logic(self.article.__class__, permission_logic)
     self.assertFalse(
             permission_logic.has_perm(self.user2, self.perm3, self.article))
Exemplo n.º 14
0
 def test_has_perm_delete_with_obj_collaborators(self):
     permission_logic = CollaboratorsPermissionLogic()
     add_permission_logic(self.article.__class__, permission_logic)
     self.assertTrue(
             permission_logic.has_perm(self.user2, self.perm3, self.article))
 def test_has_perm_delete_with_obj_collaborators_diff_field_name(self):
     permission_logic = CollaboratorsPermissionLogic(field_name='editors')
     add_permission_logic(self.article.__class__, permission_logic)
     self.assertFalse(
             permission_logic.has_perm(self.user2, self.perm3, self.article))
 def test_has_perm_add_with_obj_collaborators_non_any(self):
     permission_logic = CollaboratorsPermissionLogic(any_permission=False)
     self.assertFalse(
             permission_logic.has_perm(self.user2, self.perm1, self.article))
 def test_has_perm_add_with_obj_collaborators_non_any_no_change(self):
     permission_logic = CollaboratorsPermissionLogic(any_permission=False,
                                              change_permission=False)
     add_permission_logic(self.article.__class__, permission_logic)
     self.assertFalse(
             permission_logic.has_perm(self.user2, self.perm1, self.article))
 def test_has_perm_change_with_obj_collaborators_non_any_no_delete(self):
     permission_logic = CollaboratorsPermissionLogic(any_permission=False,
                                              delete_permission=False)
     self.assertTrue(
             permission_logic.has_perm(self.user2, self.perm2, self.article))
 def test_has_perm_change_without_obj(self):
     permission_logic = CollaboratorsPermissionLogic()
     add_permission_logic(self.article.__class__, permission_logic)
     self.assertTrue(permission_logic.has_perm(self.user1, self.perm2))
 def test_has_perm_delete_without_obj(self):
     permission_logic = CollaboratorsPermissionLogic()
     self.assertFalse(permission_logic.has_perm(self.user1, self.perm3))
 def test_has_perm_add_without_obj_with_anonymous(self):
     permission_logic = CollaboratorsPermissionLogic()
     add_permission_logic(self.article.__class__, permission_logic)
     self.assertFalse(permission_logic.has_perm(self.anonymous, self.perm1))
Exemplo n.º 22
0
from django.conf import settings
from django.db.models import get_models, get_app
'''
EXAMPLE
PERMISSION_LOGICS = (
    ('example.Person', AuthorPermissionLogic(field_name='owner',)),
    ('example.Person', CollaboratorsPermissionLogic()),
)
'''

# Loop the registered apps from settings
for app_name in settings.REST_EASY_APPS:

    # Get the models, then loop
    PERMISSION_LOGICS = ()
    app_models = get_app(app_name)
    for app_model in get_models(app_models):
        PERMISSION_LOGICS = PERMISSION_LOGICS + ((
            app_name + '.' + app_model.__name__,
            AuthorPermissionLogic(field_name='owner'),
        ), )
        PERMISSION_LOGICS = PERMISSION_LOGICS + ((
            app_name + '.' + app_model.__name__,
            CollaboratorsPermissionLogic(),
        ), )
        #PERMISSION_LOGICS = PERMISSION_LOGICS + (( app_name+'.'+app_model.__name__,GroupInPermissionLogic(),),)
        PERMISSION_LOGICS = PERMISSION_LOGICS + ((
            app_name + '.' + app_model.__name__,
            StaffPermissionLogic(),
        ), )