Skip to content

Commit

Permalink
fix: permission issue without login (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure authored Nov 5, 2024
1 parent bccda31 commit 248e9e5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
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

0 comments on commit 248e9e5

Please sign in to comment.