remove public information in message, it's remplace by role
This commit is contained in:
parent
94168554f2
commit
1ed86e035b
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
applicationservice_name:
|
||||
type: String
|
||||
|
@ -5,8 +5,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
source_name:
|
||||
type: String
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
applicationservice_name:
|
||||
type: String
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
applicationservice_id:
|
||||
type: Number
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
parameters:
|
||||
server_id:
|
||||
type: Number
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: false
|
||||
|
||||
parameters:
|
||||
server_id:
|
||||
type: Number
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
parameters:
|
||||
server_id:
|
||||
type: Number
|
||||
|
@ -5,8 +5,6 @@ description: Crée un serveur.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
server_name:
|
||||
type: String
|
||||
|
@ -5,8 +5,6 @@ description: Un serveur a été créé.
|
||||
|
||||
pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
parameters:
|
||||
type: Server
|
||||
description: Description du serveur.
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
parameters:
|
||||
server_id:
|
||||
type: Number
|
||||
|
@ -5,8 +5,6 @@ description: Retourne les attributs détaillés d’un serveur.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
server_name:
|
||||
type: String
|
||||
|
@ -4,8 +4,6 @@ uri: server.list
|
||||
description: |
|
||||
Liste les serveurs disponibles.
|
||||
|
||||
public: true
|
||||
|
||||
pattern: rpc
|
||||
|
||||
response:
|
||||
|
@ -5,8 +5,6 @@ description: Des modèles de serveur ont été créés.
|
||||
|
||||
pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
parameters:
|
||||
type: Servermodel
|
||||
description: Informations sur les modèles de serveur créés.
|
||||
|
@ -5,8 +5,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
source_name:
|
||||
type: String
|
||||
|
@ -5,8 +5,6 @@ description: Retourne les attributs détaillés d'un modèle de serveur suivant
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: false
|
||||
|
||||
parameters:
|
||||
servermodel_id:
|
||||
type: Number
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
source_id:
|
||||
type: Number
|
||||
@ -19,13 +17,3 @@ parameters:
|
||||
response:
|
||||
type: '[]Servermodel'
|
||||
description: Liste des modèles de serveur disponibles.
|
||||
|
||||
errors:
|
||||
- uri: servermodel.list.error.database_not_available
|
||||
|
||||
related:
|
||||
- servermodel.describe
|
||||
- servermodel.create
|
||||
- servermodel.update
|
||||
- servermodel.delete
|
||||
- servermodel.event
|
||||
|
@ -5,8 +5,6 @@ description: Des modèles de serveur ont été modifiés.
|
||||
|
||||
pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
parameters:
|
||||
type: 'Servermodel'
|
||||
description: Informations sur les modèles de serveur modifiés.
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
response:
|
||||
type: '[]Session'
|
||||
description: |
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
id:
|
||||
type: Number
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
ref: Config.SessionId
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
ref: Config.SessionId
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -5,8 +5,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
response:
|
||||
type: '[]Session'
|
||||
description: |
|
||||
|
@ -5,8 +5,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
id:
|
||||
type: Number
|
||||
|
@ -5,8 +5,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
ref: Config.SessionId
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
ref: Config.SessionId
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
source_name:
|
||||
type: String
|
||||
|
@ -5,8 +5,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
source_id:
|
||||
type: Number
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
source_name:
|
||||
type: String
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
response:
|
||||
type: '[]Source'
|
||||
description: Liste des sources disponibles.
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
source_id:
|
||||
type: Number
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
source_id:
|
||||
type: Number
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
release_id:
|
||||
type: Number
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
response:
|
||||
type: '[]Release'
|
||||
description: Liste des versions disponibles.
|
||||
|
@ -6,8 +6,6 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
server_name:
|
||||
type: String
|
||||
|
22
messages/v1/messages/uri.role.join.yml
Normal file
22
messages/v1/messages/uri.role.join.yml
Normal file
@ -0,0 +1,22 @@
|
||||
---
|
||||
uri: uri.role.join
|
||||
|
||||
description: Crée un rôle utilisateur.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
role_name:
|
||||
type: String
|
||||
shortarg: n
|
||||
description: Nom du rôle.
|
||||
ref: User.RoleName
|
||||
uri:
|
||||
type: String
|
||||
shortarg: u
|
||||
description: Nom du message.
|
||||
|
||||
response:
|
||||
type: URIRole
|
||||
description: Association de rôle créé.
|
||||
|
11
messages/v1/messages/uri.role.list.yml
Normal file
11
messages/v1/messages/uri.role.list.yml
Normal file
@ -0,0 +1,11 @@
|
||||
---
|
||||
uri: uri.role.list
|
||||
|
||||
description: Liste des associations d'URI et de rôle.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
response:
|
||||
type: '[]URIRole'
|
||||
description: Liste des associations.
|
||||
|
25
messages/v1/messages/user.create.yml
Normal file
25
messages/v1/messages/user.create.yml
Normal file
@ -0,0 +1,25 @@
|
||||
---
|
||||
uri: user.create
|
||||
|
||||
description: Crée un utilisateur.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
user_login:
|
||||
type: String
|
||||
shortarg: l
|
||||
description: Login de l'utilisateur.
|
||||
ref: User.Login
|
||||
user_name:
|
||||
type: String
|
||||
shortarg: n
|
||||
description: Nom de l'utilisateur.
|
||||
user_surname:
|
||||
type: String
|
||||
shortarg: s
|
||||
description: Nom de famille de l'utilisateur.
|
||||
|
||||
response:
|
||||
type: User
|
||||
description: Description de l'utilisateur créé.
|
18
messages/v1/messages/user.delete.yml
Normal file
18
messages/v1/messages/user.delete.yml
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
uri: user.delete
|
||||
|
||||
description: Supprimer un utilisateur.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
user_login:
|
||||
type: String
|
||||
shortarg: l
|
||||
description: Login de l'utilisateur.
|
||||
ref: User.Login
|
||||
|
||||
response:
|
||||
type: User
|
||||
description: Description de l'utilisateur supprimé.
|
||||
|
11
messages/v1/messages/user.list.yml
Normal file
11
messages/v1/messages/user.list.yml
Normal file
@ -0,0 +1,11 @@
|
||||
---
|
||||
uri: user.list
|
||||
|
||||
description: |
|
||||
Liste les utilisateurs disponibles.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
response:
|
||||
type: '[]User'
|
||||
description: Retourne la liste des utilisateurs.
|
32
messages/v1/messages/user.role.create.yml
Normal file
32
messages/v1/messages/user.role.create.yml
Normal file
@ -0,0 +1,32 @@
|
||||
---
|
||||
uri: user.role.create
|
||||
|
||||
description: Crée un rôle utilisateur.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
user_login:
|
||||
type: String
|
||||
shortarg: l
|
||||
description: Login de l'utilisateur.
|
||||
ref: User.UserLogin
|
||||
role_name:
|
||||
type: String
|
||||
shortarg: n
|
||||
description: Nom du rôle.
|
||||
ref: User.RoleName
|
||||
role_attribute:
|
||||
type: String
|
||||
shortarg: a
|
||||
description: Attribut contrôlé.
|
||||
default: null
|
||||
role_attribute_value:
|
||||
type: String
|
||||
shortarg: v
|
||||
description: Valeur de l'attribut contrôlé.
|
||||
default: null
|
||||
|
||||
response:
|
||||
type: Role
|
||||
description: Description du rôle créé.
|
19
messages/v1/messages/user.role.list.yml
Normal file
19
messages/v1/messages/user.role.list.yml
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
uri: user.role.list
|
||||
|
||||
description: |
|
||||
Liste les rôles disponibles.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
user_login:
|
||||
type: String
|
||||
shortarg: l
|
||||
description: Login de l'utilisateur associé.
|
||||
ref: User.RoleName
|
||||
default: null
|
||||
|
||||
response:
|
||||
type: '[]Role'
|
||||
description: Retourne la liste des rôles.
|
26
messages/v1/types/role.yml
Normal file
26
messages/v1/types/role.yml
Normal file
@ -0,0 +1,26 @@
|
||||
---
|
||||
title: Role
|
||||
type: object
|
||||
description: Description du rôle.
|
||||
properties:
|
||||
role_id:
|
||||
type: number
|
||||
description: Identifiant de l'utilisateur.
|
||||
ref: User.RoleUserId
|
||||
user_login:
|
||||
type: string
|
||||
description: Login du l'utilisateur.
|
||||
ref: User.Login
|
||||
role_name:
|
||||
type: string
|
||||
description: Nom du rôle.
|
||||
role_attribute:
|
||||
type: string
|
||||
description: Nom de l'utilisateur.
|
||||
role_attribute_value:
|
||||
type: string
|
||||
description: Valeur de l'attribut contrôlé.
|
||||
|
||||
required:
|
||||
- role_id
|
||||
- role_name
|
15
messages/v1/types/uri.role.yml
Normal file
15
messages/v1/types/uri.role.yml
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
title: URIRole
|
||||
type: object
|
||||
description: Description de l'assication du message et du rôle.
|
||||
properties:
|
||||
role_name:
|
||||
type: string
|
||||
description: Nom du rôle
|
||||
ref: User.RoleName
|
||||
uri:
|
||||
type: string
|
||||
description: Nom du message
|
||||
required:
|
||||
- role_name
|
||||
- uri
|
24
messages/v1/types/user.yml
Normal file
24
messages/v1/types/user.yml
Normal file
@ -0,0 +1,24 @@
|
||||
---
|
||||
title: User
|
||||
type: object
|
||||
description: Description de l'utilisateur.
|
||||
properties:
|
||||
user_id:
|
||||
type: number
|
||||
description: Identifiant de l'utilisateur.
|
||||
ref: User.UserId
|
||||
user_login:
|
||||
type: string
|
||||
description: Login de l'utilisateur.
|
||||
user_name:
|
||||
type: string
|
||||
description: Nom de l'utilisateur.
|
||||
user_surname:
|
||||
type: string
|
||||
description: Nom de famille de l'utilisateur.
|
||||
|
||||
required:
|
||||
- user_id
|
||||
- user_login
|
||||
- user_name
|
||||
- user_surname
|
20
messages/v1/types/userrole.yml
Normal file
20
messages/v1/types/userrole.yml
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
title: UserRole
|
||||
type: object
|
||||
description: Description de l'association du rôle et de l'utilisateur.
|
||||
properties:
|
||||
user_role_id:
|
||||
type: number
|
||||
description: Identifiant de l'association.
|
||||
ref: User.UserRoleId
|
||||
user_login:
|
||||
type: string
|
||||
description: Login de l'utilisateur.
|
||||
role_name:
|
||||
type: string
|
||||
description: Nom du rôle.
|
||||
|
||||
required:
|
||||
- user_role_id
|
||||
- user_login
|
||||
- role_name
|
@ -89,8 +89,7 @@ async def handle(request):
|
||||
async def api(request, risotto_context):
|
||||
global tiramisu
|
||||
if not tiramisu:
|
||||
config = await Config(get_messages(load_shortarg=True,
|
||||
only_public=True)[1])
|
||||
config = await Config(get_messages(load_shortarg=True)[1])
|
||||
await config.property.read_write()
|
||||
tiramisu = await config.option.dict(remotable='none')
|
||||
return tiramisu
|
||||
@ -113,11 +112,8 @@ async def get_app(loop):
|
||||
print(_('======== Registered messages ========'))
|
||||
for message in messages:
|
||||
web_message = f'/api/{version}/{message}'
|
||||
if dispatcher.messages[version][message]['public']:
|
||||
print(f' - {web_message}')
|
||||
else:
|
||||
pattern = dispatcher.messages[version][message]['pattern']
|
||||
print(f' - {web_message} (private {pattern})')
|
||||
pattern = dispatcher.messages[version][message]['pattern']
|
||||
print(f' - {web_message} ({pattern})')
|
||||
routes.append(post(web_message, handle))
|
||||
print()
|
||||
print(_('======== Registered extra routes ========'))
|
||||
|
@ -44,7 +44,6 @@ class MessageDefinition:
|
||||
'uri',
|
||||
'description',
|
||||
'parameters',
|
||||
'public',
|
||||
'errors',
|
||||
'pattern',
|
||||
'related',
|
||||
@ -54,7 +53,6 @@ class MessageDefinition:
|
||||
# default value for non mandatory key
|
||||
self.version = u''
|
||||
self.parameters = OrderedDict()
|
||||
self.public = False
|
||||
self.errors = []
|
||||
self.related = []
|
||||
self.response = None
|
||||
@ -63,10 +61,7 @@ class MessageDefinition:
|
||||
for key, value in raw_def.items():
|
||||
if isinstance(value, str):
|
||||
value = value.strip()
|
||||
if key == 'public':
|
||||
if not isinstance(value, bool):
|
||||
raise ValueError(_("{} must be a boolean, not {}").format(key, value))
|
||||
elif key == 'pattern':
|
||||
if key == 'pattern':
|
||||
if value not in ['rpc', 'event', 'error']:
|
||||
raise Exception(_('unknown pattern {}').format(value))
|
||||
elif key == 'parameters':
|
||||
@ -86,9 +81,6 @@ class MessageDefinition:
|
||||
getattr(self, key)
|
||||
except AttributeError:
|
||||
raise Exception(_('mandatory key not set {} message').format(key))
|
||||
# message with pattern = error must be public
|
||||
if self.public is False and self.pattern == 'error':
|
||||
raise Exception(_('Error message must be public : {}').format(self.uri))
|
||||
if self.uri != message:
|
||||
raise Exception(_(f'yaml file name "{message}.yml" does not match uri "{self.uri}"'))
|
||||
|
||||
@ -581,7 +573,7 @@ def _get_root_option(select_option, optiondescriptions):
|
||||
return OptionDescription('root', 'root', options_obj)
|
||||
|
||||
|
||||
def get_messages(load_shortarg=False, only_public=False):
|
||||
def get_messages(load_shortarg=False):
|
||||
"""generate description from yml files
|
||||
"""
|
||||
optiondescriptions = OrderedDict()
|
||||
@ -592,8 +584,7 @@ def get_messages(load_shortarg=False, only_public=False):
|
||||
messages.sort()
|
||||
for message_name in messages:
|
||||
message_def = get_message(message_name)
|
||||
if message_def.pattern not in ['rpc', 'event'] or \
|
||||
(not message_def.public and only_public):
|
||||
if message_def.pattern not in ['rpc', 'event']:
|
||||
continue
|
||||
optiondescriptions_name.append(message_def.uri)
|
||||
optiondescriptions_name.sort()
|
||||
@ -603,11 +594,9 @@ def get_messages(load_shortarg=False, only_public=False):
|
||||
properties=frozenset(['mandatory', 'positional']))
|
||||
for message_name in messages:
|
||||
message_def = get_message(message_name)
|
||||
if message_def.pattern not in ['rpc', 'event'] or \
|
||||
(not message_def.public and only_public):
|
||||
if message_def.pattern not in ['rpc', 'event']:
|
||||
continue
|
||||
optiondescriptions_info[message_def.uri] = {'pattern': message_def.pattern,
|
||||
'public': message_def.public}
|
||||
optiondescriptions_info[message_def.uri] = {'pattern': message_def.pattern}
|
||||
if message_def.pattern == 'rpc':
|
||||
optiondescriptions_info[message_def.uri]['response'] = _parse_responses(message_def,
|
||||
message_name)
|
||||
|
1
src/risotto/services/uri/__init__.py
Normal file
1
src/risotto/services/uri/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .uri import Risotto
|
43
src/risotto/services/uri/uri.py
Normal file
43
src/risotto/services/uri/uri.py
Normal file
@ -0,0 +1,43 @@
|
||||
from typing import Dict, List
|
||||
|
||||
from ...controller import Controller
|
||||
from ...register import register
|
||||
from ...context import Context
|
||||
from ...utils import _
|
||||
|
||||
|
||||
class Risotto(Controller):
|
||||
@register('v1.uri.role.join', None, database=True)
|
||||
async def uri_role_join(self,
|
||||
risotto_context: Context,
|
||||
role_name: str,
|
||||
uri: str) -> Dict:
|
||||
# Verify if user exists and get ID
|
||||
sql = '''
|
||||
SELECT URIId
|
||||
FROM URI
|
||||
WHERE URIName = $1
|
||||
'''
|
||||
uri_id = await risotto_context.connection.fetchval(sql,
|
||||
uri)
|
||||
if uri_id is None:
|
||||
raise Exception(_(f'unable to find message {uri}'))
|
||||
sql = '''
|
||||
INSERT INTO RoleURI(RoleName, URIId)
|
||||
VALUES ($1,$2)
|
||||
'''
|
||||
uri_id = await risotto_context.connection.fetchrow(sql,
|
||||
role_name,
|
||||
uri_id)
|
||||
return {'role_name': role_name,
|
||||
'uri': uri}
|
||||
|
||||
@register('v1.uri.role.list', None, database=True)
|
||||
async def uri_role_list(self,
|
||||
risotto_context: Context) -> List[Dict]:
|
||||
sql = '''
|
||||
SELECT RoleName as role_name, URI.URIName as uri
|
||||
FROM RoleURI, URI
|
||||
WHERE RoleURI.URIId = URI.URIId
|
||||
'''
|
||||
return [dict(r) for r in await risotto_context.connection.fetch(sql)]
|
1
src/risotto/services/user/__init__.py
Normal file
1
src/risotto/services/user/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .user import Risotto
|
143
src/risotto/services/user/user.py
Normal file
143
src/risotto/services/user/user.py
Normal file
@ -0,0 +1,143 @@
|
||||
from typing import Dict, Optional
|
||||
|
||||
from ...controller import Controller
|
||||
from ...register import register
|
||||
from ...context import Context
|
||||
from ...utils import _
|
||||
|
||||
|
||||
class Risotto(Controller):
|
||||
@register('v1.user.create', None, database=True)
|
||||
async def user_create(self,
|
||||
risotto_context: Context,
|
||||
user_login: str,
|
||||
user_name: str,
|
||||
user_surname: str) -> Dict:
|
||||
user_insert = """INSERT INTO RisottoUser(UserLogin, UserName, UserSurname)
|
||||
VALUES ($1,$2,$3)
|
||||
RETURNING UserId
|
||||
"""
|
||||
user_id = await risotto_context.connection.fetchval(user_insert,
|
||||
user_login,
|
||||
user_name,
|
||||
user_surname)
|
||||
return {'user_id': user_id,
|
||||
'user_login': user_login,
|
||||
'user_name': user_name,
|
||||
'user_surname': user_surname}
|
||||
|
||||
@register('v1.user.list', None, database=True)
|
||||
async def user_list(self,
|
||||
risotto_context: Context) -> Dict:
|
||||
sql = '''
|
||||
SELECT UserId as user_id, UserLogin as user_login, UserName as user_name, UserSurname as user_surname
|
||||
FROM RisottoUser
|
||||
'''
|
||||
users = await risotto_context.connection.fetch(sql)
|
||||
return [dict(r) for r in users]
|
||||
|
||||
@register('v1.user.delete', None, database=True)
|
||||
async def user_delete(self,
|
||||
risotto_context: Context,
|
||||
user_login: str) -> Dict:
|
||||
sql = '''
|
||||
DELETE FROM RisottoUser
|
||||
WHERE UserLogin = $1
|
||||
RETURNING UserId as user_id, UserLogin as user_login, UserName as user_name, UserSurname as user_surname
|
||||
'''
|
||||
user = await risotto_context.connection.fetchrow(sql,
|
||||
user_login)
|
||||
if user is None:
|
||||
raise Exception(_(f'unable to find user {user_login}'))
|
||||
return dict(user)
|
||||
|
||||
@register('v1.user.role.create', None, database=True)
|
||||
async def user_role_create(self,
|
||||
risotto_context: Context,
|
||||
user_login: str,
|
||||
role_name: str,
|
||||
role_attribute: str,
|
||||
role_attribute_value: str) -> Dict:
|
||||
# Verify if user exists and get ID
|
||||
sql = '''
|
||||
SELECT UserId
|
||||
FROM RisottoUser
|
||||
WHERE UserLogin = $1
|
||||
'''
|
||||
user_id = await risotto_context.connection.fetchval(sql,
|
||||
user_login)
|
||||
if user_id is None:
|
||||
raise Exception(_(f'unable to find user {user_login}'))
|
||||
sql = '''INSERT INTO UserRole(RoleUserId, RoleName, RoleAttribute, RoleAttributeValue)
|
||||
VALUES($1,$2,$3,$4)
|
||||
RETURNING RoleId
|
||||
'''
|
||||
role_id = await risotto_context.connection.fetchval(sql,
|
||||
user_id,
|
||||
role_name,
|
||||
role_attribute,
|
||||
role_attribute_value)
|
||||
return {'role_id': role_id,
|
||||
'user_login': user_login,
|
||||
'role_name': role_name,
|
||||
'role_attribute': role_attribute,
|
||||
'role_attribute_value': role_attribute_value}
|
||||
|
||||
@register('v1.user.role.list', None, database=True)
|
||||
async def user_role_list(self,
|
||||
risotto_context: Context,
|
||||
user_login: Optional[str]) -> Dict:
|
||||
if not user_login:
|
||||
sql = '''
|
||||
SELECT RoleId as role_id, RoleName as role_name, RoleAttribute as role_attribute, RoleAttributeValue as role_attribute_value, RisottoUser.UserLogin as user_login
|
||||
FROM UserRole, RisottoUser
|
||||
WHERE UserRole.RoleUserId = RisottoUser.UserId
|
||||
'''
|
||||
roles = await risotto_context.connection.fetch(sql)
|
||||
else:
|
||||
# Verify if user exists and get ID
|
||||
sql = '''
|
||||
SELECT UserId
|
||||
FROM RisottoUser
|
||||
WHERE UserLogin = $1
|
||||
'''
|
||||
user_id = await risotto_context.connection.fetchval(sql,
|
||||
user_login)
|
||||
if user_id is None:
|
||||
raise Exception(_(f'unable to find user {user_login}'))
|
||||
sql = '''
|
||||
SELECT RoleId as role_id, RoleName as role_name, RoleAttribute as role_attribute, RoleAttributeValue as role_attribute_value, RisottoUser.UserLogin as user_login
|
||||
FROM UserRole, RisottoUser
|
||||
WHERE UserRole.RoleUserId = RisottoUser.UserId AND UserRole.RoleUserId = $1
|
||||
'''
|
||||
roles = await risotto_context.connection.fetch(sql,
|
||||
user_id)
|
||||
return [dict(r) for r in roles]
|
||||
#
|
||||
# FIXME comment savoir quel role il faut supprimer ? avec attribut ou juste l'ID ?
|
||||
# @register('v1.user.role.delete', None, database=True)
|
||||
# async def user_role_delete(self,
|
||||
# risotto_context: Context,
|
||||
# user_login: str,
|
||||
# role_name: str) -> Dict:
|
||||
# # Verify if user exists and get ID
|
||||
# sql = '''
|
||||
# SELECT UserId
|
||||
# FROM RisottoUser
|
||||
# WHERE UserLogin = $1
|
||||
# '''
|
||||
# user_id = await risotto_context.connection.fetchval(sql,
|
||||
# user_login)
|
||||
# if user_id is None:
|
||||
# raise Exception(_(f'unable to find user {user_login}'))
|
||||
# sql = '''
|
||||
# DELETE FROM RisottoRole
|
||||
# WHERE RoleName = $1 AND UserId = $2
|
||||
# RETURNING RoleId as role_id, RoleName as role_name, RoleAttribute as role_attribute, RoleAttributeValue as role_attribute_value
|
||||
# '''
|
||||
# role = await risotto_context.connection.fetchrow(sql,
|
||||
# role_name,
|
||||
# user_id)
|
||||
# if role is None:
|
||||
# raise Exception(_(f'unable to find role {role_name}'))
|
||||
# return dict(role)
|
Loading…
Reference in New Issue
Block a user