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:
......
from .error import ServerSelectionError
from .query import (list_all_serverselections,
from .query import (list_all_serverselections,
fetch_serverselection,
fetch_serverselection_dict,
fetch_all_user_serverselections,
fetch_default_user_serverselection,
fetch_all_user_servers,
insert_serverselection,
update_serverselection,
update_serverselection,
delete_serverselection,
add_server_to_serverselection,
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,
......@@ -20,13 +21,13 @@ from .query import (list_all_serverselections,
class ServerSelection():
"""Serverselection Manage API
"""
"""
def list_serverselections(self, cursor):
"""Fetch Serverselectionss from database
:return: list of serverselection object
"""
"""
return list_all_serverselections(cursor)
def describe_serverselection(self, cursor, serverselectionid):
......@@ -35,21 +36,21 @@ class ServerSelection():
:param `int` serverselectionid: servserverselection identifier
"""
return fetch_serverselection_dict(cursor, serverselectionid)
def list_user_serverselections(self, cursor, username):
"""Get serverselections of a user
:param str username: user name to be add to the serverselection
"""
return fetch_all_user_serverselections(cursor, username)
def list_user_servers(self, cursor, username):
"""Get serverselections of a user
:param str username: user name to be add to the serverselection
"""
return fetch_all_user_servers(cursor, username)
def default_user_serverselection(self, cursor, username):
"""Get the default serverselection of a user
......@@ -96,66 +97,75 @@ class ServerSelection():
"""Add a server to a serverselection in database
:param int serverid: server identifier
:param int serverselectionid: serverselection identifier
:param int serverselectionid: serverselection identifier
:return bool: True for addition success, False either
"""
return add_server_to_serverselection(cursor, serverid, serverselectionid)
def remove_server_from_selection(self, cursor, serverid, serverselectionid):
"""Remove a server from a serverselection in database
:param int serverid: server identifier
:param int serverselectionid: serverselection identifier
:param int serverselectionid: serverselection identifier
:return bool: True for addition success, False either
"""
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
:param int serverid: server identifier
: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 add_user_to_serverselection(cursor, serverselectionid, username, role)
def remove_user_from_serverselection(self, cursor, serverselectionid, username):
"""Remove a user from a serverselection
:param int serverid: server identifier
:param int serverselectionid: serverselection identifier
:param str username: user name to be add to the serverseleciton
:param int serverselectionid: serverselection identifier
:param str username: user name to be add to the serverseleciton
:return bool: True for addition success, False either
"""
return remove_user_from_serverselection(cursor, serverselectionid, username)
def update_user_to_serverselection(self, cursor, serverselectionid, username, role):
"""Update a user from a serverselection
:param int serverid: server identifier
: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 update_user_from_serverselection(cursor, serverselectionid, username, role)
def get_serverselection_user_role(self, cursor, serverselectionid, username):
"""Update a user from a serverselection
:param int serverid: server identifier
: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 fetch_serverselection_user_role(cursor, username, serverselectionid)
def get_serverselection_user_server_role(self, cursor, serverid, username):
"""Update a user from a serverselection
:param int serverid: server identifier
: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 fetch_serverselection_user_server_role(cursor, username, serverid)
......@@ -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