def require_perms(view_func, required):
 from horizon.exceptions import NotAuthorized
 current_perms = getattr(view_func, '_required_perms', set([]))
 view_func._required_perms = (current_perms | set(required))
 @functools.wraps(view_func, assigned=available_attrs(view_func))
 def dec(request, *args, **kwargs):
  if request.user.is_authenticated():
   if request.user.has_perms(view_func._required_perms):
    return view_func(request, *args, **kwargs)
  raise NotAuthorized((_('You are not authorized to access %s') % request.path))
 if required:
  return dec
 else:
  return view_func

def require_perms ( view_func , required ) : from horizon . exceptions import NotAuthorized current_perms = getattr ( view_func , '_required_perms' , set ( [ ] ) ) view_func . _required_perms = ( current_perms | set ( required ) ) @ functools . wraps ( view_func , assigned = available_attrs ( view_func ) ) def dec ( request , * args , ** kwargs ) : if request . user . is_authenticated ( ) : if request . user . has_perms ( view_func . _required_perms ) : return view_func ( request , * args , ** kwargs ) raise NotAuthorized ( ( _ ( 'You are not authorized to access %s' ) % request . path ) ) if required : return dec else : return view_func
enforces permission-based access controls .