Allowing admins to disable the diable key

This commit is contained in:
Mohamed ElKalioby
2019-05-19 16:08:32 +03:00
parent 7c2958bebf
commit 1f3fca0f48
5 changed files with 17 additions and 5 deletions

4
mfa/CHANGELOG.md Normal file
View File

@@ -0,0 +1,4 @@
# Change Log
## v1.2.0
* Added: MFA_HIDE_DISABLE setting option to disable users from deactivating their keys.

View File

@@ -20,6 +20,7 @@
$("#modal-footer").prepend("<button id='actionBtn' class='btn btn-danger' onclick='confirmDel("+id+")'>Confirm Deletion</button>")
$("#popUpModal").modal()
}
{% if not HIDE_DISABLE %}
function toggleKey(id) {
$.ajax({
url:"{% url 'toggle_key' %}?id="+id,
@@ -33,6 +34,7 @@
}
})
}
{% endif %}
</script>
<link href="{% static 'mfa/css/bootstrap-toggle.min.css' %}" rel="stylesheet">
<script src="{% static 'mfa/js/bootstrap-toggle.min.js'%}"></script>
@@ -87,7 +89,11 @@
<td>{{ key.expires }}</td>
<td>{% if key.device %}{{ key.device }}{% endif %}</td>
<td>{{ key.last_used }}</td>
<td><input type="checkbox" id="toggle_{{ key.id }}" {% if key.enabled %}checked{% endif %} data-onstyle="success" data-offstyle="danger" onchange="toggleKey({{ key.id }})" data-toggle="toggle"></td>
{% if key.key_type in HIDE_DISABLE %}
<td>{% if key.enabled %}On{% else %} Off{% endif %}</td>
{% else %}
<td><input type="checkbox" id="toggle_{{ key.id }}" {% if key.enabled %}checked{% endif %} data-onstyle="success" data-offstyle="danger" onchange="toggleKey({{ key.id }})" data-toggle="toggle" class="status_chk"></td>
{% endif %}
<td><a href="javascript:void(0)" onclick="deleteKey({{ key.id }},'{{ key.key_type }}')"> <span class="fa fa-trash"></span></a></td>
</tr>
{% empty %}

View File

@@ -12,14 +12,15 @@ from . import TrustedDevice
from user_agents import parse
def index(request):
keys=[]
context={"keys":User_Keys.objects.filter(username=request.user.username),"UNALLOWED_AUTHEN_METHODS":settings.MFA_UNALLOWED_METHODS}
context={"keys":User_Keys.objects.filter(username=request.user.username),"UNALLOWED_AUTHEN_METHODS":settings.MFA_UNALLOWED_METHODS
,"HIDE_DISABLE":getattr(settings,"MFA_HIDE_DISABLE",[])}
for k in context["keys"]:
if k.key_type =="Trusted Device" :
setattr(k,"device",parse(k.properties.get("user_agent","-----")))
elif k.key_type == "FIDO2":
setattr(k,"device",k.properties.get("type","----"))
keys.append(k)
context["keys"]=keys
context["keys"]=keys
return render_to_response("MFA.html",context,context_instance=RequestContext(request))
def verify(request,username):