Commit b8e7c396 by Oláh István Gergely

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

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