fix layout and drop rols for public page of device

This commit is contained in:
Cayo Puigdefabregas 2023-06-02 18:24:07 +02:00
parent e3b8543a12
commit 9671333635
3 changed files with 1 additions and 121 deletions

View File

@ -46,18 +46,6 @@
<div class="row">
<div class="col">
<nav class="header-nav ms-auto">
<ul class="d-flex align-items-right">
<li class="nav-item">
{% if not rols and user.is_anonymous %}
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#validateModal">Validate</button>
{% else %}
<button class="btn btn-primary" id="buttonRol" data-bs-toggle="modal" data-bs-target="#rolsModal">Select your rol</button>
<a class="btn btn-primary" href="{{ url_for('core.logout') }}?next={{ device_real.url.to_text() }}">Logout</a>
{% endif %}
</li>
</ul>
</nav>
<div class="col-xl-12">
<div class="card">
@ -228,73 +216,5 @@
</div>
</div>
</div>
{% if user.is_anonymous and not rols %}
<div class="modal fade" id="validateModal" tabindex="-1" style="display: none;" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Validate as <span id="title-action"></span></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<a class="btn btn-primary" type="button"
href="{# url_for('core.login') #}?next={{ device_real.url.to_text() }}">
User of system
</a>
{% if oidc %}
<br />
<a class="btn btn-primary mt-3" type="button" href="{{ url_for('oidc.login_other_inventory') }}?next={{ device_real.url.to_text() }}">
User of other inventory
</a>
{% endif %}
</div>
<div class="modal-footer"></div>
</div>
</div>
</div>
{% else %}
<div class="modal fade" id="rolsModal" tabindex="-1" style="display: none;" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<form action="{{ device_real.url.to_text() }}" method="get">
<div class="modal-header">
<h5 class="modal-title">Select your Rol <span id="title-action"></span></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<select name="rol">
{% for k, v in rols %}
<option value="{{ k }}" {% if v==rol %}selected=selected{% endif %}>{{ v }}</option>
{% endfor %}
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary" value="Send" />
</div>
</form>
</div>
</div>
</div>
{% endif %}
</body>
<!-- Custom Code -->
{% if not user.is_anonymous and not rol %}
<script>
$(document).ready(() => {
$("#buttonRol").click();
});
</script>
{% endif %}
</html>

View File

@ -133,43 +133,7 @@ class DeviceView(View):
else:
return self.one_private(id)
def get_rols(self):
rols = session.get('rols')
if not g.user.is_authenticated and not rols:
return []
if rols:
return [(k, k) for k in rols]
if 'dpp' not in app.blueprints.keys():
return []
if not session.get('token_dlt'):
return []
token_dlt = session.get('token_dlt')
api_dlt = app.config.get('API_DLT')
if not token_dlt or not api_dlt:
return []
api = API(api_dlt, token_dlt, "ethereum")
result = api.check_user_roles()
if result.get('Status') != 200:
return []
if 'Success' not in result.get('Data', {}).get('status'):
return []
rols = result.get('Data', {}).get('data', {})
return [(k, k) for k, v in rols.items() if v]
def one_public(self, id: int):
rols = self.get_rols()
# rols = [("isOperator", "isOperator"), ("Inspector", "Inspector"), ("Recicler", "Recicler")]
rol = len(rols) == 1 and rols[0][0] or None
if 'rol' in request.args:
rol = dict(rols).get(request.args.get('rol'))
devices = Device.query.filter_by(devicehub_id=id, active=True).all()
if not devices:
devices = [Device.query.filter_by(dhid_bk=id, active=True).one()]
@ -184,18 +148,14 @@ class DeviceView(View):
placeholder = device.binding or device.placeholder
device_abstract = placeholder and placeholder.binding or device
device_real = placeholder and placeholder.device or device
oidc = 'oidc' in app.blueprints.keys()
return render_template(
'devices/layout.html',
oidc=oidc,
placeholder=placeholder,
device=device,
device_abstract=device_abstract,
device_real=device_real,
states=states,
abstract=abstract,
rols=rols,
rol=rol,
user=g.user,
)

View File

@ -262,7 +262,7 @@
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<form action="{{ device_real.url.to_text() }}" method="get">
<form action="{{ path }}" method="get">
<div class="modal-header">
<h5 class="modal-title">Select your Rol <span id="title-action"></span></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>