Commit 4c4f5985 authored by ibuler's avatar ibuler

Finish asset permission detail and add user or user group list

parent 7b99a33a
...@@ -22,10 +22,10 @@ class AssetPermission(models.Model): ...@@ -22,10 +22,10 @@ class AssetPermission(models.Model):
asset_groups = models.ManyToManyField(AssetGroup, related_name='granted_by_permissions', blank=True) asset_groups = models.ManyToManyField(AssetGroup, related_name='granted_by_permissions', blank=True)
system_users = models.ManyToManyField(SystemUser, related_name='granted_by_permissions') system_users = models.ManyToManyField(SystemUser, related_name='granted_by_permissions')
action = models.CharField(choices=ACTION_CHOICE, max_length=8, default='1') action = models.CharField(choices=ACTION_CHOICE, max_length=8, default='1')
is_active = models.BooleanField(default=True) is_active = models.BooleanField(default=True, verbose_name=_('Active'))
date_expired = models.DateTimeField(default=date_expired_default, verbose_name=_('Date expired')) date_expired = models.DateTimeField(default=date_expired_default, verbose_name=_('Date expired'))
created_by = models.CharField(max_length=128, blank=True) created_by = models.CharField(max_length=128, blank=True, verbose_name=_('Created by'))
date_created = models.DateTimeField(auto_now=True) date_created = models.DateTimeField(auto_now=True, verbose_name=_('Date created'))
comment = models.TextField(verbose_name=_('Comment'), blank=True) comment = models.TextField(verbose_name=_('Comment'), blank=True)
def __unicode__(self): def __unicode__(self):
...@@ -33,7 +33,7 @@ class AssetPermission(models.Model): ...@@ -33,7 +33,7 @@ class AssetPermission(models.Model):
@property @property
def is_valid(self): def is_valid(self):
if self.date_expired < timezone.now() and is_active: if self.date_expired < timezone.now() and self.is_active:
return True return True
return True return True
......
This diff is collapsed.
...@@ -20,31 +20,31 @@ ...@@ -20,31 +20,31 @@
{% endblock %} {% endblock %}
{% block table_body %} {% block table_body %}
{% for permission in asset_permission_list %} {% for asset_permission in asset_permission_list %}
<tr class="gradeX"> <tr class="gradeX">
<td class="text-center"> <td class="text-center">
<input type="checkbox" name="checked" value="{{ permission.id }}"> <input type="checkbox" name="checked" value="{{ asset_permission.id }}">
</td> </td>
<td class="text-center"> <td class="text-center">
<a href=""> <a href="{% url 'perms:asset-permission-detail' pk=asset_permission.id %}">
{{ permission.name }} {{ asset_permission.name }}
</a> </a>
</td> </td>
<td class="text-center">{{ permission.users.count}}</td> <td class="text-center">{{ asset_permission.users.count}}</td>
<td class="text-center">{{ permission.user_groups.count}}</td> <td class="text-center">{{ asset_permission.user_groups.count}}</td>
<td class="text-center">{{ permission.assets.count }}</td> <td class="text-center">{{ asset_permission.assets.count }}</td>
<td class="text-center">{{ permission.asset_groups.count }}</td> <td class="text-center">{{ asset_permission.asset_groups.count }}</td>
<td class="text-center">{{ permission.system_users.count }}</td> <td class="text-center">{{ asset_permission.system_users.count }}</td>
<td class="text-center"> <td class="text-center">
{% if permission.is_valid %} {% if asset_permission.is_valid %}
<i class="fa fa-check text-navy"></i> <i class="fa fa-check text-navy"></i>
{% else %} {% else %}
<i class="fa fa-times text-danger"></i> <i class="fa fa-times text-danger"></i>
{% endif %} {% endif %}
</td> </td>
<td class="text-center"> <td class="text-center">
<a href="{% url 'perms:asset-permission-update' pk=permission.id %}" class="btn btn-xs btn-info">{% trans 'Update' %}</a> <a href="{% url 'perms:asset-permission-update' pk=asset_permission.id %}" class="btn btn-xs btn-info">{% trans 'Update' %}</a>
<a href="{% url 'perms:asset-permission-delete' pk=permission.id %}" class="btn btn-xs btn-danger del">{% trans 'Delete' %}</a> <a href="{% url 'perms:asset-permission-delete' pk=asset_permission.id %}" class="btn btn-xs btn-danger del">{% trans 'Delete' %}</a>
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
......
This diff is collapsed.
...@@ -14,5 +14,9 @@ urlpatterns = [ ...@@ -14,5 +14,9 @@ urlpatterns = [
name='asset-permission-detail'), name='asset-permission-detail'),
url(r'^asset-permission/(?P<pk>[0-9]+)/delete$', views.AssetPermissionDeleteView.as_view(), url(r'^asset-permission/(?P<pk>[0-9]+)/delete$', views.AssetPermissionDeleteView.as_view(),
name='asset-permission-delete'), name='asset-permission-delete'),
url(r'^asset-permission/(?P<pk>[0-9]+)/user$', views.AssetPermissionUserListView.as_view(),
name='asset-permission-user-list'),
url(r'^asset-permission/(?P<pk>[0-9]+)/asset$', views.AssetPermissionAssetListView.as_view(),
name='asset-permission-asset-list'),
] ]
...@@ -11,7 +11,7 @@ from django.urls import reverse_lazy ...@@ -11,7 +11,7 @@ from django.urls import reverse_lazy
from django.contrib.messages.views import SuccessMessageMixin from django.contrib.messages.views import SuccessMessageMixin
from django.views.generic.detail import DetailView, SingleObjectMixin from django.views.generic.detail import DetailView, SingleObjectMixin
from .hands import AdminUserRequiredMixin, User, UserGroup from .hands import AdminUserRequiredMixin, User, UserGroup, SystemUser
from .models import AssetPermission from .models import AssetPermission
from .forms import AssetPermissionForm from .forms import AssetPermissionForm
...@@ -95,14 +95,17 @@ class AssetPermissionUpdateView(AdminUserRequiredMixin, UpdateView): ...@@ -95,14 +95,17 @@ class AssetPermissionUpdateView(AdminUserRequiredMixin, UpdateView):
class AssetPermissionDetailView(AdminUserRequiredMixin, DetailView): class AssetPermissionDetailView(AdminUserRequiredMixin, DetailView):
template_name = 'assets/system_user_detail.html' template_name = 'perms/asset_permission_detail.html'
context_object_name = 'system_user' context_object_name = 'asset_permission'
model = AssetPermission model = AssetPermission
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = { context = {
'app': _('Assets'), 'app': _('Perms'),
'action': _('System user detail') 'action': _('Asset permission detail'),
'system_users_remain': [system_user for system_user in SystemUser.objects.all()
if system_user not in self.object.system_users.all()],
'system_users': self.object.system_users.all(),
} }
kwargs.update(context) kwargs.update(context)
return super(AssetPermissionDetailView, self).get_context_data(**kwargs) return super(AssetPermissionDetailView, self).get_context_data(**kwargs)
...@@ -112,3 +115,32 @@ class AssetPermissionDeleteView(AdminUserRequiredMixin, DeleteView): ...@@ -112,3 +115,32 @@ class AssetPermissionDeleteView(AdminUserRequiredMixin, DeleteView):
model = AssetPermission model = AssetPermission
template_name = 'perms/delete_confirm.html' template_name = 'perms/delete_confirm.html'
success_url = reverse_lazy('perms:asset-permission-list') success_url = reverse_lazy('perms:asset-permission-list')
class AssetPermissionUserListView(AdminUserRequiredMixin, SingleObjectMixin, ListView):
template_name = 'perms/asset_permission_user_list.html'
context_object_name = 'asset_permission'
paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
def get(self, request, *args, **kwargs):
self.object = self.get_object(queryset=AssetPermission.objects.all())
return super(AssetPermissionUserListView, self).get(request, *args, **kwargs)
def get_queryset(self):
return self.object.users.all()
def get_context_data(self, **kwargs):
context = {
'app': _('Perms'),
'action': _('Asset permission user list'),
'users_remain': [user for user in User.objects.all() if user not in self.get_queryset()],
'user_groups': self.object.user_groups.all(),
'user_groups_remain': [user_group for user_group in UserGroup.objects.all()
if user_group not in self.object.user_groups.all()]
}
kwargs.update(context)
return super(AssetPermissionUserListView, self).get_context_data(**kwargs)
class AssetPermissionAssetListView(AdminUserRequiredMixin, ListView):
pass
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 to comment