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): ...@@ -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') @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): async def delete_server(self, cursor,_session_user, serverid):
try: try:
self.serverselection.remove_server_from_all_selections(cursor, serverid)
return self.server.delete_server(cursor, serverid) return self.server.delete_server(cursor, serverid)
except ServerErrorDatabaseNotAvailable as err: except ServerErrorDatabaseNotAvailable as err:
......
from .error import ServerSelectionError from .error import ServerSelectionError
from .query import (list_all_serverselections, from .query import (list_all_serverselections,
fetch_serverselection, fetch_serverselection,
fetch_serverselection_dict, fetch_serverselection_dict,
fetch_all_user_serverselections, fetch_all_user_serverselections,
fetch_default_user_serverselection, fetch_default_user_serverselection,
fetch_all_user_servers, fetch_all_user_servers,
insert_serverselection, insert_serverselection,
update_serverselection, update_serverselection,
delete_serverselection, delete_serverselection,
add_server_to_serverselection, add_server_to_serverselection,
remove_server_from_serverselection, remove_server_from_serverselection,
add_user_to_serverselection, add_user_to_serverselection,
remove_user_from_serverselection, remove_user_from_serverselection,
remove_server_from_all_serverselections,
update_user_from_serverselection, update_user_from_serverselection,
fetch_serverselection_user_role, fetch_serverselection_user_role,
fetch_serverselection_user_server_role, fetch_serverselection_user_server_role,
...@@ -20,13 +21,13 @@ from .query import (list_all_serverselections, ...@@ -20,13 +21,13 @@ from .query import (list_all_serverselections,
class ServerSelection(): class ServerSelection():
"""Serverselection Manage API """Serverselection Manage API
""" """
def list_serverselections(self, cursor): def list_serverselections(self, cursor):
"""Fetch Serverselectionss from database """Fetch Serverselectionss from database
:return: list of serverselection object :return: list of serverselection object
""" """
return list_all_serverselections(cursor) return list_all_serverselections(cursor)
def describe_serverselection(self, cursor, serverselectionid): def describe_serverselection(self, cursor, serverselectionid):
...@@ -35,21 +36,21 @@ class ServerSelection(): ...@@ -35,21 +36,21 @@ class ServerSelection():
:param `int` serverselectionid: servserverselection identifier :param `int` serverselectionid: servserverselection identifier
""" """
return fetch_serverselection_dict(cursor, serverselectionid) return fetch_serverselection_dict(cursor, serverselectionid)
def list_user_serverselections(self, cursor, username): def list_user_serverselections(self, cursor, username):
"""Get serverselections of a user """Get serverselections of a user
:param str username: user name to be add to the serverselection :param str username: user name to be add to the serverselection
""" """
return fetch_all_user_serverselections(cursor, username) return fetch_all_user_serverselections(cursor, username)
def list_user_servers(self, cursor, username): def list_user_servers(self, cursor, username):
"""Get serverselections of a user """Get serverselections of a user
:param str username: user name to be add to the serverselection :param str username: user name to be add to the serverselection
""" """
return fetch_all_user_servers(cursor, username) return fetch_all_user_servers(cursor, username)
def default_user_serverselection(self, cursor, username): def default_user_serverselection(self, cursor, username):
"""Get the default serverselection of a user """Get the default serverselection of a user
...@@ -96,66 +97,75 @@ class ServerSelection(): ...@@ -96,66 +97,75 @@ class ServerSelection():
"""Add a server to a serverselection in database """Add a server to a serverselection in database
:param int serverid: server identifier :param int serverid: server identifier
:param int serverselectionid: serverselection identifier :param int serverselectionid: serverselection identifier
:return bool: True for addition success, False either :return bool: True for addition success, False either
""" """
return add_server_to_serverselection(cursor, serverid, serverselectionid) return add_server_to_serverselection(cursor, serverid, serverselectionid)
def remove_server_from_selection(self, cursor, serverid, serverselectionid): def remove_server_from_selection(self, cursor, serverid, serverselectionid):
"""Remove a server from a serverselection in database """Remove a server from a serverselection in database
:param int serverid: server identifier :param int serverid: server identifier
:param int serverselectionid: serverselection identifier :param int serverselectionid: serverselection identifier
:return bool: True for addition success, False either :return bool: True for addition success, False either
""" """
return remove_server_from_serverselection(cursor, serverid, serverselectionid) 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): def add_user_to_serverselection(self, cursor, serverselectionid, username, role):
"""Add a user to a serverselection """Add a user to a serverselection
:param int serverid: server identifier :param int serverid: server identifier
:param str username: user name to be add to the serverseleciton :param str username: user name to be add to the serverseleciton
:param str role: user role to be add to the serverseleciton :param str role: user role to be add to the serverseleciton
:return bool: True for addition success, False either :return bool: True for addition success, False either
""" """
return add_user_to_serverselection(cursor, serverselectionid, username, role) return add_user_to_serverselection(cursor, serverselectionid, username, role)
def remove_user_from_serverselection(self, cursor, serverselectionid, username): def remove_user_from_serverselection(self, cursor, serverselectionid, username):
"""Remove a user from a serverselection """Remove a user from a serverselection
:param int serverid: server identifier :param int serverid: server identifier
:param int serverselectionid: serverselection identifier :param int serverselectionid: serverselection identifier
:param str username: user name to be add to the serverseleciton :param str username: user name to be add to the serverseleciton
:return bool: True for addition success, False either :return bool: True for addition success, False either
""" """
return remove_user_from_serverselection(cursor, serverselectionid, username) return remove_user_from_serverselection(cursor, serverselectionid, username)
def update_user_to_serverselection(self, cursor, serverselectionid, username, role): def update_user_to_serverselection(self, cursor, serverselectionid, username, role):
"""Update a user from a serverselection """Update a user from a serverselection
:param int serverid: server identifier :param int serverid: server identifier
:param str username: user name to be add to the serverseleciton :param str username: user name to be add to the serverseleciton
:param str role: user role to be add to the serverseleciton :param str role: user role to be add to the serverseleciton
:return bool: True for addition success, False either :return bool: True for addition success, False either
""" """
return update_user_from_serverselection(cursor, serverselectionid, username, role) return update_user_from_serverselection(cursor, serverselectionid, username, role)
def get_serverselection_user_role(self, cursor, serverselectionid, username): def get_serverselection_user_role(self, cursor, serverselectionid, username):
"""Update a user from a serverselection """Update a user from a serverselection
:param int serverid: server identifier :param int serverid: server identifier
:param str username: user name to be add to the serverseleciton :param str username: user name to be add to the serverseleciton
:param str role: user role to be add to the serverseleciton :param str role: user role to be add to the serverseleciton
:return bool: True for addition success, False either :return bool: True for addition success, False either
""" """
return fetch_serverselection_user_role(cursor, username, serverselectionid) return fetch_serverselection_user_role(cursor, username, serverselectionid)
def get_serverselection_user_server_role(self, cursor, serverid, username): def get_serverselection_user_server_role(self, cursor, serverid, username):
"""Update a user from a serverselection """Update a user from a serverselection
:param int serverid: server identifier :param int serverid: server identifier
:param str username: user name to be add to the serverseleciton :param str username: user name to be add to the serverseleciton
:param str role: user role to be add to the serverseleciton :param str role: user role to be add to the serverseleciton
:return bool: True for addition success, False either :return bool: True for addition success, False either
""" """
return fetch_serverselection_user_server_role(cursor, username, serverid) return fetch_serverselection_user_server_role(cursor, username, serverid)
...@@ -90,6 +90,17 @@ SERVERSELECTION_REMOVE_SERVER = ''' ...@@ -90,6 +90,17 @@ SERVERSELECTION_REMOVE_SERVER = '''
WHERE serverselectionid = %s WHERE serverselectionid = %s
RETURNING * 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 Add User and Role to serverselection
...@@ -265,6 +276,10 @@ def add_server_to_serverselection(cursor, serverselectionserversid, serverselect ...@@ -265,6 +276,10 @@ def add_server_to_serverselection(cursor, serverselectionserversid, serverselect
def remove_server_from_serverselection(cursor, serverselectionserversid, serverselectionid): def remove_server_from_serverselection(cursor, serverselectionserversid, serverselectionid):
return serverselection_row_to_dict(fetchone(cursor, SERVERSELECTION_REMOVE_SERVER, (serverselectionserversid, serverselectionid), raises=True)) 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): def add_user_to_serverselection(cursor, serverselectionid, username, role):
serverselectionuserrolehstore = username + '=>' + role serverselectionuserrolehstore = username + '=>' + role
return serverselection_row_to_dict(fetchone(cursor, SERVERSELECTION_ADD_USER, (serverselectionuserrolehstore, serverselectionid), raises=True)) 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