diff mbox series

[layerindex-web,2/2] layerindex: Allow staff to set Yocto compatibility

Message ID 20250224-mathieu-yp-compat-staff-v1-2-9b8d07f00af7@bootlin.com
State New
Headers show
Series layerindex: Allow staff to set Yocto compatibility | expand

Commit Message

Mathieu Dubois-Briand Feb. 24, 2025, 10:59 a.m. UTC
Fixes [YOCTO #15738]

Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
---
 layerindex/forms.py | 7 ++++++-
 layerindex/views.py | 5 +++++
 2 files changed, 11 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/layerindex/forms.py b/layerindex/forms.py
index 10acb8806d9e..360af402c2a4 100644
--- a/layerindex/forms.py
+++ b/layerindex/forms.py
@@ -24,7 +24,8 @@  import settings
 from layerindex.models import (Branch, ClassicRecipe,
                                LayerBranch, LayerItem, LayerMaintainer,
                                LayerNote, RecipeChange, RecipeChangeset,
-                               SecurityQuestion, UserProfile, PatchDisposition)
+                               SecurityQuestion, UserProfile, PatchDisposition,
+                               YPCompatibleVersion)
 
 
 class StyledForm(forms.Form):
@@ -77,6 +78,7 @@  class EditLayerForm(StyledModelForm):
     # Additional form fields
     vcs_subdir = forms.CharField(label='Repository subdirectory', max_length=60, required=False, help_text='Subdirectory within the repository where the layer is located, if not in the root (usually only used if the repository contains more than one layer)')
     actual_branch = forms.CharField(label='Actual branch', max_length=80, required=False, help_text='Name of the actual branch in the repository matching the core branch (e.g. the development branch is "master" by default)')
+    yp_compatible_version = forms.ModelChoiceField(label='Yocto Project Compatible version', queryset=YPCompatibleVersion.objects.all(), required=False)
     deps = forms.ModelMultipleChoiceField(label='Other layers this layer depends upon', queryset=LayerItem.objects.filter(comparison=False), required=False)
     captcha = CaptchaField(label='Verification', help_text='Please enter the letters displayed for verification purposes', error_messages={'invalid':'Incorrect entry, please try again'})
 
@@ -109,6 +111,9 @@  class EditLayerForm(StyledModelForm):
         self.fields = new_fields
         self.fields['vcs_subdir'].initial = layerbranch.vcs_subdir
         self.fields['actual_branch'].initial = layerbranch.actual_branch
+        self.fields['yp_compatible_version'].initial = layerbranch.yp_compatible_version
+        if not user.is_staff:
+            self.fields['yp_compatible_version'].widget.attrs['disabled'] = True
         self.was_saved = False
         self.allow_base_type = allow_base_type
 
diff --git a/layerindex/views.py b/layerindex/views.py
index 4df2a0921506..3cf91d2bf68d 100644
--- a/layerindex/views.py
+++ b/layerindex/views.py
@@ -204,6 +204,11 @@  def edit_layer_view(request, template_name, branch='master', slug=None):
                     reset_last_rev = True
                 layerbranch.save()
                 maintainerformset.save()
+                if (request.user.is_authenticated and request.user.is_staff):
+                    new_yp_compatible = form.cleaned_data['yp_compatible_version']
+                    if layerbranch.yp_compatible_version != new_yp_compatible:
+                        layerbranch.yp_compatible_version = new_yp_compatible
+                    layerbranch.save()
                 if slug:
                     new_deps = form.cleaned_data['deps']
                     existing_deps = [deprec.dependency for deprec in layerbranch.dependencies_set.all()]