Implement organization selection in user management

This commit is contained in:
Kumi 2019-02-02 10:03:33 +00:00
parent 6ada4c9757
commit a0e5007958
5 changed files with 30 additions and 5 deletions

View file

@ -62,7 +62,7 @@ def sigSuperUser(target, source, newstatus):
sigUser(target, source, UserLog.SUPERUSER, str(not newstatus), str(newstatus)) sigUser(target, source, UserLog.SUPERUSER, str(not newstatus), str(newstatus))
def sigOrgaUser(target, source, oldorga, neworga): 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 # WiFi Signals

View file

@ -4,11 +4,18 @@ from django.contrib.auth.models import User
register = template.Library() 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): 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): def directUserOrgas(user):
return sorted(user.organization_set.all(), key=lambda x: str(x)) return abcSort(user.organization_set.all())
@register.simple_tag @register.simple_tag
def directOrgaString(user): def directOrgaString(user):
@ -32,5 +39,5 @@ def userWifis(context):
@register.simple_tag(takes_context=True) @register.simple_tag(takes_context=True)
def userUsers(context): def userUsers(context):
return orgaObjects(User, userOrgas(context)) if context.request.user.is_staff else [] return orgaObjects(User, userOrgas(context))

View file

@ -291,6 +291,12 @@ def edituser(request, user_id):
sigSuperUser(user[0].username, request.user.username, newsuper) sigSuperUser(user[0].username, request.user.username, newsuper)
user[0].is_superuser = 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", "") newmail = request.POST.get("email", "")
if newmail != user[0].email: if newmail != user[0].email:
sigMailUser(user[0].username, request.user.username, user[0].email, newmail) sigMailUser(user[0].username, request.user.username, user[0].email, newmail)

View file

@ -1,4 +1,5 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load manager %}
{% block content %} {% block content %}
@ -20,6 +21,17 @@
<label for="email">Email Address</label> <label for="email">Email Address</label>
<input type="email" required class="form-control" id="email" name="email" value="{{ auser.email }}"></input> <input type="email" required class="form-control" id="email" name="email" value="{{ auser.email }}"></input>
</div> </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 %} {% if user.is_staff %}
<div class="form-group form-check"> <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"> <input class="form-check-input" type="checkbox" value="True" {% if auser.is_staff %} checked {% endif %} id="staff" name="staff">

View file

@ -84,7 +84,7 @@
{% userUsers as users %} {% userUsers as users %}
{% for auser in users %} {% for auser in users %}
<tr> <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>{% 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>{{ 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="/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>