Commit 319e9a39 authored by Lionel Morin's avatar Lionel Morin

Merge branch 'msg_serverselection_set' into 'develop'

Msg serverselection set

See merge request !12
parents fabb64e0 61909c29
Pipeline #499 passed with stage
in 0 seconds
......@@ -7,9 +7,11 @@ p, admin, v1.serverselection.update, allowed
p, admin, v1.serverselection.delete, allowed
p, admin, v1.serverselection.server.add, allowed
p, admin, v1.serverselection.server.remove, allowed
p, admin, v1.serverselection.server.set, allowed
p, admin, v1.serverselection.user.add, allowed
p, admin, v1.serverselection.user.remove, allowed
p, admin, v1.serverselection.user.update, allowed
p, admin, v1.serverselection.user.list, allowed
p, manager, v1.server.exec.deploy, allowed
p, manager, v1.server.exec.command, allowed
......
......@@ -89,6 +89,25 @@ class ServerRunner(ZephirCommonController):
else:
return server_role
def get_profil_for_servers_list(self, cursor, uri, message_arguments):
serveridList = message_arguments['serveridlist'].split(',')
if '_session_user' not in message_arguments or message_arguments['_session_user']['profil'] == 'root':
return 'root'
else:
role=None
for server_id in serveridList :
profils = self._get_serverselection_user_server_role(cursor, server_id, message_arguments['_session_user']['username'])
if profils == []:
return None
for profil in profils:
if 'role' in profil:
role = profil['role']
if not self.policy.enforce(role, uri, 'allowed'):
return None
else:
return None
return role
@register_wamp('v1.server.list', notification_uri=None, database=True)
async def list_servers(self, cursor, _session_user):
try:
......@@ -541,6 +560,22 @@ class ServerRunner(ZephirCommonController):
except ServerSelectionError as err:
raise ApplicationError('serverselection.error', reason=str(err))
@register_wamp('v1.serverselection.server.set', notification_uri=None, database=True, profil_adapter='get_profil_for_servers_list')
async def set_serverselection_server_list(self, cursor,_session_user, serverselectionid, serveridlist):
try:
return self.serverselection.set_serverselection_server_list(cursor, serverselectionid, serveridlist)
except ServerSelectionErrorDatabaseNotAvailable as err:
raise ApplicationError('serverselection.error.database_not_available', reason=str(err))
except ServerSelectionErrorDbConnection as err:
raise ApplicationError('serverselection.error.db-connection', reason=str(err))
except ServerSelectionErrorInvalidServerSelectionId as err:
raise ApplicationError('serverselection.error.invalid_serverselection_id', reason=str(err))
except ServerSelectionErrorUnknownServerSelectionId as err:
raise ApplicationError('serverselection.error.unknown_serverselection_id', reason=str(err))
except ServerSelectionError as err:
raise ApplicationError('serverselection.error', reason=str(err))
@register_wamp('v1.serverselection.user.add', notification_uri=None, database=True, profil_adapter='get_profil_for_serverselection')
async def add_user_to_serverselection(self, cursor,_session_user, serverselectionid, username, role):
try:
......@@ -560,7 +595,7 @@ class ServerRunner(ZephirCommonController):
@register_wamp('v1.serverselection.user.remove', notification_uri=None, database=True, profil_adapter='get_profil_for_serverselection')
async def remove_user_from_serverselection(self, cursor, _session_user, serverselectionid, username):
try:
if self._get_serverselection_user_role(cursor, serverselectionid, username)['role'] != 'owner':
if self._get_serverselection_user_role(cursor, serverselectionid, username)['role'] != 'owner':
return self.serverselection.remove_user_from_serverselection(cursor, serverselectionid, username)
else:
raise Exception(_('Can not remove user with role owner from serverseleciton'))
......
......@@ -16,7 +16,8 @@ from .query import (list_all_serverselections,
update_user_from_serverselection,
fetch_serverselection_user_role,
fetch_serverselection_user_server_role,
erase_serverselection
erase_serverselection,
set_list_server_serverselection
)
class ServerSelection():
......@@ -120,6 +121,15 @@ class ServerSelection():
"""
return remove_server_from_all_serverselections(cursor, serverid)
def set_serverselection_server_list(self, cursor, serverselectionid, serveridlist):
"""Set the list of servers in a serverselection
:param int serverselectionid: serverselection identifier
:param string serveridlist: servers list
:return bool: True for addition success, False either
"""
return set_list_server_serverselection(cursor, serverselectionid, serveridlist)
def add_user_to_serverselection(self, cursor, serverselectionid, username, role):
"""Add a user to a serverselection
......
......@@ -99,6 +99,15 @@ SERVERSELECTION_REMOVE_SERVER_FROM_ALL = '''
RETURNING *
'''
"""
Set a servers list in a serverselection
"""
SERVERSELECTION_SET_SERVER_LIST = '''
UPDATE serverselection
SET serverselectionserversid = %s
WHERE serverselectionid = %s
RETURNING *
'''
......@@ -279,6 +288,9 @@ def remove_server_from_serverselection(cursor, serverselectionserversid, servers
def remove_server_from_all_serverselections(cursor, serverselectionserversid ):
return serverselection_row_to_dict(fetchone(cursor, SERVERSELECTION_REMOVE_SERVER_FROM_ALL, (serverselectionserversid,), raises=True))
def set_list_server_serverselection(cursor, serverselectionid, serveridlist):
serveridlist = '{'+serveridlist+'}'
return serverselection_row_to_dict(fetchone(cursor, SERVERSELECTION_SET_SERVER_LIST, (serveridlist,serverselectionid), raises=True))
def add_user_to_serverselection(cursor, serverselectionid, username, role):
serverselectionuserrolehstore = username + '=>' + role
......
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