From f418366a4ed3e51b92d6bd5fb2a5da0c13b6c651 Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Tue, 25 Aug 2015 15:43:49 +0200 Subject: [PATCH 1/4] hide description if empty --- cred/templates/cred_detail.html | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cred/templates/cred_detail.html b/cred/templates/cred_detail.html index ba2913a4..ffe93776 100644 --- a/cred/templates/cred_detail.html +++ b/cred/templates/cred_detail.html @@ -83,17 +83,17 @@

{% cred_icon cred.iconname %} {{ cred.title }}

- -{% trans "Description:" %} -{% if cred.descriptionmarkdown %} -
- {% markdown_cred cred.description %} -
-{% else %} -
{{ cred.description }}
+{% if cred.description %} + {% trans "Description:" %} + {% if cred.descriptionmarkdown %} +
+ {% markdown_cred cred.description %} +
+ {% else %} +
{{ cred.description }}
+ {% endif %} {% endif %} - {% if delete %}
{% csrf_token %} From 87a21b53bc2d3dd14e5b6e45be7442bab1953a56 Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Tue, 25 Aug 2015 15:47:27 +0200 Subject: [PATCH 2/4] #293 group's users management --- staff/templates/staff_groupdetail.html | 1 + staff/templates/staff_groupmanageusers.html | 27 +++++++++++++++++++++ staff/templates/staff_home.html | 12 ++++++++- staff/urls.py | 2 ++ staff/views.py | 19 +++++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 staff/templates/staff_groupmanageusers.html diff --git a/staff/templates/staff_groupdetail.html b/staff/templates/staff_groupdetail.html index 40841ee4..c471271f 100644 --- a/staff/templates/staff_groupdetail.html +++ b/staff/templates/staff_groupdetail.html @@ -11,6 +11,7 @@

{% trans "Group" %} {{ group.name }}

{% if not USE_LDAP_GROUPS %}

diff --git a/staff/templates/staff_groupmanageusers.html b/staff/templates/staff_groupmanageusers.html new file mode 100644 index 00000000..e255addf --- /dev/null +++ b/staff/templates/staff_groupmanageusers.html @@ -0,0 +1,27 @@ +{% extends "base.html" %} +{% load url from future %} +{% load i18n %} + +{% block content %} +

{% trans "User management for group" %}: {{ group.name }}

+ {% if delete %} +
+ {% trans "unenrol" %} {{ user.username }} +
+ {% endif %} +

{% trans "Add users" %}

+

{% trans "Enrolled Users" %} ({{ group.user_set.all|length }})

+ + + + + + + {% for u in group.user_set.all %} + + + + + {% endfor %} +
{% trans "User" %}{% trans "Delete" %}
{{ u.username }}{% trans "Delete" %}
+{% endblock %} \ No newline at end of file diff --git a/staff/templates/staff_home.html b/staff/templates/staff_home.html index f3150111..07618c49 100644 --- a/staff/templates/staff_home.html +++ b/staff/templates/staff_home.html @@ -44,12 +44,22 @@

{% trans "Users" %}

{% trans "Access Groups" %}

- {% if not USE_LDAP_GROUPS %}{% endif %} + + + + {% if not USE_LDAP_GROUPS %} + + + + {% endif %} + {% for g in grouplist %} + {% if not USE_LDAP_GROUPS %} + {% endif %} diff --git a/staff/urls.py b/staff/urls.py index d4d4516d..2bd677d3 100644 --- a/staff/urls.py +++ b/staff/urls.py @@ -31,6 +31,8 @@ url(r'^groupadd/$', 'groupadd'), url(r'^groupedit/(?P\d+)/$', 'groupedit'), url(r'^groupdelete/(?P\d+)/$', 'groupdelete'), + url(r'^groupmanageusers/(?P\d+)/$', 'groupmanageusers'), + url(r'^groupmanageusersdelete/(?P\d+)/(?P\d+)/$', 'groupmanageusersdelete'), url(r'^useredit/(?P\d+)/$', UpdateUser.as_view(), name="user_edit"), url(r'^userdelete/(?P\d+)/$', 'userdelete'), ) diff --git a/staff/views.py b/staff/views.py index 5dee45ec..73481582 100644 --- a/staff/views.py +++ b/staff/views.py @@ -90,6 +90,25 @@ def groupdelete(request, gid): return HttpResponseRedirect(reverse('staff.views.home')) return render(request, 'staff_groupdetail.html', {'group': group, 'delete': True}) +@rattic_staff_required +def groupmanageusers(request, gid): + group = get_object_or_404(Group, pk=gid) + if request.method == 'POST': + form = GroupForm(request.POST, instance=group) + if form.is_valid(): + form.save() + return HttpResponseRedirect(reverse('staff.views.home')) + else: + form = GroupForm(instance=group) + + return render(request, 'staff_groupmanageusers.html', {'group': group, 'form': form}) + +@rattic_staff_required +def groupmanageusersdelete(request, gid, uid): + group = get_object_or_404(Group, pk=gid) + user = get_object_or_404(User, pk=uid) + group.user_set.remove(user) + return render(request, 'staff_groupmanageusers.html', {'group': group, 'user': user,'delete': True}) @rattic_staff_required def userdelete(request, uid): From af5af8014ea35fc0f06f1b085568e7fc7ba59c4f Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Tue, 25 Aug 2015 15:50:33 +0200 Subject: [PATCH 3/4] add ability to toggle user status from user list --- staff/templates/staff_home.html | 8 ++++++++ staff/urls.py | 1 + staff/views.py | 11 +++++++++++ 3 files changed, 20 insertions(+) diff --git a/staff/templates/staff_home.html b/staff/templates/staff_home.html index 07618c49..cdf4fc36 100644 --- a/staff/templates/staff_home.html +++ b/staff/templates/staff_home.html @@ -27,6 +27,7 @@

{% trans "Users" %}

{% if not LDAP_ENABLED %} + {% endif %} @@ -36,6 +37,13 @@

{% trans "Users" %}

{% if not LDAP_ENABLED %} + {% endif %} diff --git a/staff/urls.py b/staff/urls.py index 2bd677d3..47435e80 100644 --- a/staff/urls.py +++ b/staff/urls.py @@ -34,6 +34,7 @@ url(r'^groupmanageusers/(?P\d+)/$', 'groupmanageusers'), url(r'^groupmanageusersdelete/(?P\d+)/(?P\d+)/$', 'groupmanageusersdelete'), url(r'^useredit/(?P\d+)/$', UpdateUser.as_view(), name="user_edit"), + url(r'^usertogglestatus/(?P\d+)/$', 'usertogglestatus'), url(r'^userdelete/(?P\d+)/$', 'userdelete'), ) diff --git a/staff/views.py b/staff/views.py index 73481582..aa5fcba5 100644 --- a/staff/views.py +++ b/staff/views.py @@ -110,6 +110,17 @@ def groupmanageusersdelete(request, gid, uid): group.user_set.remove(user) return render(request, 'staff_groupmanageusers.html', {'group': group, 'user': user,'delete': True}) +@rattic_staff_required +def usertogglestatus(request, uid): + user = get_object_or_404(User, pk=uid) + user.is_active = not user.is_active + user.save() + + if not user.is_active: + return HttpResponseRedirect(reverse('cred.views.list', args=('changeadvice', uid))) + else: + return HttpResponseRedirect(reverse('staff.views.home')) + @rattic_staff_required def userdelete(request, uid): user = get_object_or_404(User, pk=uid) From e47f43463fcfe35e3b6e31b7561c53efeeae9a03 Mon Sep 17 00:00:00 2001 From: ak4t0sh Date: Fri, 28 Aug 2015 00:31:22 +0200 Subject: [PATCH 4/4] #293 group's users management add form to enrol users into groups --- ratticweb/static/rattic/js/newcore.js | 14 ++++++++++++++ staff/models.py | 21 +++++++++++++++++++++ staff/templates/staff_groupmanageusers.html | 20 +++++++++++++++++--- staff/urls.py | 2 +- staff/views.py | 20 ++++++++------------ 5 files changed, 61 insertions(+), 16 deletions(-) diff --git a/ratticweb/static/rattic/js/newcore.js b/ratticweb/static/rattic/js/newcore.js index 7a5ea404..d65220b7 100644 --- a/ratticweb/static/rattic/js/newcore.js +++ b/ratticweb/static/rattic/js/newcore.js @@ -673,6 +673,17 @@ var RATTIC = (function ($, ZeroClipboard) { }); }; + /* Make the user select boxes be awesome */ + my.controls.userSelectors = function (selectors) { + var options = { + valueField: 'id', + labelField: 'name', + searchField: 'name', + plugins: ['remove_button'] + }; + selectors.selectize(options); + }; + /* Make the tag select boxes be awesome */ my.controls.groupSelectors = function (selectors) { var options = { @@ -764,6 +775,9 @@ $(document).ready(function () { // A Group selector that will create for staff members RATTIC.controls.groupSelectors($('.rattic-group-selector')); + // A User selector + RATTIC.controls.userSelectors($('.rattic-user-selector')); + // Button that submits a form indicated by a data attribute RATTIC.controls.formSubmitById($('.rattic-form-submit-by-id')); diff --git a/staff/models.py b/staff/models.py index 1208a634..5b85303d 100644 --- a/staff/models.py +++ b/staff/models.py @@ -91,3 +91,24 @@ def clean(self): del cleaned_data['password'] return cleaned_data + +class GroupManageUsersAddUserForm(forms.ModelForm): + class Meta: + model = Group + fields=('users',) + users = forms.ModelMultipleChoiceField( + queryset=User.objects.all(), + widget=forms.SelectMultiple(attrs={'class': 'rattic-user-selector'}) + ) + + def __init__(self, *args, **kwargs): + super(GroupManageUsersAddUserForm, self).__init__(*args, **kwargs) + self.fields['users'].queryset = User.objects.exclude(groups=self.instance) + + def save(self, *args, **kwargs): + group = Group.objects.get(id=self.instance.id) + newusers = self.cleaned_data['users'] + for user in newusers: + group.user_set.add(user) + self.instance=group + return super(GroupManageUsersAddUserForm, self).save(*args, **kwargs) \ No newline at end of file diff --git a/staff/templates/staff_groupmanageusers.html b/staff/templates/staff_groupmanageusers.html index e255addf..09a269fa 100644 --- a/staff/templates/staff_groupmanageusers.html +++ b/staff/templates/staff_groupmanageusers.html @@ -4,12 +4,26 @@ {% block content %}

{% trans "User management for group" %}: {{ group.name }}

- {% if delete %} + {% if deleteduser %}
- {% trans "unenrol" %} {{ user.username }} + {{ deleteduser.username }} {% trans "deleted" %}
{% endif %}

{% trans "Add users" %}

+ {% csrf_token %} + {% for field in form %} +
+ {{ field.errors }} + +
+ {{ field }} +
+
+ {% endfor %} +
+ +
+

{% trans "Enrolled Users" %} ({{ group.user_set.all|length }})

{% trans "Name" %}{% trans "Edit" %}{% trans "Delete" %}
{% trans "Name" %}{% trans "Users" %}{% trans "Edit" %}{% trans "Manage users" %}{% trans "Delete" %}
{{ g.name }}{{ g.user_set.all|length }}{% trans "Edit" %}{% trans "Manage users" %} {% trans "Delete" %}
{% trans "email" %}{% trans "Edit" %}{% trans "Toggle status" %} {% trans "Delete" %}
{{ u.email }}{% trans "Edit" %} + {% if not u.is_active %} + {% trans "Enable" %} + {% else %} + {% trans "Disable" %} + {% endif %} + {% trans "Delete" %}
@@ -20,7 +34,7 @@

{% trans "Enrolled Users" %} ({{ group.user_set.all|length }})

{% for u in group.user_set.all %} - + {% endfor %}
{{ u.username }}{% trans "Delete" %}{% trans "Delete" %}
diff --git a/staff/urls.py b/staff/urls.py index 47435e80..01afe20f 100644 --- a/staff/urls.py +++ b/staff/urls.py @@ -32,7 +32,7 @@ url(r'^groupedit/(?P\d+)/$', 'groupedit'), url(r'^groupdelete/(?P\d+)/$', 'groupdelete'), url(r'^groupmanageusers/(?P\d+)/$', 'groupmanageusers'), - url(r'^groupmanageusersdelete/(?P\d+)/(?P\d+)/$', 'groupmanageusersdelete'), + url(r'^groupmanageusers/(?P\d+)/(?P\d+)/$', 'groupmanageusers'), url(r'^useredit/(?P\d+)/$', UpdateUser.as_view(), name="user_edit"), url(r'^usertogglestatus/(?P\d+)/$', 'usertogglestatus'), url(r'^userdelete/(?P\d+)/$', 'userdelete'), diff --git a/staff/views.py b/staff/views.py index aa5fcba5..a1c42d1c 100644 --- a/staff/views.py +++ b/staff/views.py @@ -17,7 +17,7 @@ from cred.icon import get_icon_list from cred.models import CredAudit, Cred, Tag from cred.forms import CredForm -from models import UserForm, GroupForm, KeepassImportForm, AuditFilterForm +from models import UserForm, GroupForm, GroupManageUsersAddUserForm, KeepassImportForm, AuditFilterForm from decorators import rattic_staff_required @@ -91,25 +91,21 @@ def groupdelete(request, gid): return render(request, 'staff_groupdetail.html', {'group': group, 'delete': True}) @rattic_staff_required -def groupmanageusers(request, gid): +def groupmanageusers(request, gid, delete=0): group = get_object_or_404(Group, pk=gid) if request.method == 'POST': - form = GroupForm(request.POST, instance=group) + form = GroupManageUsersAddUserForm(request.POST, instance=group) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('staff.views.home')) else: - form = GroupForm(instance=group) - + form = GroupManageUsersAddUserForm(instance=group) + if delete: + user = get_object_or_404(User, pk=delete) + group.user_set.remove(user) + return render(request, 'staff_groupmanageusers.html', {'group': group, 'form': form, 'deleteduser': user}) return render(request, 'staff_groupmanageusers.html', {'group': group, 'form': form}) -@rattic_staff_required -def groupmanageusersdelete(request, gid, uid): - group = get_object_or_404(Group, pk=gid) - user = get_object_or_404(User, pk=uid) - group.user_set.remove(user) - return render(request, 'staff_groupmanageusers.html', {'group': group, 'user': user,'delete': True}) - @rattic_staff_required def usertogglestatus(request, uid): user = get_object_or_404(User, pk=uid)