Fixed staff dashboard showing

Added test method for services & authenticators
This commit is contained in:
Adolfo Gómez 2014-03-19 02:39:56 +00:00
parent 5d984fb94e
commit cf2051b8f2
8 changed files with 118 additions and 65 deletions

View File

@ -116,3 +116,17 @@ class Authenticators(ModelHandler):
return auth.searchGroups(term)
except:
self.invalidRequestException()
def test(self, type_):
from uds.core.Environment import Environment
authType = auths.factory().lookup(type_)
dct = self._params.copy()
dct['_request'] = self._request
res = authType.test(Environment.getTempEnv(), dct)
if res[0]:
return 'ok'
else:
return res[1]

View File

@ -109,3 +109,13 @@ class Providers(ModelHandler):
return DetailServices.serviceToDict(Service.objects.get(pk=self._args[1]), True)
except:
raise RequestError(ugettext('Service not found'))
def test(self, type_):
from uds.core.Environment import Environment
spType = services.factory().lookup(type_)
res = spType.test(Environment.getTempEnv(), self._params)
if res[0]:
return 'ok'
else:
return res[1]

View File

@ -83,8 +83,6 @@ def getServicesPoolsCounters(servicePool, counter_type):
class System(Handler):
needs_admin = True # By default, staff is lower level needed
def get(self):
logger.debug('args: {0}'.format(self._args))
if len(self._args) == 1:

View File

@ -176,6 +176,10 @@ class BaseModelHandler(Handler):
def success(self):
return 'done'
def test(self, type_):
logger.debug('Called base test for {0} --> {1}'.format(self.__class__.__name__, self._params))
return self.invalidMethodException()
# Details do not have types at all
# so, right now, we only process details petitions for Handling & tables info
@ -535,7 +539,7 @@ class ModelHandler(BaseModelHandler):
logger.debug('method POST for {0}, {1}'.format(self.__class__.__name__, self._args))
if len(self._args) == 2:
if self._args[0] == 'test':
return 'tested'
return self.test(self._args[1])
self.invalidMethodException()

View File

@ -5,7 +5,7 @@ gui.authenticators.link = (event) ->
# Button definition to trigger "Test" action
testButton = testButton:
text: gettext("Test authenticator")
text: gettext("Test")
css: "btn-info"

View File

