Offer the search box to whoever can actually search
The sidebar box was drawn for anyone signed in, on the reasoning that offering it to a signed-out reader gives them a control that can only answer 401. That stopped being the right test when the guest role became able to hold assets.view: the box was hidden from exactly the visitor the grant was reopened for, and a guest could reach search only by typing /search?q= by hand. The client cannot decide this. Its hasPermission getter reads the signed-in user's permission list and a guest has no user at all, so asking it about a guest answers no for everyone. get_navigation already had the problem and already solved it by letting the server decide, so capabilities does the same thing and reports what the CALLER holds. It reports booleans about the caller and never what the guest role holds in general, so it tells an anonymous reader nothing the rendered page does not. Public because it is the pre-login call that decides whether the box is drawn at all. Members who lack assets.view now lose a box that only ever 401'd for them. On a failed call the box stays hidden rather than falling back to the old signed-in test, which would put it back in front of those same members. Scope: product
This commit is contained in:
@@ -252,6 +252,38 @@ def get_navigation():
|
||||
return success_response(all_items)
|
||||
|
||||
|
||||
@dashboard_bp.route('/capabilities', methods=['GET'])
|
||||
def get_capabilities():
|
||||
"""What THIS caller can reach, for chrome that would otherwise only 401.
|
||||
|
||||
The sidebar search box was gated on being signed in, because a box that
|
||||
can only answer 401 is worse than no box. That stopped being the right
|
||||
test once the guest role could be granted assets.view: a signed-out
|
||||
visitor at a machine may now search for the asset number in front of them,
|
||||
and the box stayed hidden from exactly the person it was re-opened for.
|
||||
|
||||
The client cannot answer this itself. Its hasPermission getter reads the
|
||||
signed-in user's permission list, and a guest has no user at all, so
|
||||
asking it about a guest returns false for everyone. The navigation route
|
||||
above has the same problem and solves it the same way: the server knows
|
||||
what the guest role holds, so the server decides.
|
||||
|
||||
Public, and deliberately so - it is the pre-login call that decides
|
||||
whether the box is drawn. It reports only booleans about the caller, never
|
||||
what the guest role holds in general, so it says nothing to an anonymous
|
||||
reader that the rendered page does not already.
|
||||
"""
|
||||
from flask_jwt_extended import verify_jwt_in_request
|
||||
from shopdb.utils.authz import caller_holds
|
||||
|
||||
verify_jwt_in_request(optional=True)
|
||||
return success_response({
|
||||
# Global search is gated on assets.view, and each domain behind it now
|
||||
# gates on its own permission, so holding this reaches assets alone.
|
||||
'cansearch': caller_holds('assets.view'),
|
||||
})
|
||||
|
||||
|
||||
@dashboard_bp.route('/widgets', methods=['GET'])
|
||||
@require_permission('assets.view')
|
||||
def get_widgets():
|
||||
|
||||
Reference in New Issue
Block a user