Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.0]-change user scalable in different devices #6051

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions seahub/base/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,82 @@ def process_request(self, request):
if request.session.get('force_passwd_change', False):
if self._request_in_black_list(request):
return HttpResponseRedirect(reverse('auth_password_change'))

class UserAgentMiddleWare(MiddlewareMixin):
user_agents_test_match = (
"w3c ", "acs-", "alav", "alca", "amoi", "audi",
"avan", "benq", "bird", "blac", "blaz", "brew",
"cell", "cldc", "cmd-", "dang", "doco", "eric",
"hipt", "inno", "ipaq", "java", "jigs", "kddi",
"keji", "leno", "lg-c", "lg-d", "lg-g", "lge-",
"maui", "maxo", "midp", "mits", "mmef", "mobi",
"mot-", "moto", "mwbp", "nec-", "newt", "noki",
"xda", "palm", "pana", "pant", "phil", "play",
"port", "prox", "qwap", "sage", "sams", "sany",
"sch-", "sec-", "send", "seri", "sgh-", "shar",
"sie-", "siem", "smal", "smar", "sony", "sph-",
"symb", "t-mo", "teli", "tim-", "tosh", "tsm-",
"upg1", "upsi", "vk-v", "voda", "wap-", "wapa",
"wapi", "wapp", "wapr", "webc", "winw", "xda-",)
user_agents_test_search = u"(?:%s)" % u'|'.join((
'up.browser', 'up.link', 'mmp', 'symbian', 'smartphone', 'midp',
'wap', 'phone', 'windows ce', 'pda', 'mobile', 'mini', 'palm',
'netfront', 'opera mobi',
))
user_agents_exception_search = u"(?:%s)" % u'|'.join((
'ipad',
))
http_accept_regex = re.compile("application/vnd\.wap\.xhtml\+xml", re.IGNORECASE)
user_agents_android_search = u"(?:android)"
user_agents_mobile_search = u"(?:mobile)"
user_agents_tablets_search = u"(?:%s)" % u'|'.join(('ipad', 'tablet', ))

def __init__(self, get_response=None):
self.get_response = get_response

# these for detect mobile
user_agents_test_match = r'^(?:%s)' % '|'.join(self.user_agents_test_match)
self.user_agents_test_match_regex = re.compile(user_agents_test_match, re.IGNORECASE)
self.user_agents_test_search_regex = re.compile(self.user_agents_test_search, re.IGNORECASE)
self.user_agents_exception_search_regex = re.compile(self.user_agents_exception_search, re.IGNORECASE)

# these three used to detect tablet
self.user_agents_android_search_regex = re.compile(self.user_agents_android_search, re.IGNORECASE)
self.user_agents_mobile_search_regex = re.compile(self.user_agents_mobile_search, re.IGNORECASE)
self.user_agents_tablets_search_regex = re.compile(self.user_agents_tablets_search, re.IGNORECASE)

def process_request(self, request):
is_mobile = False
is_tablet = False

if 'HTTP_USER_AGENT' in request.META:
user_agent = request.META['HTTP_USER_AGENT']

# Test common mobile values.
if self.user_agents_test_search_regex.search(user_agent) and \
not self.user_agents_exception_search_regex.search(user_agent):
is_mobile = True
else:
# Nokia like test for WAP browsers.
# http://www.developershome.com/wap/xhtmlmp/xhtml_mp_tutorial.asp?page=mimeTypesFileExtension

if 'HTTP_ACCEPT' in request.META:
http_accept = request.META['HTTP_ACCEPT']
if self.http_accept_regex.search(http_accept):
is_mobile = True

if not is_mobile:
# Now we test the user_agent from a big list.
if self.user_agents_test_match_regex.match(user_agent):
is_mobile = True

# Ipad or Blackberry
if self.user_agents_tablets_search_regex.search(user_agent):
is_tablet = True
# Android-device. If User-Agent doesn't contain Mobile, then it's a tablet
elif (self.user_agents_android_search_regex.search(user_agent) and
not self.user_agents_mobile_search_regex.search(user_agent)):
is_tablet = True

request.is_mobile = is_mobile
request.is_tablet = is_tablet
1 change: 1 addition & 0 deletions seahub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
'seahub.two_factor.middleware.ForceTwoFactorAuthMiddleware',
'seahub.trusted_ip.middleware.LimitIpMiddleware',
'seahub.organizations.middleware.RedirectMiddleware',
'seahub.base.middleware.UserAgentMiddleWare',
]

SITE_ROOT_URLCONF = 'seahub.urls'
Expand Down
4 changes: 4 additions & 0 deletions seahub/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
<meta name="keywords" content="{% trans "File, Collaboration, Team, Organization" %}" />
{% if site_description != '' %}<meta name="description" content="{{ site_description }}" />{% endif %}
{% block viewport %}
{% if request.is_mobile or request.is_tablet %}
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
{% else %}
<meta name="viewport" content="width=device-width, initial-scale=1" />
{% endif %}
{% endblock %}
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<link rel="icon" href="{{ MEDIA_URL }}{{ favicon_path }}" type="image/x-icon">
Expand Down
4 changes: 4 additions & 0 deletions seahub/templates/base_for_react.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
<meta name="keywords" content="{% trans "File, Collaboration, Team, Organization" %}" />
{% if site_description != '' %}<meta name="description" content="{{ site_description }}" />{% endif %}
{% block viewport %}
{% if request.is_mobile or request.is_tablet %}
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
{% else %}
<meta name="viewport" content="width=device-width, initial-scale=1" />
{% endif %}
{% endblock %}
{% block extra_ogp_tags %}{% endblock %}
<meta http-equiv="x-ua-compatible" content="ie=edge" />
Expand Down
4 changes: 4 additions & 0 deletions seahub/templates/markdown_file_view_react.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
<html lang="{{ LANGUAGE_CODE }}">
<head>
<meta charset="UTF-8" />
{% if request.is_mobile or request.is_tablet %}
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
{% else %}
<meta name="viewport" content="width=device-width, initial-scale=1" />
{% endif %}
<title>{{ filename }}</title>

<link rel="icon" href="{{ MEDIA_URL }}{{ favicon_path }}" id="favicon" />
Expand Down
4 changes: 4 additions & 0 deletions seahub/templates/plain_markdown_file_view_react.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
<html lang="{{ LANGUAGE_CODE }}">
<head>
<meta charset="UTF-8" />
{% if request.is_mobile or request.is_tablet %}
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
{% else %}
<meta name="viewport" content="width=device-width, initial-scale=1" />
{% endif %}
<title>{{ filename }}</title>

<link rel="icon" href="{{ MEDIA_URL }}{{ favicon_path }}" id="favicon" />
Expand Down
6 changes: 5 additions & 1 deletion seahub/two_factor/templates/two_factor/_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<html>
<head>
<title>{% block title %}{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% if request.is_mobile or request.is_tablet %}
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
{% else %}
<meta name="viewport" content="width=device-width, initial-scale=1" />
{% endif %}
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.2/css/bootstrap.min.css" rel="stylesheet" media="screen">
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7/html5shiv.js"></script>
Expand Down
Loading