1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-05 09:17:54 +03:00

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) return auth.searchGroups(term)
except: except:
self.invalidRequestException() 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) return DetailServices.serviceToDict(Service.objects.get(pk=self._args[1]), True)
except: except:
raise RequestError(ugettext('Service not found')) 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): class System(Handler):
needs_admin = True # By default, staff is lower level needed
def get(self): def get(self):
logger.debug('args: {0}'.format(self._args)) logger.debug('args: {0}'.format(self._args))
if len(self._args) == 1: if len(self._args) == 1:

View File

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

View File

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

View File

@ -291,7 +291,11 @@
fields = gui.forms.read(form_selector) fields = gui.forms.read(form_selector)
gui.doLog "Fields: ", fields gui.doLog "Fields: ", fields
rest.test type, fields, ((data) -> 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: " " actionButton: " "
return return

View File

@ -46,6 +46,7 @@ import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def dictFromAuthType(type_): def dictFromAuthType(type_):
''' '''
Returns a dictionary that describes the authenticator, so the administration Returns a dictionary that describes the authenticator, so the administration
@ -66,6 +67,7 @@ def dictFromAuthType(type_):
'canCreateUsers' : type_.createUser != auths.Authenticator.createUser, 'canCreateUsers' : type_.createUser != auths.Authenticator.createUser,
} }
@needs_credentials @needs_credentials
def getAuthenticatorsTypes(credentials): def getAuthenticatorsTypes(credentials):
''' '''
@ -76,6 +78,7 @@ def getAuthenticatorsTypes(credentials):
res.append(dictFromAuthType(_type)) res.append(dictFromAuthType(_type))
return res return res
@needs_credentials @needs_credentials
def getAuthenticators(credentials): def getAuthenticators(credentials):
''' '''
@ -93,6 +96,7 @@ def getAuthenticators(credentials):
return res return res
@needs_credentials @needs_credentials
def getAuthenticatorType(credentials, id): def getAuthenticatorType(credentials, id):
''' '''
@ -106,6 +110,7 @@ def getAuthenticatorType(credentials, id):
except Authenticator.DoesNotExist: except Authenticator.DoesNotExist:
raise InsertException(_('Authenticator does not exists')) raise InsertException(_('Authenticator does not exists'))
@needs_credentials @needs_credentials
def getAuthenticatorGui(credentials, type): def getAuthenticatorGui(credentials, type):
''' '''
@ -115,6 +120,7 @@ def getAuthenticatorGui(credentials, type):
authType = auths.factory().lookup(type) authType = auths.factory().lookup(type)
return authType.guiDescription() return authType.guiDescription()
@needs_credentials @needs_credentials
def getAuthenticator(credentials, id): def getAuthenticator(credentials, id):
''' '''
@ -134,12 +140,14 @@ def getAuthenticator(credentials, id):
res.append(val) res.append(val)
return res return res
@needs_credentials @needs_credentials
def getAuthenticatorGroups(credentials, id): def getAuthenticatorGroups(credentials, id):
''' '''
''' '''
return getRealGroups(id) return getRealGroups(id)
@needs_credentials @needs_credentials
def createAuthenticator(credentials, type, data): def createAuthenticator(credentials, type, data):
''' '''
@ -152,8 +160,8 @@ def createAuthenticator(credentials, type, data):
dict_['_request'] = credentials.request dict_['_request'] = credentials.request
auth = None auth = None
try: try:
auth = Authenticator.objects.create(name = dict_['name'], comments = dict_['comments'], auth = Authenticator.objects.create(name=dict_['name'], comments=dict_['comments'],
data_type = type, priority=int(dict_['priority']), small_name=dict_['smallName']) data_type=type, priority=int(dict_['priority']), small_name=dict_['smallName'])
auth.data = auth.getInstance(dict_).serialize() auth.data = auth.getInstance(dict_).serialize()
auth.save() auth.save()
except auths.Authenticator.ValidationException as e: except auths.Authenticator.ValidationException as e:
@ -171,6 +179,7 @@ def createAuthenticator(credentials, type, data):
# Returns true always, # Returns true always,
return True return True
@needs_credentials @needs_credentials
def modifyAuthenticator(credentials, id, data): def modifyAuthenticator(credentials, id, data):
''' '''
@ -197,6 +206,7 @@ def modifyAuthenticator(credentials, id, data):
return True return True
@needs_credentials @needs_credentials
def removeAuthenticator(credentials, id): def removeAuthenticator(credentials, id):
''' '''
@ -205,19 +215,21 @@ def removeAuthenticator(credentials, id):
Authenticator.objects.get(pk=id).delete() Authenticator.objects.get(pk=id).delete()
return True return True
@needs_credentials @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 invokes the test function of the specified authenticator type, with the suplied data
''' '''
logger.debug("Testing authenticator, type: {0}, data:{1}".format(type, 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 # We need an "temporary" environment to test this service
dict_ = dictFromData(data) dict_ = dictFromData(data)
dict_['_request'] = credentials.request dict_['_request'] = credentials.request
res = authType.test(Environment.getTempEnv(), dict_) res = authType.test(Environment.getTempEnv(), dict_)
return {'ok' : res[0], 'message' : res[1]} return {'ok' : res[0], 'message' : res[1]}
@needs_credentials @needs_credentials
def checkAuthenticator(credentials, id): def checkAuthenticator(credentials, id):
''' '''
@ -227,6 +239,7 @@ def checkAuthenticator(credentials, id):
a = auth.getInstance() a = auth.getInstance()
return a.check() return a.check()
@needs_credentials @needs_credentials
def searchAuthenticator(credentials, id, srchUser, srchString): 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 # 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. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
''' '''
@author: Adolfo Gómez, dkmaster at dkmon dot com @author: Adolfo Gómez, dkmaster at dkmon dot com
''' '''
@ -44,6 +45,7 @@ from uds.core import services
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@needs_credentials @needs_credentials
def getServiceProvidersTypes(credentials): def getServiceProvidersTypes(credentials):
''' '''
@ -55,6 +57,7 @@ def getServiceProvidersTypes(credentials):
res.append(val) res.append(val)
return res return res
@needs_credentials @needs_credentials
def getServiceProviders(credentials): def getServiceProviders(credentials):
''' '''
@ -69,6 +72,7 @@ def getServiceProviders(credentials):
pass pass
return res return res
@needs_credentials @needs_credentials
def getServiceProviderGui(credentials, type_): def getServiceProviderGui(credentials, type_):
''' '''
@ -77,6 +81,7 @@ def getServiceProviderGui(credentials, type_):
spType = ServiceProviderFactory.factory().lookup(type_) spType = ServiceProviderFactory.factory().lookup(type_)
return spType.guiDescription() return spType.guiDescription()
@needs_credentials @needs_credentials
def getServiceProvider(credentials, id_): def getServiceProvider(credentials, id_):
''' '''
@ -95,6 +100,7 @@ def getServiceProvider(credentials, id_):
res.append(val) res.append(val)
return res return res
@needs_credentials @needs_credentials
def createServiceProvider(credentials, type_, data): def createServiceProvider(credentials, type_, data):
''' '''
@ -105,7 +111,7 @@ def createServiceProvider(credentials, type_, data):
try: try:
dic = dictFromData(data) dic = dictFromData(data)
# First create data without serialization, then serialies data with correct environment # 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.data = sp.getInstance(dic).serialize()
sp.save() sp.save()
except services.ServiceProvider.ValidationException as e: except services.ServiceProvider.ValidationException as e:
@ -118,6 +124,7 @@ def createServiceProvider(credentials, type_, data):
raise ValidationException(str(e)) raise ValidationException(str(e))
return True return True
@needs_credentials @needs_credentials
def modifyServiceProvider(credentials, id_, data): def modifyServiceProvider(credentials, id_, data):
''' '''
@ -143,6 +150,7 @@ def modifyServiceProvider(credentials, id_, data):
return True return True
@needs_credentials @needs_credentials
def removeServiceProvider(credentials, id_): def removeServiceProvider(credentials, id_):
''' '''
@ -157,6 +165,7 @@ def removeServiceProvider(credentials, id_):
raise FindException(_('Can\'t locate the service provider') + '.' + _('Please, refresh interface')) raise FindException(_('Can\'t locate the service provider') + '.' + _('Please, refresh interface'))
return True return True
@needs_credentials @needs_credentials
def getOffersFromServiceProvider(credentials, type_): def getOffersFromServiceProvider(credentials, type_):
''' '''
@ -169,6 +178,7 @@ def getOffersFromServiceProvider(credentials, type_):
res.append(val) res.append(val)
return res return res
@needs_credentials @needs_credentials
def testServiceProvider(credentials, type_, data): def testServiceProvider(credentials, type_, data):
''' '''
@ -181,6 +191,7 @@ def testServiceProvider(credentials, type_, data):
res = spType.test(Environment.getTempEnv(), dct) res = spType.test(Environment.getTempEnv(), dct)
return {'ok' : res[0], 'message' : res[1]} return {'ok' : res[0], 'message' : res[1]}
@needs_credentials @needs_credentials
def checkServiceProvider(credentials, id_): def checkServiceProvider(credentials, id_):
''' '''
@ -204,4 +215,3 @@ def registerServiceProvidersFunctions(dispatcher):
dispatcher.register_function(testServiceProvider, 'testServiceProvider') dispatcher.register_function(testServiceProvider, 'testServiceProvider')
dispatcher.register_function(checkServiceProvider, 'checkServiceProvider') dispatcher.register_function(checkServiceProvider, 'checkServiceProvider')