Users fix
This commit is contained in:
parent
93743bdc8e
commit
c51a9bd5ff
@ -16,9 +16,7 @@ def save(request):
|
||||
request.dbsession.add(item)
|
||||
add_roles(item, json['roles'], request.dbsession)
|
||||
transaction.commit()
|
||||
item = request.dbsession.query(User).filter(User.id == item.id).first()
|
||||
roles = request.dbsession.query(Role).order_by(Role.name).all() if request.has_permission('Users') else []
|
||||
return user_info(item, roles)
|
||||
return user_info(item.id, request.dbsession, request.has_permission('Users'))
|
||||
|
||||
|
||||
@view_config(request_method='PUT', route_name='v1_users_id', renderer='json', permission='Users', trans=True)
|
||||
@ -40,9 +38,7 @@ def update(request):
|
||||
if json['password'] != '' and json['password'] != item.password:
|
||||
item.password = json['password']
|
||||
transaction.commit()
|
||||
item = request.dbsession.query(User).filter(User.id == item.id).first()
|
||||
roles = request.dbsession.query(Role).order_by(Role.name).all() if request.has_permission('Users') else []
|
||||
return user_info(item, roles)
|
||||
return user_info(item.id, request.dbsession, request.has_permission('Users'))
|
||||
|
||||
|
||||
@view_config(request_method='DELETE', route_name='v1_users_id', renderer='json', permission='Users', trans=True)
|
||||
@ -82,14 +78,12 @@ def show_id(request):
|
||||
item = request.dbsession.query(User).filter(User.name.ilike(id_)).first()
|
||||
if item is None:
|
||||
raise ValidationFailure('User name / id not found')
|
||||
roles = request.dbsession.query(Role).order_by(Role.name).all() if request.has_permission('Users') else []
|
||||
return user_info(item, roles)
|
||||
return user_info(item, request.dbsession, request.has_permission('Users'))
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='v1_users_new', renderer='json', permission='Authenticated')
|
||||
def show_blank(request):
|
||||
roles = request.dbsession.query(Role).order_by(Role.name).all() if request.has_permission('Users') else []
|
||||
return user_info(None, roles)
|
||||
return user_info(None, request.dbsession, request.has_permission('Users'))
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='v1_users_list', renderer='json', permission='Users')
|
||||
@ -106,22 +100,13 @@ def show_list(request):
|
||||
@view_config(request_method='GET', route_name='v1_users_list', renderer='json', request_param='names',
|
||||
permission='Authenticated')
|
||||
def show_name(request):
|
||||
list = request.dbsession.query(User).filter(User.locked_out == False).order_by(User.name).all()
|
||||
return [{'name': item.name} for item in list]
|
||||
list_ = request.dbsession.query(User).filter(User.locked_out == False).order_by(User.name).all()
|
||||
return [{'name': item.name} for item in list_]
|
||||
|
||||
|
||||
def user_info(item, roles):
|
||||
if item is not None:
|
||||
return {
|
||||
'id': item.id,
|
||||
'name': item.name,
|
||||
'password': '',
|
||||
'lockedOut': item.locked_out,
|
||||
'roles': [
|
||||
{'id': role.id, 'name': role.name, 'enabled': True if role in item.roles else False} for role in roles
|
||||
]
|
||||
}
|
||||
else:
|
||||
def user_info(item, dbsession, has_users_permission):
|
||||
roles = dbsession.query(Role).order_by(Role.name).all() if has_users_permission else []
|
||||
if item is None:
|
||||
return {
|
||||
'name': '',
|
||||
'password': '',
|
||||
@ -130,6 +115,17 @@ def user_info(item, roles):
|
||||
{'id': role.id, 'name': role.name, 'enabled': False} for role in roles
|
||||
]
|
||||
}
|
||||
if type(item) is uuid.UUID:
|
||||
item = dbsession.query(User).filter(User.id == item.id).first()
|
||||
return {
|
||||
'id': item.id,
|
||||
'name': item.name,
|
||||
'password': '',
|
||||
'lockedOut': item.locked_out,
|
||||
'roles': [
|
||||
{'id': role.id, 'name': role.name, 'enabled': True if role in item.roles else False} for role in roles
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
def add_roles(user, roles, dbsession):
|
||||
|
@ -22,6 +22,9 @@
|
||||
<a mat-raised-button routerLink="/roles">
|
||||
Roles
|
||||
</a>
|
||||
<a mat-raised-button routerLink="/users">
|
||||
Users
|
||||
</a>
|
||||
<a mat-raised-button routerLink="/logout" *ngIf="nameObject | async as name">
|
||||
<mat-icon>account_box</mat-icon>
|
||||
Logout {{name}}
|
||||
|
@ -25,11 +25,11 @@
|
||||
<mat-checkbox formControlName="lockedOut">Is Locked Out?</mat-checkbox>
|
||||
</div>
|
||||
<mat-divider></mat-divider>
|
||||
<div formArrayName="groups">
|
||||
<div fxLayout="row" *ngFor="let g of item.groups; index as i" [formGroupName]="i" fxLayout="row"
|
||||
<div formArrayName="roles">
|
||||
<div fxLayout="row" *ngFor="let r of item.roles; index as i" [formGroupName]="i" fxLayout="row"
|
||||
fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px">
|
||||
<mat-checkbox formControlName="group" fxFlex>{{g.name}}</mat-checkbox>
|
||||
<mat-checkbox formControlName="role" fxFlex>{{r.name}}</mat-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
Loading…
x
Reference in New Issue
Block a user