Last active
October 8, 2019 21:55
-
-
Save ybenitezf/5e66627c668813886f9da60f67aef5e9 to your computer and use it in GitHub Desktop.
web2py inverse to accessible_query: given a record id, table name and permission returns a query of the users with access
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def accessible_to(db, name, table, record_id=0): | |
"""accessible_query inverse | |
parameters: | |
db: DAL instance | |
name: permission name | |
table: table name or table object | |
record_id: record id | |
retorna: Query | |
""" | |
if isinstance(table, str) and table in db.tables(): | |
table = db[table] | |
parte1 = (db.auth_permission.name == name) | |
parte1 &= (db.auth_permission.table_name == table) | |
if record_id != 0: | |
parte1 &= ( | |
(db.auth_permission.record_id == record_id) | | |
(db.auth_permission.record_id == 0)) | |
else: | |
# solo a la tabla en general | |
parte1 &= (db.auth_permission.record_id == 0) | |
parte2 = (db.auth_user.id == db.auth_membership.user_id) | |
parte2 &= (db.auth_membership.group_id == db.auth_group.id) | |
parte2 &= (db.auth_group.id == db.auth_permission.group_id) | |
sub = db(parte1 & parte2)._select(db.auth_user.id, distinct=True) | |
return db.auth_user.id.belongs(sub) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment