Commit b8e7c396 by Oláh István Gergely

dashboard: list acl groups, remove groups, group perm fix

parent a37614e8
......@@ -39,7 +39,7 @@
<thead><tr><th></th><th>{% trans "Who" %}</th><th></th><th></th></tr></thead>
{% for i in users %}
<tr><td><i class="icon-user"></i></td><td>{{i.username}}</td>
<td><a data-groupmember-pk="{{i.pk}}" href="{% url "dashboard.views.remove-groupmember" user_pk=i.pk group_pk=group.pk %}?next={{ request.path }}" class="real-link groupmember-delete btn btn-link btn-xs"><i class="icon-remove"><span class="sr-only">{% trans "remove" %}</span></i></a></td></tr>
<td><a data-groupmember-pk="{{i.pk}}" href="{% url "dashboard.views.remove-user" user_pk=i.pk group_pk=group.pk %}?next={{ request.path }}" class="real-link groupmember-delete btn btn-link btn-xs"><i class="icon-remove"><span class="sr-only">{% trans "remove" %}</span></i></a></td></tr>
{% endfor %}
<tr><td><i class="icon-plus"></i></td>
<td><input type="text" class="form-control" name="perm-new-name"
......@@ -60,7 +60,16 @@
<option{%if id = i.level%} selected="selected"{%endif%} value="{{id}}">{{name}}</option>
{% endfor %}
</select></td>
<td class="user-remove"><a href="#" class="btn btn-link btn-xs"><i class="icon-remove"><span class="sr-only">{% trans "remove" %}</span></i></a></td></tr>
<td class="user-remove"><a data-groupaclmember-pk="{{i.user.id}}" href="{% url "dashboard.views.remove-acluser" user_pk=i.user.pk group_pk=group.pk %}?next={{ request.path }}" class="real-link groupacl-delete btn btn-link btn-xs"><i class="icon-remove"><span class="sr-only">{% trans "remove" %}</span></i></a></td></tr>
{% endfor %}
{% for i in acl.groups %}
<tr><td><i class="icon-user"></i></td><td>{{ i.group }}</td>
<td><select class="form-control" name="perm-g-{{ i.group.pk }}">
{% for id, name in acl.levels %}
<option{%if id = i.level%} selected="selected"{%endif%} value="{{id}}">{{name}}</option>
{% endfor %}
</select></td>
<td class="user-remove"><a data-groupaclmember-pk="{{i.group.pk }}" href="{% url "dashboard.views.remove-aclgroup" user_pk=i.group.pk group_pk=group.pk %}?next={{ request.path }}" class="real-link groupacl-delete btn btn-link btn-xs"><i class="icon-remove"><span class="sr-only">{% trans "remove" %}</span></i></a></td></tr>
{% endfor %}
<tr><td><i class="icon-plus"></i></td>
<td><input type="text" class="form-control" name="perm-new-name"
......
from django.conf.urls import patterns, url
from .views import (
AclUpdateView, DiskAddView, FavouriteView, GroupAclUpdateView,
GroupDelete, GroupDetailView, GroupList, GroupUserDelete,
IndexView, LeaseCreate, LeaseDelete, LeaseDetail, MyPreferencesView,
NodeAddTraitView, NodeCreate, NodeDelete, NodeDetailView, NodeFlushView,
NodeGraphView, NodeList, NodeStatus, NotificationView, PortDelete,
TemplateAclUpdateView, TemplateCreate, TemplateDelete, TemplateDetail,
TemplateList, TransferOwnershipConfirmView, TransferOwnershipView,
vm_activity, VmCreate, VmDelete, VmDetailView, VmDetailVncTokenView,
VmGraphView, VmList, VmMassDelete, VmMigrateView, VmRenewView,
GroupAclRemoveView, GroupMemberRemoveView
AclUpdateView, DiskAddView, FavouriteView, GroupAclUpdateView, GroupDelete,
GroupDetailView, GroupList, GroupUserDelete, IndexView, LeaseCreate,
LeaseDelete, LeaseDetail, MyPreferencesView, NodeAddTraitView, NodeCreate,
NodeDelete, NodeDetailView, NodeFlushView, NodeGraphView, NodeList,
NodeStatus, NotificationView, PortDelete, TemplateAclUpdateView,
TemplateCreate, TemplateDelete, TemplateDetail, TemplateList,
TransferOwnershipConfirmView, TransferOwnershipView, vm_activity, VmCreate,
VmDelete, VmDetailView, VmDetailVncTokenView, VmGraphView, VmList,
VmMassDelete, VmMigrateView, VmRenewView, GroupRemoveAclUserView,
GroupRemoveAclGroupView, GroupRemoveUserView
)
from vm.models import Instance
......@@ -102,10 +102,13 @@ urlpatterns = patterns(
name="dashboard.views.disk-add"),
url(r'^profile/$', MyPreferencesView.as_view(),
name="dashboard.views.profile"),
url(r'^group/(?P<group_pk>\d+)/remove/acl/(?P<user_pk>\d+)/$',
GroupAclRemoveView.as_view(),
name="dashboard.views.remove-groupaclmember"),
url(r'^group/(?P<group_pk>\d+)/remove/member/(?P<user_pk>\d+)/$',
GroupMemberRemoveView.as_view(),
name="dashboard.views.remove-groupmember"),
url(r'^group/(?P<group_pk>\d+)/remove/acl/user/(?P<user_pk>\d+)/$',
GroupRemoveAclUserView.as_view(),
name="dashboard.views.remove-acluser"),
url(r'^group/(?P<group_pk>\d+)/remove/acl/group/(?P<user_pk>\d+)/$',
GroupRemoveAclGroupView.as_view(),
name="dashboard.views.remove-aclgroup"),
url(r'^group/(?P<group_pk>\d+)/remove/user/(?P<user_pk>\d+)/$',
GroupRemoveUserView.as_view(),
name="dashboard.views.remove-user"),
)
......@@ -635,6 +635,8 @@ class AclUpdateView(LoginRequiredMixin, View, SingleObjectMixin):
m = re.match('perm-([ug])-(\d+)', key)
if m:
typ, id = m.groups()
print "+++++++++++++++++++++"
print typ
entity = {'u': User, 'g': Group}[typ].objects.get(id=id)
if getattr(instance, "owner", None) == entity:
logger.info("Tried to set owner's acl level for %s by %s.",
......@@ -986,7 +988,7 @@ class GroupUserDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView):
return reverse_lazy('dashboard.index')
class GroupMemberRemoveView(LoginRequiredMixin, DeleteView):
class GroupRemoveUserView(LoginRequiredMixin, DeleteView):
model = Group
slug_field = 'pk'
slug_url_kwarg = 'group_pk'
......@@ -1004,15 +1006,15 @@ class GroupMemberRemoveView(LoginRequiredMixin, DeleteView):
else:
return ['dashboard/confirm/base-remove.html']
def remove_user(self, userpk):
def remove_member(self, pk):
container = self.get_object()
container.user_set.remove(User.objects.get(pk=userpk))
container.user_set.remove(User.objects.get(pk=pk))
def get_success_message(self):
return _("Member successfully removed from group!")
def delete(self, request, *args, **kwargs):
self.remove_user(kwargs["user_pk"])
self.remove_member(kwargs["user_pk"])
success_url = self.get_success_url()
success_message = self.get_success_message()
......@@ -1026,14 +1028,24 @@ class GroupMemberRemoveView(LoginRequiredMixin, DeleteView):
return HttpResponseRedirect(success_url)
class GroupAclRemoveView(GroupMemberRemoveView):
class GroupRemoveAclUserView(GroupRemoveUserView):
def remove_user(self, userpk):
def remove_member(self, pk):
container = self.get_object().profile
container.set_level(User.objects.get(pk=userpk), None)
container.set_level(User.objects.get(pk=pk), None)
def get_success_message(self):
return _("Acl member successfully removed from group!")
return _("Acl user successfully removed from group!")
class GroupRemoveAclGroupView(GroupRemoveUserView):
def remove_member(self, pk):
container = self.get_object().profile
container.set_level(Group.objects.get(pk=pk), None)
def get_success_message(self):
return _("Acl group successfully removed from group!")
class GroupDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment