Example #1
0
    def get_permissions(self, obj):
        perms = Permissions(obj)
        rv = {
            ns: {
                "perms": perms.get(ns.format(org_id=obj.org.id), as_string=True),
                "label": label,
            }
            for ns, label in self.permission_namespaces
        }

        return rv
Example #2
0
    def get_permissions(self, obj):
        perms = Permissions(obj.user)
        rv = {
            ns: {
                "perms": perms.get(ns.format(org_id=obj.org.id), as_string=True),
                "label": label,
            }
            for ns, label in self.permission_namespaces
        }

        # for svc in self.context.get("services",[]):
        #    rv[svc.slug] = perms.get([obj.org, svc], as_string=True)
        return rv
Example #3
0
    def test_permissions_get(self):
        """
        test django.grainy.util.Permissions.get
        """

        perms = Permissions(self.users["user_a"])

        self.assertEqual(perms.get(ModelA), PERM_READ)
        self.assertEqual(perms.get(ModelA, as_string=True), "r")
        self.assertEqual(perms.get(ModelB), PERM_READ | PERM_UPDATE)
        self.assertEqual(perms.get(ModelB, as_string=True), "ru")
        self.assertEqual(perms.get("detail_manual", as_string=True), "c")
        self.assertEqual(
            perms.get("detail_manual.1", as_string=True, explicit=True),
            "crud")
        self.assertEqual(
            perms.get("detail_manual.2", as_string=True, explicit=True), "")
        self.assertEqual(perms.get("detail_manual.2", as_string=True), "c")