@ -291,7 +291,11 @@
fields = gui.forms.read(form_selector)
gui.doLog "Fields: ", fields
rest.test type, fields, ((data) ->
gui.launchModal gettext("Test result"), data,
if data == 'ok'
text = gettext("Test passed successfully")
else
text = "<b class=\"text-danger\">Test failed: #{data}</b>"
gui.launchModal gettext("Test result"), text,
actionButton: " "
return

View File

@ -46,6 +46,7 @@ import logging
logger = logging.getLogger(__name__)
def dictFromAuthType(type_):
'''
Returns a dictionary that describes the authenticator, so the administration
@ -66,6 +67,7 @@ def dictFromAuthType(type_):
'canCreateUsers' : type_.createUser != auths.Authenticator.createUser,
}
@needs_credentials
def getAuthenticatorsTypes(credentials):
'''
@ -76,6 +78,7 @@ def getAuthenticatorsTypes(credentials):
res.append(dictFromAuthType(_type))
return res
@needs_credentials
def getAuthenticators(credentials):
'''
@ -93,6 +96,7 @@ def getAuthenticators(credentials):
return res
@needs_credentials
def getAuthenticatorType(credentials, id):
'''
@ -106,6 +110,7 @@ def getAuthenticatorType(credentials, id):
except Authenticator.DoesNotExist:
raise InsertException(_('Authenticator does not exists'))
@needs_credentials
def getAuthenticatorGui(credentials, type):
'''
@ -115,6 +120,7 @@ def getAuthenticatorGui(credentials, type):
authType = auths.factory().lookup(type)
return authType.guiDescription()
@needs_credentials
def getAuthenticator(credentials, id):
'''
@ -134,12 +140,14 @@ def getAuthenticator(credentials, id):
res.append(val)
return res
@needs_credentials
def getAuthenticatorGroups(credentials, id):
'''
'''
return getRealGroups(id)
@needs_credentials
def createAuthenticator(credentials, type, data):
'''
@ -152,14 +160,14 @@ def createAuthenticator(credentials, type, data):
dict_['_request'] = credentials.request
auth = None
try:
auth = Authenticator.objects.create(name = dict_['name'], comments = dict_['comments'],
data_type = type, priority=int(dict_['priority']), small_name=dict_['smallName'])
auth = Authenticator.objects.create(name=dict_['name'], comments=dict_['comments'],
data_type=type, priority=int(dict_['priority']), small_name=dict_['smallName'])
auth.data = auth.getInstance(dict_).serialize()
auth.save()
except auths.Authenticator.ValidationException as e:
auth.delete()
raise ValidationException(str(e))
except IntegrityError: # Must be exception at creation
except IntegrityError: # Must be exception at creation
raise InsertException(_('Name %s already exists') % (dict_['name']))
except Exception as e:
logger.exception("Exception at createAuthenticator")
@ -171,6 +179,7 @@ def createAuthenticator(credentials, type, data):
# Returns true always,
return True
@needs_credentials
def modifyAuthenticator(credentials, id, data):
'''
@ -197,6 +206,7 @@ def modifyAuthenticator(credentials, id, data):
return True
@needs_credentials
def removeAuthenticator(credentials, id):
'''
@ -205,19 +215,21 @@ def removeAuthenticator(credentials, id):
Authenticator.objects.get(pk=id).delete()
return True
@needs_credentials
def testAuthenticator(credentials, type, data):
def testAuthenticator(credentials, type_, data):
'''
invokes the test function of the specified authenticator type, with the suplied data
'''
logger.debug("Testing authenticator, type: {0}, data:{1}".format(type, data))
authType = auths.factory().lookup(type)
authType = auths.factory().lookup(type_)
# We need an "temporary" environment to test this service
dict_ = dictFromData(data)
dict_['_request'] = credentials.request
res = authType.test(Environment.getTempEnv(), dict_)
return {'ok' : res[0], 'message' : res[1]}
@needs_credentials
def checkAuthenticator(credentials, id):
'''
@ -227,6 +239,7 @@ def checkAuthenticator(credentials, id):
a = auth.getInstance()
return a.check()
@needs_credentials
def searchAuthenticator(credentials, id, srchUser, srchString):
'''

View File

@ -27,6 +27,7 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''
@author: Adolfo Gómez, dkmaster at dkmon dot com
'''
@ -44,6 +45,7 @@ from uds.core import services
logger = logging.getLogger(__name__)
@needs_credentials
def getServiceProvidersTypes(credentials):
'''
@ -55,6 +57,7 @@ def getServiceProvidersTypes(credentials):
res.append(val)
return res
@needs_credentials
def getServiceProviders(credentials):
'''
@ -69,6 +72,7 @@ def getServiceProviders(credentials):
pass
return res
@needs_credentials
def getServiceProviderGui(credentials, type_):
'''
@ -77,6 +81,7 @@ def getServiceProviderGui(credentials, type_):
spType = ServiceProviderFactory.factory().lookup(type_)
return spType.guiDescription()
@needs_credentials
def getServiceProvider(credentials, id_):
'''
@ -95,6 +100,7 @@ def getServiceProvider(credentials, id_):
res.append(val)
return res
@needs_credentials
def createServiceProvider(credentials, type_, data):
'''
@ -105,19 +111,20 @@ def createServiceProvider(credentials, type_, data):
try:
dic = dictFromData(data)
# First create data without serialization, then serialies data with correct environment
sp = Provider.objects.create(name = dic['name'], comments = dic['comments'], data_type = type_)
sp = Provider.objects.create(name=dic['name'], comments=dic['comments'], data_type=type_)
sp.data = sp.getInstance(dic).serialize()
sp.save()
except services.ServiceProvider.ValidationException as e:
sp.delete()
raise ValidationException(str(e))
except IntegrityError: # Must be exception at creation
except IntegrityError: # Must be exception at creation
raise InsertException(_('Name %s already exists') % (dic['name']))
except Exception as e:
logger.exception('Unexpected exception')
raise ValidationException(str(e))
return True
@needs_credentials
def modifyServiceProvider(credentials, id_, data):
'''
@ -135,7 +142,7 @@ def modifyServiceProvider(credentials, id_, data):
prov.save()
except services.ServiceProvider.ValidationException as e:
raise ValidationException(str(e))
except IntegrityError: # Must be exception at creation
except IntegrityError: # Must be exception at creation
raise InsertException(_('Name %s already exists') % (dic['name']))
except Exception as e:
logger.exception('Unexpected exception')
@ -143,6 +150,7 @@ def modifyServiceProvider(credentials, id_, data):
return True
@needs_credentials
def removeServiceProvider(credentials, id_):
'''
@ -157,6 +165,7 @@ def removeServiceProvider(credentials, id_):
raise FindException(_('Can\'t locate the service provider') + '.' + _('Please, refresh interface'))
return True
@needs_credentials
def getOffersFromServiceProvider(credentials, type_):
'''
@ -169,6 +178,7 @@ def getOffersFromServiceProvider(credentials, type_):
res.append(val)
return res
@needs_credentials
def testServiceProvider(credentials, type_, data):
'''
@ -181,6 +191,7 @@ def testServiceProvider(credentials, type_, data):
res = spType.test(Environment.getTempEnv(), dct)
return {'ok' : res[0], 'message' : res[1]}
@needs_credentials
def checkServiceProvider(credentials, id_):
'''
@ -204,4 +215,3 @@ def registerServiceProvidersFunctions(dispatcher):
dispatcher.register_function(testServiceProvider, 'testServiceProvider')
dispatcher.register_function(checkServiceProvider, 'checkServiceProvider')