Ajout de fonctions CRUD
This commit is contained in:
parent
01f4557c22
commit
73b8d4f159
1 changed files with 100 additions and 22 deletions
122
crud_cli.py
122
crud_cli.py
|
@ -143,8 +143,24 @@ def delete_role():
|
|||
|
||||
|
||||
def add_permission():
|
||||
resource_id = int(input('Resource ID: '))
|
||||
role_id = int(input('Role ID: '))
|
||||
conf_resource = 'n'
|
||||
conf_role = 'n'
|
||||
resource_id = None
|
||||
role_id = None
|
||||
while not conf_resource == 'y':
|
||||
resource_id = int(input('Resource ID: '))
|
||||
resource = Resource.get(id=resource_id)
|
||||
print(f'Resource name: {resource.name}')
|
||||
conf_resource = input('Is this OK? (y)')
|
||||
if conf_resource == '':
|
||||
conf_resource = 'y'
|
||||
while not conf_role == 'y':
|
||||
role_id = int(input('Role ID: '))
|
||||
role = Role.get(id=role_id)
|
||||
print(f'Role name: {role.name}')
|
||||
conf_role = input('Is this OK? (y)')
|
||||
if conf_role == '':
|
||||
conf_role = 'y'
|
||||
name = input('Permission Name: ')
|
||||
description = input('Permission Description: ')
|
||||
permission_model = PermissionModel(name=name, idResource=resource_id, idRole=role_id, description=description)
|
||||
|
@ -177,16 +193,32 @@ def edit_permission():
|
|||
if description == '':
|
||||
description = permission.description
|
||||
# Editing resource
|
||||
resource_id = input(f'Resource ID [{permission.idResource}]: ')
|
||||
if resource_id == '':
|
||||
resource_id = permission.idResource
|
||||
conf_resource = 'n'
|
||||
while not conf_resource == 'y':
|
||||
resource_id = input(f'Resource ID [{permission.idResource}]: ')
|
||||
if resource_id == '':
|
||||
resource_id = permission.idResource
|
||||
resource = Resource.get(id=resource_id)
|
||||
print(f'Resource name: {resource.name}')
|
||||
conf_resource = input('Is this OK? (y)')
|
||||
if conf_resource == '':
|
||||
conf_resource = 'y'
|
||||
# Editing role
|
||||
role_id = input(f'Role ID [{permission.idRole}]: ')
|
||||
if role_id == '':
|
||||
role_id = permission.idRole
|
||||
conf_role = 'n'
|
||||
while not conf_role == 'y':
|
||||
role_id = input(f'Role ID [{permission.idRole}]: ')
|
||||
if role_id == '':
|
||||
role_id = permission.idRole
|
||||
role = Role.get(id=role_id)
|
||||
print(f'Role name: {role.name}')
|
||||
conf_role = input('Is this OK? (y)')
|
||||
if conf_role == '':
|
||||
conf_role = 'y'
|
||||
# Editing permission
|
||||
print('Editing Permission...')
|
||||
db_edit_permission(permission_id, permission_model=PermissionModel(name=name, idResource=resource_id, idRole=role_id, description=description))
|
||||
db_edit_permission(permission_id,
|
||||
permission_model=PermissionModel(name=name, idResource=resource_id, idRole=role_id,
|
||||
description=description))
|
||||
print('Permission edited')
|
||||
return None
|
||||
|
||||
|
@ -201,11 +233,36 @@ def delete_permission():
|
|||
|
||||
def add_user_account():
|
||||
username = input('Username: ')
|
||||
person_id = int(input('Person ID: '))
|
||||
resource_id = int(input('Resource ID: '))
|
||||
role_id = int(input('Role ID: '))
|
||||
conf_person = 'n'
|
||||
conf_resource = 'n'
|
||||
conf_role = 'n'
|
||||
person_id = None
|
||||
resource_id = None
|
||||
role_id = None
|
||||
while not conf_person == 'y':
|
||||
person_id = int(input('Person ID: '))
|
||||
person = Person.get(id=person_id)
|
||||
print(f'Person name: {person.first_name} {person.last_name}')
|
||||
conf_person = input('Is this OK? (y)')
|
||||
if conf_person == '':
|
||||
conf_person = 'y'
|
||||
while not conf_resource == 'y':
|
||||
resource_id = int(input('Resource ID: '))
|
||||
resource = Resource.get(id=resource_id)
|
||||
print(f'Resource name: {resource.name}')
|
||||
conf_resource = input('Is this OK? (y)')
|
||||
if conf_resource == '':
|
||||
conf_resource = 'y'
|
||||
while not conf_role == 'y':
|
||||
role_id = int(input('Role ID: '))
|
||||
role = Role.get(id=role_id)
|
||||
print(f'Role name: {role.name}')
|
||||
conf_role = input('Is this OK? (y)')
|
||||
if conf_role == '':
|
||||
conf_role = 'y'
|
||||
date = datetime.date.fromisoformat(input('Date (YYYY-MM-DD): '))
|
||||
user_account_model = UserAccountModel(username=username, idPerson=person_id, idResource=resource_id, idRole=role_id, date=date)
|
||||
user_account_model = UserAccountModel(username=username, idPerson=person_id, idResource=resource_id, idRole=role_id,
|
||||
date=date)
|
||||
print("Adding User Account...")
|
||||
db_add_user_account(user_account_model)
|
||||
print("User Account added")
|
||||
|
@ -231,17 +288,38 @@ def edit_user_account():
|
|||
if username == '':
|
||||
username = user_account.username
|
||||
# Editing person
|
||||
person_id = input(f'User Account person ID [{user_account.idPerson}]')
|
||||
if person_id == '':
|
||||
person_id = user_account.idPerson
|
||||
conf_person = 'n'
|
||||
while not conf_person == 'y':
|
||||
person_id = input(f'User Account person ID [{user_account.idPerson}]')
|
||||
if person_id == '':
|
||||
person_id = user_account.idPerson
|
||||
person = Person.get(id=person_id)
|
||||
print(f'Person name: {person.first_name} {person.last_name}')
|
||||
conf_person = input('Is this OK? (y)')
|
||||
if conf_person == '':
|
||||
conf_person = 'y'
|
||||
# Editing resource
|
||||
resource_id = input(f'User Account resource ID [{user_account.idResource}]')
|
||||
if resource_id == '':
|
||||
resource_id = user_account.idResource
|
||||
conf_resource = 'n'
|
||||
while not conf_resource == 'y':
|
||||
resource_id = input(f'User Account resource ID [{user_account.idResource}]')
|
||||
if resource_id == '':
|
||||
resource_id = user_account.idResource
|
||||
resource = Resource.get(id=resource_id)
|
||||
print(f'Resource name: {resource.name}')
|
||||
conf_resource = input('Is this OK? (y)')
|
||||
if conf_resource == '':
|
||||
conf_resource = 'y'
|
||||
# Editing role
|
||||
role_id = input(f'User Account role ID [{user_account.idRole}]')
|
||||
if role_id == '':
|
||||
role_id = user_account.idRole
|
||||
conf_role = 'n'
|
||||
while not conf_role == 'y':
|
||||
role_id = input(f'User Account role ID [{user_account.idRole}]')
|
||||
if role_id == '':
|
||||
role_id = user_account.idRole
|
||||
role = Role.get(id=role_id)
|
||||
print(f'Role name: {role.name}')
|
||||
conf_role = input('Is this OK? (y)')
|
||||
if conf_role == '':
|
||||
conf_role = 'y'
|
||||
# Editing date
|
||||
date = datetime.date.fromisoformat(input(f'User Account date [{datetime.date.isoformat(user_account.date)}]: '))
|
||||
if date == '':
|
||||
|
|
Loading…
Reference in a new issue