Commit eff70ab4 authored by Lionel Morin's avatar Lionel Morin
Browse files

Merge branch 'remove_server' into 'develop'

Remover server from all serverselection when delete server

See merge request !11
parents d10404be 01a2e007
Pipeline #386 passed with stage
in 0 seconds
......@@ -201,6 +201,7 @@ class ServerRunner(ZephirCommonController):
@register_wamp('v1.server.delete', notification_uri='v1.server.deleted', database=True, profil_adapter='get_profil_for_server')
async def delete_server(self, cursor,_session_user, serverid):
try:
self.serverselection.remove_server_from_all_selections(cursor, serverid)
return self.server.delete_server(cursor, serverid)
except ServerErrorDatabaseNotAvailable as err:
......
......@@ -12,6 +12,7 @@ from .query import (list_all_serverselections,
remove_server_from_serverselection,
add_user_to_serverselection,
remove_user_from_serverselection,
remove_server_from_all_serverselections,
update_user_from_serverselection,
fetch_serverselection_user_role,
fetch_serverselection_user_server_role,
......@@ -110,6 +111,15 @@ class ServerSelection():
"""
return remove_server_from_serverselection(cursor, serverid, serverselectionid)
def remove_server_from_all_selections(self, cursor, serverid):
"""Remove a server from a serverselection in database
:param int serverid: server identifier
:param int serverselectionid: serverselection identifier
:return bool: True for addition success, False either
"""
return remove_server_from_all_serverselections(cursor, serverid)
def add_user_to_serverselection(self, cursor, serverselectionid, username, role):
"""Add a user to a serverselection
......
......@@ -90,6 +90,17 @@ SERVERSELECTION_REMOVE_SERVER = '''
WHERE serverselectionid = %s
RETURNING *
'''
"""
Remove a server from all the serverselections
"""
SERVERSELECTION_REMOVE_SERVER_FROM_ALL = '''
UPDATE serverselection
SET serverselectionserversid = array_remove(serverselectionserversid, %s)
RETURNING *
'''
"""
Add User and Role to serverselection
......@@ -265,6 +276,10 @@ def add_server_to_serverselection(cursor, serverselectionserversid, serverselect
def remove_server_from_serverselection(cursor, serverselectionserversid, serverselectionid):
return serverselection_row_to_dict(fetchone(cursor, SERVERSELECTION_REMOVE_SERVER, (serverselectionserversid, serverselectionid), raises=True))
def remove_server_from_all_serverselections(cursor, serverselectionserversid ):
return serverselection_row_to_dict(fetchone(cursor, SERVERSELECTION_REMOVE_SERVER_FROM_ALL, (serverselectionserversid,), raises=True))
def add_user_to_serverselection(cursor, serverselectionid, username, role):
serverselectionuserrolehstore = username + '=>' + role
return serverselection_row_to_dict(fetchone(cursor, SERVERSELECTION_ADD_USER, (serverselectionuserrolehstore, serverselectionid), raises=True))
......
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