Add delete user function in frontend
This commit is contained in:
parent
fb7faddd15
commit
d673ce311d
4 changed files with 18 additions and 15 deletions
|
@ -20,6 +20,7 @@ urlpatterns = [
|
|||
path('makeuser/', views.makeuser, name='makeuser'),
|
||||
path('wifi/<int:wifi_id>/edit/', views.editwifi, name='editwifi'),
|
||||
path('wifi/<int:wifi_id>/delete/', views.deletewifi, name='deletewifi'),
|
||||
path('user/<int:user_id>/edit/', views.edituser, name='edituser'),
|
||||
path('users/<int:user_id>/edit/', views.edituser, name='edituser'),
|
||||
path('users/<int:user_id>/delete/', views.deleteuser, name='deleteuser'),
|
||||
path('update', views.update, name='update')
|
||||
]
|
||||
|
|
|
@ -453,15 +453,16 @@ def deletedevice(request, device_id):
|
|||
|
||||
@user_passes_test(is_staff)
|
||||
def deletewifi(request, wifi_id):
|
||||
wifi = get_object_or_404(Wifi, id=wifi_id)
|
||||
|
||||
for organization in Organization.objects.filter(users=request.user):
|
||||
if organization == wifi.organization:
|
||||
wifi.delete()
|
||||
break
|
||||
|
||||
wifi = get_object_or_404(Wifi, id=wifi_id, organization__in=request.user.organization_set.all())
|
||||
wifi.delete()
|
||||
return redirect("/wifi/")
|
||||
|
||||
@user_passes_test(is_superuser)
|
||||
def deleteuser(request, user_id):
|
||||
user = get_object_or_404(User, id=user_id)
|
||||
user.delete()
|
||||
return redirect("/users/")
|
||||
|
||||
@user_passes_test(is_staff)
|
||||
def makewifi(request):
|
||||
wifi_serial = request.POST.get("serial", "")
|
||||
|
|
|
@ -51,15 +51,19 @@ function updateStatus(device_id) {
|
|||
};
|
||||
|
||||
function askdelete(device_id) {
|
||||
if (confirm("Are you sure you want to delete this device?")) window.location.href = "/devices/" + device_id + "/delete";
|
||||
if (confirm("Are you sure you want to delete this Device?")) window.location.href = "/devices/" + device_id + "/delete";
|
||||
};
|
||||
|
||||
function askdeletewifi(wifi_id) {
|
||||
if (confirm("Are you sure you want to delete this WiFi?")) window.location.href = "/wifi/" + wifi_id + "/delete";
|
||||
};
|
||||
|
||||
function askdeleteuser(user_id) {
|
||||
if (confirm("Are you sure you want to delete this User?")) window.location.href = "/users/" + user_id + "/delete";
|
||||
};
|
||||
|
||||
function askreboot(device_id) {
|
||||
if (confirm("Are you sure you want to reboot this device?")) window.location.href = "/devices/" + device_id + "/reboot";
|
||||
if (confirm("Are you sure you want to reboot this Device?")) window.location.href = "/devices/" + device_id + "/reboot";
|
||||
};
|
||||
|
||||
function downloadnotice() {
|
||||
|
@ -76,7 +80,6 @@ function showdevices() {
|
|||
$("#linkusers").css("font-weight", "normal");
|
||||
|
||||
window.history.pushState("", "", "/devices/");
|
||||
return false;
|
||||
};
|
||||
|
||||
function showwifi() {
|
||||
|
@ -89,7 +92,6 @@ function showwifi() {
|
|||
$("#linkusers").css("font-weight", "normal");
|
||||
|
||||
window.history.pushState("", "", "/wifi/");
|
||||
return false;
|
||||
};
|
||||
|
||||
function showusers() {
|
||||
|
@ -102,7 +104,6 @@ function showusers() {
|
|||
$("#linkusers").css("font-weight", "bold");
|
||||
|
||||
window.history.pushState("", "", "/users/");
|
||||
return false;
|
||||
};
|
||||
|
||||
var page = document.location.pathname.substring(1, document.location.pathname.lastIndexOf('/'));
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
{% block content %}
|
||||
|
||||
<p><b>Organization:</b> {% orgaString %}</p>
|
||||
<p><b>User:</b> {{ user.first_name }} {{ user.last_name }} ({{ user.username }}) <a href="/user/{{ user.id }}/edit"><i class="fas fa-edit" title="Edit User"></i></a></p>
|
||||
<p><b>User:</b> {{ user.first_name }} {{ user.last_name }} ({{ user.username }}) <a href="/users/{{ user.id }}/edit"><i class="fas fa-edit" title="Edit User"></i></a></p>
|
||||
|
||||
<div align="center"><b>Manage:</b> <a id="linkdevices" href="#" onclick="showdevices();">Devices</a> ‐ <a id="linkwifi" href="#" onclick="showwifi();">WiFi</a>{% if user.is_staff %} ‐ <a id="linkusers" href="#" onclick="showusers();">Users</a>{% endif %}</div>
|
||||
|
||||
|
@ -87,7 +87,7 @@
|
|||
<td><div style="display:inline;" {% if user.is_superuser %}title="{% directOrgaString auser %}"{% endif %}>{% if auser.is_staff %}<b>{% endif %}{{ auser.username }}{% if auser.is_staff %}</b>{% endif %}</div></td>
|
||||
<td>{% if auser.is_staff %}<b>{% endif %}{{ auser.first_name }} {{ auser.last_name }}{% if auser.is_staff %}</b>{% endif %}</td>
|
||||
<td>{{ auser.userstatus.last_action }}</td>
|
||||
<td><a href="/user/{{ auser.id }}/edit"><i class="fas fa-edit" title="Edit User"></i></a> {% if auser.email %}<a href="mailto:{{ auser.email }}"><i class="fas fa-envelope" title="Send Email"></i></a>{% endif %}</td>
|
||||
<td><a href="/users/{{ auser.id }}/edit"><i class="fas fa-edit" title="Edit User"></i></a> {% if auser.email %}<a href="mailto:{{ auser.email }}"><i class="fas fa-envelope" title="Send Email"></i></a>{% endif %}{% if user.is_superuser %} <a href="#"><i style="color: darkred;" onclick="askdeleteuser({{ auser.id }});" class="fas fa-trash-alt" title="Delete User"></i></a>{% endif %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
|
|
Loading…
Reference in a new issue