From 1e223e7b575fc505b568f549b55d2ba6696d4ec2 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Fri, 27 Dec 2019 16:07:29 +0100 Subject: [PATCH] add default uri roles --- messages/v1/messages/uri.role.join.yml | 4 +- messages/v1/types/uri.role.yml | 4 +- src/risotto/services/uri/uri.py | 65 ++++++++++++++++++++++++-- 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/messages/v1/messages/uri.role.join.yml b/messages/v1/messages/uri.role.join.yml index 6da97e6..9198770 100644 --- a/messages/v1/messages/uri.role.join.yml +++ b/messages/v1/messages/uri.role.join.yml @@ -8,10 +8,10 @@ pattern: rpc parameters: role_name: type: String - shortarg: n + shortarg: r description: Nom du rôle. ref: User.RoleName - uri: + uri_name: type: String shortarg: u description: Nom du message. diff --git a/messages/v1/types/uri.role.yml b/messages/v1/types/uri.role.yml index 26aaa82..b83fabc 100644 --- a/messages/v1/types/uri.role.yml +++ b/messages/v1/types/uri.role.yml @@ -7,9 +7,9 @@ properties: type: string description: Nom du rôle ref: User.RoleName - uri: + uri_name: type: string description: Nom du message required: - role_name - - uri + - uri_name diff --git a/src/risotto/services/uri/uri.py b/src/risotto/services/uri/uri.py index 6c9ca34..0959197 100644 --- a/src/risotto/services/uri/uri.py +++ b/src/risotto/services/uri/uri.py @@ -7,11 +7,67 @@ from ...utils import _ class Risotto(Controller): + async def on_join(self, + risotto_context): + for uri in ['v1.applicationservice.create', + 'v1.applicationservice.dataset.updated', + 'v1.server.create', + 'v1.servermodel.dataset.updated', + 'v1.session.server.start', + 'v1.source.create', + 'v1.source.dataset.update', + 'v1.source.release.create', + 'v1.template.generate', + 'v1.uri.role.join', + 'v1.uri.role.list', + 'v1.user.create', + 'v1.user.delete', + 'v1.user.list', + 'v1.user.role.create', + 'v1.user.role.list']: + try: + await self.call('v1.uri.role.join', + risotto_context, + role_name='administrator', + uri_name=uri) + except: + pass + for uri in ['v1.applicationservice.describe', + 'v1.applicationservice.get_by_id', + 'v1.server.describe', + 'v1.server.list', + 'v1.servermodel.list', + 'v1.session.server.configure', + 'v1.session.server.filter', + 'v1.session.server.get', + 'v1.session.server.list', + 'v1.session.servermodel.configure', + 'v1.session.servermodel.filter', + 'v1.session.servermodel.get', + 'v1.session.servermodel.list', + 'v1.session.servermodel.start', + 'v1.session.servermodel.stop', + 'v1.session.servermodel.validate', + 'v1.session.server.stop', + 'v1.session.server.validate', + 'v1.source.describe', + 'v1.source.list', + 'v1.source.release.get_by_distribution', + 'v1.source.release.get_by_id', + 'v1.source.release.list']: + try: + await self.call('v1.uri.role.join', + risotto_context, + role_name='all', + uri_name=uri) + except: + pass + @register('v1.uri.role.join', None, database=True) async def uri_role_join(self, risotto_context: Context, role_name: str, - uri: str) -> Dict: + uri_name: str) -> Dict: # Verify if user exists and get ID sql = ''' SELECT URIId @@ -19,18 +75,19 @@ class Risotto(Controller): WHERE URIName = $1 ''' uri_id = await risotto_context.connection.fetchval(sql, - uri) + uri_name) if uri_id is None: - raise Exception(_(f'unable to find message {uri}')) + raise Exception(_(f'unable to find message {uri_name}')) sql = ''' INSERT INTO RoleURI(RoleName, URIId) VALUES ($1,$2) + ON CONFLICT DO NOTHING ''' uri_id = await risotto_context.connection.fetchrow(sql, role_name, uri_id) return {'role_name': role_name, - 'uri': uri} + 'uri_name': uri_name} @register('v1.uri.role.list', None, database=True) async def uri_role_list(self,