Best Python code snippet using playwright-python
permissions.py
Source:permissions.py
...7 from `tabWebsite Route Permission`8 where ifnull(`read`, 0)=0 and ifnull(`write`, 0)=0 and ifnull(`admin`, 0)=0""")9 frappe.db.sql("""delete from `tabWebsite Route Permission`10 where ifnull(`read`, 0)=0 and ifnull(`write`, 0)=0 and ifnull(`admin`, 0)=0""")11 clear_permissions(permissions_cache_to_be_cleared)12def get_access(doc, pathname, user=None):13 user = user or frappe.session.user14 key = "website_route_permissions:{}".format(user)15 cache = frappe.cache()16 permissions = cache.get_value(key) or {}17 if not permissions.get(doc.name):18 permissions[doc.name] = _get_access(doc, pathname, user)19 cache.set_value(key, permissions)20 return permissions.get(doc.name)21def _get_access(doc, pathname, user):22 read = write = admin = private_read = 023 if user == "Guest":24 return { "read": doc.public_read, "write": 0, "admin": 0 }25 if doc.public_write:26 read = write = 127 elif doc.public_read:28 read = 129 for perm in frappe.db.sql("""select30 `tabWebsite Route Permission`.`read`,31 `tabWebsite Route Permission`.`write`,32 `tabWebsite Route Permission`.`admin`,33 `tabWebsite Group`.lft,34 `tabWebsite Group`.rgt35 from36 `tabWebsite Route Permission`, `tabWebsite Group`37 where38 `tabWebsite Route Permission`.website_route = %s and39 `tabWebsite Route Permission`.user = %s and40 `tabWebsite Route Permission`.reference = `tabWebsite Group`.name41 order by `tabWebsite Group`.lft asc""", (user, pathname), as_dict=True):42 if perm.lft <= doc.lft and perm.rgt >= doc.rgt:43 if not (doc.public_read or private_read):44 private_read = perm.read45 if not read: read = perm.read46 if not write: write = perm.write47 if not admin: admin = perm.admin48 if write: read = write49 if read and write and admin:50 break51 else:52 read = write = admin = private_read = 153 return { "read": read, "write": write, "admin": admin, "private_read": private_read }54def clear_permissions(users=None):55 if isinstance(users, basestring):56 users = [users]57 elif users is None:58 users = frappe.db.sql_list("""select name from `tabUser`""")59 cache = frappe.cache()60 for user in users:...
permissions_utils.py
Source:permissions_utils.py
1from restricted_endpoint_access.models.permission import Permission2from restricted_endpoint_access.models.role import Role3class PermissionUtils:4 @staticmethod5 def clear_permissions():6 Permission.objects.all().delete()7 @staticmethod8 def generate_permissions(routes):9 PermissionUtils.clear_permissions()10 for route in routes:11 PermissionUtils.generate_permission(**route)12 @staticmethod13 def generate_permission(name, route, methods, roles):14 for method in methods:15 permission = Permission.objects.create(16 name=name,17 method=method,18 url_pattern=route19 )20 if roles:21 for role in roles:22 if not role.permissions.filter(id=permission.id).exists():23 role.permissions.add(permission)
website_route_permission.py
Source:website_route_permission.py
...7class WebsiteRoutePermission(Document):8 9 def on_update(self):10 remove_empty_permissions()11 clear_permissions(self.user)...
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!