diff --git a/core/forms.py b/core/forms.py index e2b2ede..59607d4 100644 --- a/core/forms.py +++ b/core/forms.py @@ -209,12 +209,11 @@ class Meta: class SecurityMeasureCreateForm(LinkCleanMixin, StyledModelForm): + folder = forms.ModelChoiceField(queryset=Folder.objects.filter(content_type=Folder.ContentType.DOMAIN)) def __init__(self, user=None, *args, **kwargs): super().__init__(*args, **kwargs) if user: self.fields['folder'].queryset = Folder.objects.filter(id__in=RoleAssignment.get_accessible_folders(Folder.get_root_folder(), user, Folder.ContentType.DOMAIN, codename="add_securitymeasure")) - else: - self.fields['folder'].queryset = Folder.objects.filter(content_type=Folder.ContentType.DOMAIN) self.fields['folder'].widget = SearchableSelect(attrs={'class': 'text-sm rounded', 'searchbar_class': '[&_.search-icon]:text-gray-500 text-sm px-3', 'wrapper_class': 'border border-gray-300 bg-gray-50 text-gray-900 text-sm rounded-b-lg focus:ring-blue-500 focus:border-blue-500 max-h-56 overflow-y-scroll'}, @@ -389,12 +388,11 @@ def clean(self): class ProjectForm(StyledModelForm): - def __init__(self, user=None, *args, **kwargs): + folder = forms.ModelChoiceField(queryset=Folder.objects.filter(content_type=Folder.ContentType.DOMAIN)) + def __init__(self, user=None, *args, **kwargs): super(ProjectForm, self).__init__(*args, **kwargs) if user: self.fields['folder'].queryset = Folder.objects.filter(id__in=RoleAssignment.get_accessible_folders(Folder.get_root_folder(), user, Folder.ContentType.DOMAIN, codename="add_project")) - else: - self.fields['folder'].queryset = Folder.objects.filter(content_type=Folder.ContentType.DOMAIN) self.fields['folder'].widget = SearchableSelect(attrs={'class': 'text-sm rounded', 'searchbar_class': '[&_.search-icon]:text-gray-500 text-sm px-3', 'wrapper_class': 'border border-gray-300 bg-gray-50 text-gray-900 text-sm rounded-b-lg focus:ring-blue-500 focus:border-blue-500 max-h-56 overflow-y-scroll'}, diff --git a/core/views.py b/core/views.py index 575b3f2..89001ae 100644 --- a/core/views.py +++ b/core/views.py @@ -889,13 +889,13 @@ def test_func(self): return RoleAssignment.is_access_allowed(user=self.request.user, perm=Permission.objects.get(codename='add_project'), folder=Folder.objects.get(id=self.request.POST['folder'])) -class ProjectCreateViewModal(UserPassesTestMixin, CreateViewModal): +class ProjectCreateViewModal(CreateViewModal, UserPassesTestMixin): model = Project context_object_name = 'project' form_class = ProjectForm def test_func(self): - return RoleAssignment.is_access_allowed(user=self.request.user, perm=Permission.objects.get(codename='add_project'), folder=Folder.objects.get(id=self.request.POST['folder'])) + return RoleAssignment.is_access_allowed(user=self.request.user, perm=Permission.objects.get(codename="add_project"), folder=Folder.objects.get(id=self.request.POST['folder'])) class ProjectUpdateView(BaseContextMixin, UserPassesTestMixin, UpdateView): diff --git a/mira/VERSION b/mira/VERSION index ae58dec..3e6aa38 100644 --- a/mira/VERSION +++ b/mira/VERSION @@ -1 +1 @@ -3.0.2b +3.0.2c