def has_perm(self, user_obj, perm, obj=None): # if not user_obj.is_authenticated() or not user.is_active: # FIXME: load guest perms and proceed # return False # super users have access to everything if user_obj.is_superuser: return True namespace, level = permcode_to_namespace(perm) write_ops = ["add", "delete", "change"] if hasattr(obj, "nsp_write_ops") and callable(obj, "nsp_write_ops"): write_ops.extend(getattr(obj, "nsp_write_ops")()) log.info("NSP has_perms %s %s %s" % (namespace, perm, level)) perms = self.load_perms(user_obj) return has_perms(perms, namespace, level)
def test_permcode_to_namespace_change_crud(self): settings.NSP_MODE = "crud" label, flag = util.permcode_to_namespace("app.change_model") self.assertEqual("app.model.change", label) self.assertEqual(flag, constants.PERM_UPDATE)
def test_permcode_to_namespace_add_crud(self): settings.NSP_MODE = "crud" label, flag = util.permcode_to_namespace("app.add_model") self.assertEqual("app.model.add", label) self.assertEqual(flag, constants.PERM_CREATE)
def test_permcode_to_namespace_view_crud(self): settings.NSP_MODE = "crud" label, flag = util.permcode_to_namespace("app.view_model") self.assertEqual("app.model.view", label) self.assertEqual(flag, constants.PERM_READ)
def test_permcode_to_namespace_change(self): label, flag = util.permcode_to_namespace("app.change_model") self.assertEqual("app.model.change", label) self.assertEqual(flag, constants.PERM_WRITE)
def test_permcode_to_namespace_view(self): label, flag = util.permcode_to_namespace("app.view_model") self.assertEqual("app.model.view", label) self.assertEqual(flag, constants.PERM_READ)