Implement organization selection in user management
This commit is contained in:
parent
6ada4c9757
commit
a0e5007958
5 changed files with 30 additions and 5 deletions
|
@ -62,7 +62,7 @@ def sigSuperUser(target, source, newstatus):
|
|||
sigUser(target, source, UserLog.SUPERUSER, str(not newstatus), str(newstatus))
|
||||
|
||||
def sigOrgaUser(target, source, oldorga, neworga):
|
||||
sigUser(target, source, UserLog.ORGA, oldorga, neworga)
|
||||
sigUser(target, source, UserLog.ORGA, ", ".join(str(x) for x in oldorga), ", ".join(str(x) for x in neworga))
|
||||
|
||||
# WiFi Signals
|
||||
|
||||
|
|
|
@ -4,11 +4,18 @@ from django.contrib.auth.models import User
|
|||
|
||||
register = template.Library()
|
||||
|
||||
def abcSort(inlist):
|
||||
return sorted(inlist, key=lambda x: str(x))
|
||||
|
||||
@register.simple_tag
|
||||
def allOrgas():
|
||||
return abcSort(Organization.objects.all())
|
||||
|
||||
def orgaObjects(cls, orga):
|
||||
return sorted(set(cls.objects.filter(organization__in=orga)), key=lambda x: str(x))
|
||||
return abcSort(set(cls.objects.filter(organization__in=orga)))
|
||||
|
||||
def directUserOrgas(user):
|
||||
return sorted(user.organization_set.all(), key=lambda x: str(x))
|
||||
return abcSort(user.organization_set.all())
|
||||
|
||||
@register.simple_tag
|
||||
def directOrgaString(user):
|
||||
|
@ -32,5 +39,5 @@ def userWifis(context):
|
|||
|
||||
@register.simple_tag(takes_context=True)
|
||||
def userUsers(context):
|
||||
return orgaObjects(User, userOrgas(context)) if context.request.user.is_staff else []
|
||||
return orgaObjects(User, userOrgas(context))
|
||||
|
||||
|
|
|
@ -291,6 +291,12 @@ def edituser(request, user_id):
|
|||
sigSuperUser(user[0].username, request.user.username, newsuper)
|
||||
user[0].is_superuser = newsuper
|
||||
|
||||
neworgas = set(request.POST.getlist("orga", []))
|
||||
oldorgas = set(user[0].organization_set.all())
|
||||
if neworgas != oldorgas:
|
||||
sigOrgaUser(user[0].username, request.user.username, oldorgas, neworgas)
|
||||
user[0].organization_set.set(neworgas)
|
||||
|
||||
newmail = request.POST.get("email", "")
|
||||
if newmail != user[0].email:
|
||||
sigMailUser(user[0].username, request.user.username, user[0].email, newmail)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{% extends "base.html" %}
|
||||
{% load manager %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
|
@ -20,6 +21,17 @@
|
|||
<label for="email">Email Address</label>
|
||||
<input type="email" required class="form-control" id="email" name="email" value="{{ auser.email }}"></input>
|
||||
</div>
|
||||
{% if user.is_superuser %}
|
||||
<div class="form-group">
|
||||
<label for="orga">Assigned Organizations</label>
|
||||
<select multiple required class="custom-select mr-sm-2" id="orga" name="orga">
|
||||
{% allOrgas as orgas %}
|
||||
{% for choice in orgas %}
|
||||
<option {% if choice in auser.organization_set.all %} selected {% endif %} value="{{ choice.id }}">{{ choice }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if user.is_staff %}
|
||||
<div class="form-group form-check">
|
||||
<input class="form-check-input" type="checkbox" value="True" {% if auser.is_staff %} checked {% endif %} id="staff" name="staff">
|
||||
|
|
|
@ -84,7 +84,7 @@
|
|||
{% userUsers as users %}
|
||||
{% for auser in users %}
|
||||
<tr>
|
||||
<td><div style="display:inline;" {% if user.is_superuser %}title="{% directOrgaString user %}"{% endif %}>{% if auser.is_staff %}<b>{% endif %}{{ auser.username }}{% if auser.is_staff %}</b>{% endif %}</div></td>
|
||||
<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>
|
||||
|
|
Loading…
Reference in a new issue