summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/res_users.py
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2024-02-07 15:17:15 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2024-02-07 15:17:15 +0700
commit1a339c7e5b644add00c3bd7c623cb6d4553277cf (patch)
tree966b744ecde042810aebbf61b658ecfe31e59bc2 /indoteknik_custom/models/res_users.py
parent953c3e611af5c57a8f7d57b5f2f651314c2a92a3 (diff)
parent20b1410fc2335f51ab08fdbecb54d6bfc437b6e1 (diff)
Merge branch 'feature/role-permission' into production
# Conflicts: # indoteknik_custom/__manifest__.py # indoteknik_custom/models/__init__.py
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)
+