guest role; guide section ticking
This commit is contained in:
@@ -187,6 +187,26 @@ def get_navigation():
|
||||
# Sort by position
|
||||
all_items.sort(key=lambda x: x.get('position', 99))
|
||||
|
||||
# A signed-out visitor is shown only what the guest role can actually
|
||||
# reach. Without this the sidebar offers them the whole app and every link
|
||||
# bounces off a 401, which reads as a broken site rather than a closed
|
||||
# door. An item with no declared permission is treated as members-only: a
|
||||
# plugin opts into being guest-visible by naming the permission its page
|
||||
# needs, which is the same string the API already gates on.
|
||||
from flask_jwt_extended import verify_jwt_in_request
|
||||
from shopdb.utils.authz import currentuser, guestholds
|
||||
|
||||
verify_jwt_in_request(optional=True)
|
||||
def guestmayreach(item):
|
||||
declared = item.get('permission')
|
||||
if not declared:
|
||||
return False
|
||||
names = declared if isinstance(declared, list) else [declared]
|
||||
return any(guestholds(name) for name in names)
|
||||
|
||||
if currentuser() is None:
|
||||
all_items = [item for item in all_items if guestmayreach(item)]
|
||||
|
||||
return success_response(all_items)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user