fix: reroute portal users correctly

This commit is contained in:
sokumon 2025-12-19 20:34:28 +05:30
parent 50c7a69697
commit 0ea047a776
5 changed files with 32 additions and 4 deletions

View file

@ -441,3 +441,21 @@ def get_users_with_role(role: str) -> list[str]:
.distinct()
.run(pluck=True)
)
def is_portal_user():
from frappe.utils import has_common
roles = get_portal_roles()
user_type = frappe.session.data.user_type
if user_type == "Website User" and has_common(frappe.get_roles(), roles):
return True
def get_portal_roles():
roles = []
for menu_item in frappe.get_single("Portal Settings").menu:
if menu_item.role and menu_item.role not in roles:
roles.append(menu_item.role)
return roles

View file

@ -20,6 +20,7 @@ from frappe.utils import (
get_system_timezone,
md_to_html,
)
from frappe.utils.user import is_portal_user
FRONTMATTER_PATTERN = re.compile(r"^\s*(?:---|\+\+\+)(.*?)(?:---|\+\+\+)\s*(.+)$", re.S | re.M)
H1_TAG_PATTERN = re.compile("<h1>([^<]*)")
@ -124,9 +125,10 @@ def get_home_page():
home_page = "login" if frappe.session.user == "Guest" else "me"
home_page = home_page.strip("/")
if home_page == "me" and frappe.session.data.user_type == "System User":
home_page = "desk"
if home_page == "me" and is_portal_user():
home_page = "portal"
return home_page
if frappe._dev_server:

View file

@ -75,10 +75,17 @@
<svg class="right-icon icon icon-md"><use href="#icon-home"></use></svg>
{{ _("Home") }}
</a>
<a href="/desk">
{% if is_portal_user %}
<a href="/portal">
<svg class="right-icon icon icon-md"><use href="#icon-website"></use></svg>
{{ _("Portal") }}
</a>
{% else %}
<a href="/desk">
<svg class="right-icon icon icon-md"><use href="#icon-grid"></use></svg>
{{ _("Desktop") }}
</a>
{% endif %}
<a href="/logout">
<svg class="right-icon icon icon-md"><use href="#icon-logout"></use></svg>
{{ _("Logout") }}

View file

@ -2,8 +2,8 @@
# License: MIT. See LICENSE
import frappe
import frappe.www.list
from frappe import _
from frappe.utils.user import is_portal_user
no_cache = 1
@ -14,3 +14,4 @@ def get_context(context):
context.current_user = frappe.get_doc("User", frappe.session.user)
context.show_sidebar = False
context.is_portal_user = is_portal_user()

View file

@ -12,7 +12,7 @@
{% block page_content %}
{% if not doctype %}
<h2>Welcome to the Portal</h2>
<div>Welcome to the Portal<div>
{% else %}
{% if introduction %}
<p>{{ introduction }}</p>