Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

12625 hide datasource password #12743

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion netbox/templates/core/datasource.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% load static %}
{% load helpers %}
{% load plugins %}
{% load perms %}
{% load render_table from django_tables2 %}

{% block extra_controls %}
Expand Down Expand Up @@ -88,7 +89,18 @@ <h5 class="card-header">Backend</h5>
{% for name, field in object.get_backend.parameters.items %}
<tr>
<th scope="row">{{ field.label }}</th>
<td>{{ object.parameters|get_key:name|placeholder }}</td>
{% if field.label == "Password" and object.parameters|get_key:name %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is going to be a viable approach. We can't rely on the field label to infer whether the parameter should be displayed. (And even if we could, hard-coding this in the template should be considered poor practice.) We should devise some approach to explicitly set some attribute on the parameter itself to control its display.

<td>
{% if request.user|can_add:object or request.user|can_change:object or request.user|can_delete:object %}
<span id="secret" class="font-monospace" data-secret="{{ object.parameters|get_key:name }}">{{ object.parameters|get_key:name|placeholder }}</span>
<button type="button" class="btn btn-sm btn-primary toggle-secret float-end" data-bs-toggle="button">Show Secret</button>
{% else %}
<i>Password Hidden</i>
{% endif %}
</td>
{% else %}
<td>{{ object.parameters|get_key:name|placeholder }}</td>
{% endif %}
</tr>
{% empty %}
<tr>
Expand Down