Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def decorated_view(request, *args, **kwargs):
user = request.user
if user.is_anonymous:
return reject_request(request)
if user.has_perms(['wagtailadmin.access_admin']):
preferred_language = None
if hasattr(user, 'wagtail_userprofile'):
preferred_language = user.wagtail_userprofile.get_preferred_language()
l18n.set_language(preferred_language)
time_zone = user.wagtail_userprofile.get_current_time_zone()
activate_tz(time_zone)
if preferred_language:
with override(preferred_language):
return view_func(request, *args, **kwargs)
else:
return view_func(request, *args, **kwargs)
if not request.is_ajax():
messages.error(request, _('You do not have permission to access the admin'))
return reject_request(request)