From d90fc9d5070c51944c4a36163d44809866c52dd9 Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Tue, 17 Oct 2023 14:02:54 +0200 Subject: [PATCH 1/6] Fix undefined search value --- core/forms.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/core/forms.py b/core/forms.py index e2b2ede..b8fa91e 100644 --- a/core/forms.py +++ b/core/forms.py @@ -209,12 +209,13 @@ class Meta: class SecurityMeasureCreateForm(LinkCleanMixin, StyledModelForm): + folder = forms.ModelChoiceField(queryset=Folder.objects.none()) 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'].queryset = Folder.objects.none() 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,16 +390,17 @@ def clean(self): class ProjectForm(StyledModelForm): - def __init__(self, user=None, *args, **kwargs): - super(ProjectForm, self).__init__(*args, **kwargs) + folder = forms.ModelChoiceField(queryset=Folder.objects.none()) + 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_project")) + 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'].queryset = Folder.objects.none() 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'}, - choices=self.fields['folder'].choices) + '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'}, + choices=self.fields['folder'].choices) class Meta: From b7e3d378720bae55b7030efda88fd006ea5295d5 Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Tue, 17 Oct 2023 14:03:48 +0200 Subject: [PATCH 2/6] Handle properly empty folder list when creating project --- core/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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): From 1cefe2064a65989410958e36a58b084f69fdbbb3 Mon Sep 17 00:00:00 2001 From: nas-tabchiche <71079376+nas-tabchiche@users.noreply.github.com> Date: Thu, 19 Oct 2023 12:24:47 +0200 Subject: [PATCH 3/6] Update VERSION --- mira/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mira/VERSION b/mira/VERSION index 3d54442..ae58dec 100644 --- a/mira/VERSION +++ b/mira/VERSION @@ -1 +1 @@ -3.0.2a +3.0.2b From 32c1262280df627319bced4a54f446f87d9a311d Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Thu, 19 Oct 2023 14:57:28 +0200 Subject: [PATCH 4/6] Update VERSION --- mira/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mira/VERSION b/mira/VERSION index 3d54442..ae58dec 100644 --- a/mira/VERSION +++ b/mira/VERSION @@ -1 +1 @@ -3.0.2a +3.0.2b From 0cac6585c702b1d0eda5ff1da0a8c0a4e4153c30 Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Thu, 19 Oct 2023 15:13:22 +0200 Subject: [PATCH 5/6] Fix regression --- core/forms.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/core/forms.py b/core/forms.py index b8fa91e..59607d4 100644 --- a/core/forms.py +++ b/core/forms.py @@ -209,13 +209,11 @@ class Meta: class SecurityMeasureCreateForm(LinkCleanMixin, StyledModelForm): - folder = forms.ModelChoiceField(queryset=Folder.objects.none()) + 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.none() 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'}, @@ -390,17 +388,15 @@ def clean(self): class ProjectForm(StyledModelForm): - folder = forms.ModelChoiceField(queryset=Folder.objects.none()) + folder = forms.ModelChoiceField(queryset=Folder.objects.filter(content_type=Folder.ContentType.DOMAIN)) def __init__(self, user=None, *args, **kwargs): - super().__init__(*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_securitymeasure")) - else: - self.fields['folder'].queryset = Folder.objects.none() + self.fields['folder'].queryset = Folder.objects.filter(id__in=RoleAssignment.get_accessible_folders(Folder.get_root_folder(), user, Folder.ContentType.DOMAIN, codename="add_project")) 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'}, - choices=self.fields['folder'].choices) + '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'}, + choices=self.fields['folder'].choices) class Meta: From 1d2661e6efbcfacfaefdfd20357441810c76695c Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Thu, 19 Oct 2023 15:14:07 +0200 Subject: [PATCH 6/6] Update VERSION --- mira/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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