summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/res_users.py
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2024-02-02 14:07:12 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2024-02-02 14:07:12 +0700
commitd4913c30c804c20024584182d9b70d4c87544340 (patch)
tree6412a794cce0f286db1a51e7b2c573e35bfb1673 /indoteknik_custom/models/res_users.py
parent8bc43445f1d0b70d54d0a45830e04d0fcc406fbe (diff)
Add role permission feature
Diffstat (limited to 'indoteknik_custom/models/res_users.py')
-rwxr-xr-xindoteknik_custom/models/res_users.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/indoteknik_custom/models/res_users.py b/indoteknik_custom/models/res_users.py
index 09321fc6..33f64ce3 100755
--- a/indoteknik_custom/models/res_users.py
+++ b/indoteknik_custom/models/res_users.py
@@ -39,3 +39,20 @@ class ResUsers(models.Model):
if not vouchers: return None
return ', '.join(x.code for x in vouchers)
return None
+
+ def check_access(self, model, mode):
+ assert mode in ('read', 'write', 'create', 'unlink', 'import', 'export'), 'Invalid access mode'
+
+ self._cr.execute("""
+ SELECT MAX(CASE WHEN perm_{mode} THEN 1 ELSE 0 END)
+ FROM ir_model_access a
+ JOIN ir_model m ON (m.id = a.model_id)
+ JOIN res_groups_users_rel gu ON (gu.gid = a.group_id)
+ WHERE m.model = %s
+ AND gu.uid = %s
+ AND a.active IS TRUE
+ """.format(mode=mode), (model, self._uid,))
+ r = self._cr.fetchone()[0]
+
+ return bool(r)
+