diff --git a/apps/perms/models.py b/apps/perms/models.py
index c875dfe73..fd4189d87 100644
--- a/apps/perms/models.py
+++ b/apps/perms/models.py
@@ -22,7 +22,8 @@ class AssetPermission(models.Model):
assets = models.ManyToManyField(Asset, 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')
- private_for = models.CharField(choices=PRIVATE_FOR_CHOICE, max_length=1, default='N', verbose_name=_('Private for'))
+ private_for = models.CharField(choices=PRIVATE_FOR_CHOICE, max_length=1, default='N', blank=True,
+ verbose_name=_('Private for'))
is_active = models.BooleanField(default=True, verbose_name=_('Active'))
date_expired = models.DateTimeField(default=date_expired_default, verbose_name=_('Date expired'))
created_by = models.CharField(max_length=128, blank=True, verbose_name=_('Created by'))
diff --git a/apps/users/forms.py b/apps/users/forms.py
index d7e6c9bd4..c2a72a762 100644
--- a/apps/users/forms.py
+++ b/apps/users/forms.py
@@ -88,14 +88,11 @@ class UserPrivateAssetPermissionForm(forms.ModelForm):
def save(self, commit=True):
self.instance = super(UserPrivateAssetPermissionForm, self).save(commit=commit)
+ self.instance.private_for = 'U'
self.instance.users = [self.user]
- self.instance.name = '_Private for %s %s' % (self.user.username, )
self.instance.save()
return self.instance
- def clean_private_for(self):
- return 'U'
-
class Meta:
model = AssetPermission
fields = [
@@ -110,5 +107,3 @@ class UserPrivateAssetPermissionForm(forms.ModelForm):
'data-placeholder': _('Select system users')}),
}
-
-
diff --git a/apps/users/templates/users/user_asset_permission.html b/apps/users/templates/users/user_asset_permission.html
index 747b63c7f..da819ef5f 100644
--- a/apps/users/templates/users/user_asset_permission.html
+++ b/apps/users/templates/users/user_asset_permission.html
@@ -44,7 +44,7 @@
-
{% trans 'Asset permission of ' %} {{ user.name }}
+
{% trans 'Asset permission of ' %} {{ user_object.name }}
-
diff --git a/apps/users/urls.py b/apps/users/urls.py
index 7a66afabc..c02c16cb5 100644
--- a/apps/users/urls.py
+++ b/apps/users/urls.py
@@ -18,6 +18,8 @@ urlpatterns = [
url(r'^user/(?P
[0-9]+)$', views.UserDetailView.as_view(), name='user-detail'),
url(r'^user/(?P[0-9]+)/asset-permission$', views.UserAssetPermissionView.as_view(),
name='user-asset-permission'),
+ url(r'^user/(?P[0-9]+)/asset-permission/create$', views.UserAssetPermissionCreateView.as_view(),
+ name='user-asset-permission-create'),
url(r'^user/(?P[0-9]+)/asset-granted', views.UserDetailView.as_view(), name='user-granted-asset'),
url(r'^user/(?P[0-9]+)/login-history', views.UserDetailView.as_view(), name='user-login-history'),
url(r'^first-login/$', views.UserFirstLoginView.as_view(), name='user-first-login'),
diff --git a/apps/users/views.py b/apps/users/views.py
index bfb3ccf5e..f5f651798 100644
--- a/apps/users/views.py
+++ b/apps/users/views.py
@@ -18,18 +18,17 @@ from django.views.decorators.csrf import csrf_protect
from django.views.decorators.debug import sensitive_post_parameters
from django.views.generic.base import TemplateView
from django.views.generic.list import ListView
-from django.views.generic.edit import CreateView, DeleteView, UpdateView, FormView, SingleObjectMixin, FormMixin
+from django.views.generic.edit import CreateView, DeleteView, UpdateView, FormView, SingleObjectMixin, \
+ FormMixin, ModelFormMixin, ProcessFormView, BaseCreateView
from django.views.generic.detail import DetailView
-
from formtools.wizard.views import SessionWizardView
from common.utils import get_object_or_none, get_logger
-
from .models import User, UserGroup
from .forms import UserCreateForm, UserUpdateForm, UserGroupForm, UserLoginForm, UserInfoForm, UserKeyForm, \
UserPrivateAssetPermissionForm
from .utils import AdminUserRequiredMixin, user_add_success_next, send_reset_password_mail
-
+from .hands import AssetPermission
logger = get_logger(__name__)
@@ -394,4 +393,26 @@ class UserAssetPermissionView(AdminUserRequiredMixin, FormMixin, SingleObjectMix
class UserAssetPermissionCreateView(AdminUserRequiredMixin, CreateView):
- pass
+ form_class = UserPrivateAssetPermissionForm
+ model = AssetPermission
+
+ def get(self, request, *args, **kwargs):
+ user_object = self.get_object(queryset=User.objects.all())
+ return redirect(reverse('users:user-asset-permission', kwargs={'pk': user_object.id}))
+
+ def post(self, request, *args, **kwargs):
+ self.user_object = self.get_object(queryset=User.objects.all())
+ return super(UserAssetPermissionCreateView, self).post(request, *args, **kwargs)
+
+ def get_form(self, form_class=None):
+ form = super(UserAssetPermissionCreateView, self).get_form(form_class=form_class)
+ form.user = self.user_object
+ return form
+
+ def form_invalid(self, form):
+ print(form.errors)
+ return redirect(reverse('users:user-asset-permission', kwargs={'pk': self.user_object.id}))
+
+ def get_success_url(self):
+ return reverse('users:user-asset-permission', kwargs={'pk': self.user_object.id})
+