Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: permission issue without login (backport #220) #221

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions webshop/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,8 @@
],
},
}

has_website_permission = {
"Website Item": "webshop.webshop.doctype.website_item.website_item.has_website_permission_for_website_item",
"Item Group": "webshop.webshop.doctype.website_item.website_item.has_website_permission_for_item_group"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"hide_variants",
"enable_variants",
"show_price",
"login_required_to_view_products",
"column_break_9",
"show_stock_availability",
"show_quantity_in_website",
Expand Down Expand Up @@ -366,12 +367,18 @@
"fieldtype": "Check",
"label": "Enable Redisearch",
"read_only_depends_on": "eval:!doc.is_redisearch_loaded"
},
{
"default": "0",
"fieldname": "login_required_to_view_products",
"fieldtype": "Check",
"label": "Login Required to View Products"
}
],
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2022-04-01 18:35:56.106756",
"modified": "2024-11-05 13:31:46.657592",
"modified_by": "Administrator",
"module": "Webshop",
"name": "Webshop Settings",
Expand Down
3 changes: 1 addition & 2 deletions webshop/webshop/doctype/website_item/website_item.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"actions": [],
"allow_guest_to_view": 1,
"allow_import": 1,
"autoname": "naming_series",
"creation": "2021-02-09 21:06:14.441698",
Expand Down Expand Up @@ -348,7 +347,7 @@
"index_web_pages_for_search": 1,
"links": [],
"make_attachments_public": 1,
"modified": "2022-09-30 04:01:52.090732",
"modified": "2024-11-05 13:41:45.347700",
"modified_by": "Administrator",
"module": "Webshop",
"name": "Website Item",
Expand Down
29 changes: 29 additions & 0 deletions webshop/webshop/doctype/website_item/website_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,32 @@ def make_website_item(doc, save=True):
insert_item_to_index(website_item)

return [website_item.name, website_item.web_item_name]

@frappe.whitelist()
def has_website_permission_for_website_item(doc, ptype, user, verbose=False):
# Check item group permissions for website

if user == "Administrator":
return True

if frappe.has_permission("Website Item", ptype=ptype, doc=doc, user=user):
return True

if not frappe.db.get_single_value("Webshop Settings", "login_required_to_view_products"):
return True

return False

@frappe.whitelist()
def has_website_permission_for_item_group(doc, ptype, user, verbose=False):
# Check item group permissions for website
if user == "Administrator":
return True

if frappe.has_permission("Item Group", ptype=ptype, doc=doc, user=user):
return True

if not frappe.db.get_single_value("Webshop Settings", "login_required_to_view_products"):
return True

return False
Loading