Commit f2c10487 authored by Matthieu Lamalle's avatar Matthieu Lamalle

add message server.serverselection.list

parent acd7620f
Pipeline #554 passed with stage
in 0 seconds
......@@ -382,6 +382,25 @@ class ServerRunner(ZephirCommonController):
except ServerError as err:
raise ApplicationError('server.error', reason=str(err))
@register_wamp('v1.server.serverselection.list', notification_uri=None, database=True)
async def list_server_serverselections(self, cursor, serverid):
try:
return self.serverselection.list_server_serverselections(cursor, serverid)
except ServerErrorDatabaseNotAvailable as err:
raise ApplicationError('server.error.database-not-available', reason=str(err))
except ServerErrorDbConnection as err:
raise ApplicationError('server.error.db-connection', reason=str(err))
except ServerErrorInvalidServerId as err:
raise ApplicationError('server.error.invalid-server-id', reason=str(err))
except ServerErrorUnknownServerId as err:
raise ApplicationError('server.error.unknown-server-id', reason=str(err))
except ServerErrorServerNameNotProvided as err:
raise ApplicationError('server.error.servername-not-provided', reason=str(err))
except ServerError as err:
raise ApplicationError('server.error', reason=str(err))
def _list_user_servers(self, cursor, _session_user):
try:
username = _session_user['username']
......
......@@ -17,7 +17,8 @@ from .query import (list_all_serverselections,
fetch_serverselection_user_role,
fetch_serverselection_user_server_role,
erase_serverselection,
set_list_server_serverselection
set_list_server_serverselection,
list_server_serverselections
)
class ServerSelection():
......@@ -179,3 +180,11 @@ class ServerSelection():
:return bool: True for addition success, False either
"""
return fetch_serverselection_user_server_role(cursor, username, serverid)
def list_server_serverselections(self, cursor, serverid):
"""List of serverselections of a server
:param int serverid: server identifier
:return: list of serverselection
"""
return list_server_serverselections(cursor, serverid)
......@@ -173,6 +173,14 @@ FETCH_ROLE_USER_SERVER_SERVERSELECTION = '''
AND serverselectionusers->%s IS NOT NULL
'''
"""
Fetch the selections of a server
"""
FETCH_SERVER_SERVERSELECTION_LIST = '''
SELECT * FROM serverselection
WHERE %s = ANY (serverselectionserversid)
'''
"""
Suppression du contenu de la table de serverselection
"""
......@@ -303,6 +311,13 @@ def update_user_from_serverselection(cursor, serverselectionid, username, role):
serverselectionuserrolehstore = username + '=>' + role
return serverselection_row_to_dict(fetchone(cursor, SERVERSELECTION_UPDATE_USER, (serverselectionuserrolehstore, serverselectionid), raises=True))
def list_server_serverselections(cursor, serverid):
cursor.execute(FETCH_SERVER_SERVERSELECTION_LIST, (serverid,))
ret = []
for serverselection in cursor.fetchall():
ret.append(serverselection_row_to_dict(serverselection))
return ret
def erase_serverselection(cursor):
"""
Supprime le contenu de la table Serverselection
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment