added bypass plugin detection to preferences

This commit is contained in:
Adolfo Gómez García 2015-03-26 17:31:40 +01:00
parent 151623e407
commit c7d3e4022f
7 changed files with 75 additions and 12 deletions

View File

@ -76,10 +76,10 @@ class UserPrefsManager(object):
def getHtmlForUserPreferences(self, user):
# First fill data for all preferences
data = {}
for up in user.preferences.all():
for up in user.preferences.all().order_by('module'):
data[self.__nameFor(up.module, up.name)] = up.value
res = ''
for mod, v in self._prefs.iteritems():
for mod, v in sorted(self._prefs.iteritems()):
form = forms.Form()
for p in v['prefs']:
name = self.__nameFor(mod, p.getName())
@ -166,12 +166,12 @@ class UserPreference(object):
'''
Returns a form field to add to the preferences form
'''
raise NameError('Can\'t create an abstract preference!!!')
raise NotImplementedError('Can\'t create an abstract preference!!!')
def guiField(self):
'''
'''
raise NameError('Can\'t create an abstract preference!!!')
raise NotImplementedError('Can\'t create an abstract preference!!!')
class UserTextPreference(UserPreference):
@ -225,6 +225,12 @@ class UserCheckboxPreference(UserPreference):
def __init__(self, **kwargs):
super(self.__class__, self).__init__(**kwargs)
def formField(self, value):
if value is None:
value = False
logger.debug('Value type: {}'.format(type(value)))
return forms.BooleanField(label=_(self._label), initial=value)
class CommonPrefs(object):
SZ_PREF = 'screenSize'
@ -241,6 +247,8 @@ class CommonPrefs(object):
DEPTH_24 = '3'
DEPTH_32 = '4'
BYPASS_PREF = 'bypassPluginDetection'
@staticmethod
def getWidthHeight(prefsDict):
'''
@ -284,3 +292,10 @@ class CommonPrefs(object):
(DEPTH_24, ugettext_lazy('24 bits')),
(DEPTH_32, ugettext_lazy('32 bits')))
)
bypassPluginDetectionPref = UserChoicePreference(name=BYPASS_PREF,
label=ugettext_lazy('Plugin detection'),
defvalue='0',
values=(('0', ugettext_lazy('Detect plugin')),
('1', ugettext_lazy('Bypass plugin detection')))
)

View File

@ -26,7 +26,7 @@ uds.firefox = false
blockUI = (message) ->
message = message or "<h1><span class=\"fa fa-spinner fa-spin\"></span> " + gettext("Just a moment...") + "</h1>"
message = message or "<h1><span class=\"fa fa-spinner fa-spin\"></span> " + gettext("Contacting service...") + "</h1>"
$.blockUI
message: message
return
@ -112,6 +112,7 @@ launchMozilla = (el, url, alt) ->
iFrame = $('#hiddenUdsLauncherIFrame')[0]
isSupported = false
#Set iframe.src and handle exception
console.log "Launching " + url
try
iFrame.contentWindow.location.href = url
isSupported = true
@ -181,7 +182,13 @@ uds.launch = (el) ->
dataType: "json"
success: (data) ->
unblockUI()
alert data
if data.error? and data.error isnt ''
alert data.error
else
if bypassPluginDetection is false
uds.doLaunch el, data.url, alt
else
window.location = data.url
return
error: (jqXHR, textStatus, errorThrown) ->
@ -192,6 +199,7 @@ uds.launch = (el) ->
return
uds.doLaunch = (el, url, alt) ->
if uds.firefox
launchMozilla el, url, alt
else if uds.chrome

View File

@ -91,7 +91,10 @@
<script src="{% get_static_prefix %}js/bootstrap.min.js"></script>
<script src="{% get_static_prefix %}js/bootstrap-switch.min.js"></script>
<script src="{% get_static_prefix %}js/bootstrap-select.min.js"></script>
<script>var clientRest = "/" + "{% url 'ClientAccessEnabler' 'x' 'x' %}".split("/")[1];</script>
<script>
var clientRest = "/" + "{% url 'ClientAccessEnabler' 'x' 'x' %}".split("/")[1];
var bypassPluginDetection = {% preference _uds.bypassPluginDetection %} != 0;
</script>
<script type="text/coffeescript" charset="utf-8" src="{% get_static_prefix %}js/uds-client.coffee"></script>
<script>

View File

@ -38,6 +38,7 @@ from uds.core.util.request import getRequest
from uds.core.auths.auth import ROOT_ID
from uds.core.util.Config import GlobalConfig
from uds.models.Image import Image
from uds.core.managers.UserPrefsManager import UserPrefsManager
import logging
@ -115,6 +116,30 @@ def tabindex(parser, token):
return TabIndex(tabIndexName)
class Preference(template.Node):
def __init__(self, modName, prefName):
self.modName = modName
self.prefName = prefName
def render(self, context):
prefs = context['user'].prefs(self.modName)
return prefs.get(self.prefName)
@register.tag(name='preference')
def preference(parser, token):
try:
# split_contents() knows not to split quoted strings.
tag_name, rest = token.split_contents()
modName, prefName = rest.split('.')
except ValueError:
raise template.TemplateSyntaxError(
"%r tag requires a single argument" % token.contents.split()[0]
)
return Preference(modName, prefName)
@register.assignment_tag
def preferences_allowed():
return GlobalConfig.PREFERENCES_ALLOWED.getBool(True)

View File

@ -30,7 +30,10 @@
'''
from __future__ import unicode_literals
__updated__ = '2015-03-20'
__updated__ = '2015-03-26'
from uds.core.managers.UserPrefsManager import UserPrefsManager, CommonPrefs
from django.utils.translation import ugettext_noop
from django.shortcuts import render_to_response
from django.template import RequestContext
@ -44,6 +47,15 @@ import logging
logger = logging.getLogger(__name__)
UserPrefsManager.manager().registerPrefs(
'_uds',
ugettext_noop('UDS Plugin preferences'),
[
CommonPrefs.bypassPluginDetectionPref
]
)
@webLoginRequired(admin=False)
def client_downloads(request, os=None):
'''

View File

@ -30,7 +30,7 @@
'''
from __future__ import unicode_literals
__updated__ = '2015-02-28'
__updated__ = '2015-03-26'
from django.http import HttpResponseForbidden
from django.shortcuts import render_to_response

View File

@ -210,7 +210,7 @@ def clientEnabler(request, idService, idTransport):
# Maybe we could even protect this even more by limiting referer to own server /? (just a meditation..)
response = ''
url = ''
error = _('Service not ready. Please, try again in a while.')
try:
res = getService(request, idService, idTransport)
@ -230,9 +230,9 @@ def clientEnabler(request, idService, idTransport):
ticket = TicketStore.create(data)
error = ''
response = html.udsLink(request, ticket, scrambler)
url = html.udsLink(request, ticket, scrambler)
except Exception as e:
error = six.text_type(e)
# Not ready, show message and return to this page in a while
return HttpResponse('{{ "response": "{}", "error": "{}" }}'.format(response, error), content_type='application/json')
return HttpResponse('{{ "url": "{}", "error": "{}" }}'.format(url, error), content_type='application/json')