Skip to content

Commit

Permalink
fix: project route permissions for user
Browse files Browse the repository at this point in the history
  • Loading branch information
GursheenK committed Jul 20, 2023
1 parent 610ead2 commit 5d7dd9b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
3 changes: 2 additions & 1 deletion erpnext/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
]

standard_portal_menu_items = [
{"title": "Projects", "route": "/project", "reference_doctype": "Project"},
{"title": "Projects", "route": "/project", "reference_doctype": "Project", "role": "Customer"},
{
"title": "Request for Quotations",
"route": "/rfq",
Expand Down Expand Up @@ -277,6 +277,7 @@
"Delivery Note": "erpnext.controllers.website_list_for_contact.has_website_permission",
"Issue": "erpnext.support.doctype.issue.issue.has_website_permission",
"Timesheet": "erpnext.controllers.website_list_for_contact.has_website_permission",
"Project": "erpnext.controllers.website_list_for_contact.has_website_permission",
}

before_tests = "erpnext.setup.utils.before_tests"
Expand Down
40 changes: 29 additions & 11 deletions erpnext/projects/doctype/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from frappe.query_builder import Interval
from frappe.query_builder.functions import Count, CurDate, Date, UnixTimestamp
from frappe.utils import add_days, flt, get_datetime, get_time, get_url, nowtime, today
from frappe.utils.user import is_website_user

from erpnext import get_default_company
from erpnext.controllers.queries import get_filters_cond
Expand Down Expand Up @@ -319,15 +320,24 @@ def get_timeline_data(doctype: str, name: str) -> dict[int, int]:
def get_project_list(
doctype, txt, filters, limit_start, limit_page_length=20, order_by="modified"
):
user = frappe.session.user
customers, suppliers = get_customers_suppliers("Project", frappe.session.user)

ignore_permissions = False
if is_website_user():
if not filters:
filters = []

if customers:
filters.append([doctype, "customer", "in", customers])

ignore_permissions = True

meta = frappe.get_meta(doctype)
if not filters:
filters = []

fields = "distinct *"

or_filters = []
filters.append([doctype, "customer", "in", customers])

if txt:
if meta.search_fields:
Expand All @@ -354,18 +364,26 @@ def get_project_list(
limit_start=limit_start,
limit_page_length=limit_page_length,
order_by=order_by,
ignore_permissions=ignore_permissions,
)


def get_list_context(context=None):
return {
"show_sidebar": True,
"show_search": True,
"no_breadcrumbs": True,
"title": _("Projects"),
"get_list": get_project_list,
"row_template": "templates/includes/projects/project_row.html",
}
from erpnext.controllers.website_list_for_contact import get_list_context

list_context = get_list_context(context)
list_context.update(
{
"show_sidebar": True,
"show_search": True,
"no_breadcrumbs": True,
"title": _("Projects"),
"get_list": get_project_list,
"row_template": "templates/includes/projects/project_row.html",
}
)

return list_context


@frappe.whitelist()
Expand Down

0 comments on commit 5d7dd9b

Please sign in to comment.