mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-19 20:59:01 +02:00
Limit selection of "Base" layer type
If a user doesn't have publish rights and the type of the layer isn't already "Base" then disallow selecting the Base layer type. Some submitters are selecting this type for their own layers, but it's pretty much reserved for openembedded-core and meta-oe (so that they appear at the top of the layer list). Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
parent
7954acad9f
commit
f259f0c36f
1
TODO
1
TODO
|
@ -14,7 +14,6 @@ Features
|
||||||
* Allow users to make a comment sent to admins/maintainers?
|
* Allow users to make a comment sent to admins/maintainers?
|
||||||
* Marking for recipes with ptest enabled
|
* Marking for recipes with ptest enabled
|
||||||
* Make it easy to update people's email addresses
|
* Make it easy to update people's email addresses
|
||||||
* Prevent selection of "Base" layer type for layer unless you have admin access (or layer is already of that type)
|
|
||||||
* Use proper model to store inherits
|
* Use proper model to store inherits
|
||||||
* Make dependency and inherits list items into search links
|
* Make dependency and inherits list items into search links
|
||||||
* Full-text search on layer contents
|
* Full-text search on layer contents
|
||||||
|
|
|
@ -56,7 +56,7 @@ class EditLayerForm(forms.ModelForm):
|
||||||
model = LayerItem
|
model = LayerItem
|
||||||
fields = ('name', 'layer_type', 'summary', 'description', 'vcs_url', 'vcs_web_url', 'vcs_web_tree_base_url', 'vcs_web_file_base_url', 'vcs_web_commit_url', 'usage_url', 'mailing_list_url')
|
fields = ('name', 'layer_type', 'summary', 'description', 'vcs_url', 'vcs_web_url', 'vcs_web_tree_base_url', 'vcs_web_file_base_url', 'vcs_web_commit_url', 'usage_url', 'mailing_list_url')
|
||||||
|
|
||||||
def __init__(self, user, layerbranch, *args, **kwargs):
|
def __init__(self, user, layerbranch, allow_base_type, *args, **kwargs):
|
||||||
super(self.__class__, self).__init__(*args, **kwargs)
|
super(self.__class__, self).__init__(*args, **kwargs)
|
||||||
self.layerbranch = layerbranch
|
self.layerbranch = layerbranch
|
||||||
if self.instance.pk:
|
if self.instance.pk:
|
||||||
|
@ -77,6 +77,7 @@ class EditLayerForm(forms.ModelForm):
|
||||||
self.fields = new_fields
|
self.fields = new_fields
|
||||||
self.fields['vcs_subdir'].initial = layerbranch.vcs_subdir
|
self.fields['vcs_subdir'].initial = layerbranch.vcs_subdir
|
||||||
self.was_saved = False
|
self.was_saved = False
|
||||||
|
self.allow_base_type = allow_base_type
|
||||||
|
|
||||||
def checked_deps(self):
|
def checked_deps(self):
|
||||||
val = [int(v) for v in self['deps'].value()]
|
val = [int(v) for v in self['deps'].value()]
|
||||||
|
@ -100,6 +101,12 @@ class EditLayerForm(forms.ModelForm):
|
||||||
summary = re.sub('\s+', ' ', summary)
|
summary = re.sub('\s+', ' ', summary)
|
||||||
return summary
|
return summary
|
||||||
|
|
||||||
|
def clean_layer_type(self):
|
||||||
|
layer_type = self.cleaned_data['layer_type']
|
||||||
|
if layer_type == 'A' and not self.allow_base_type:
|
||||||
|
raise forms.ValidationError("Base type is not allowed, please select a more specific type")
|
||||||
|
return layer_type
|
||||||
|
|
||||||
def clean_description(self):
|
def clean_description(self):
|
||||||
description = self.cleaned_data['description'].strip()
|
description = self.cleaned_data['description'].strip()
|
||||||
return description
|
return description
|
||||||
|
|
|
@ -121,9 +121,11 @@ def edit_layer_view(request, template_name, branch='master', slug=None):
|
||||||
layerbranch = LayerBranch(layer=layeritem, branch=branchobj)
|
layerbranch = LayerBranch(layer=layeritem, branch=branchobj)
|
||||||
deplistlayers = LayerItem.objects.filter(comparison=False).order_by('name')
|
deplistlayers = LayerItem.objects.filter(comparison=False).order_by('name')
|
||||||
|
|
||||||
|
allow_base_type = request.user.has_perm('layerindex.publish_layer') or layeritem.layer_type == 'A'
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
last_vcs_url = layeritem.vcs_url
|
last_vcs_url = layeritem.vcs_url
|
||||||
form = EditLayerForm(request.user, layerbranch, request.POST, instance=layeritem)
|
form = EditLayerForm(request.user, layerbranch, allow_base_type, request.POST, instance=layeritem)
|
||||||
maintainerformset = LayerMaintainerFormSet(request.POST, instance=layerbranch)
|
maintainerformset = LayerMaintainerFormSet(request.POST, instance=layerbranch)
|
||||||
if form.is_valid() and maintainerformset.is_valid():
|
if form.is_valid() and maintainerformset.is_valid():
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
|
@ -196,13 +198,14 @@ def edit_layer_view(request, template_name, branch='master', slug=None):
|
||||||
return_url = reverse_lazy(returnto, args=(branch, layeritem.name))
|
return_url = reverse_lazy(returnto, args=(branch, layeritem.name))
|
||||||
return HttpResponseRedirect(return_url)
|
return HttpResponseRedirect(return_url)
|
||||||
else:
|
else:
|
||||||
form = EditLayerForm(request.user, layerbranch, instance=layeritem)
|
form = EditLayerForm(request.user, layerbranch, allow_base_type, instance=layeritem)
|
||||||
maintainerformset = LayerMaintainerFormSet(instance=layerbranch)
|
maintainerformset = LayerMaintainerFormSet(instance=layerbranch)
|
||||||
|
|
||||||
return render(request, template_name, {
|
return render(request, template_name, {
|
||||||
'form': form,
|
'form': form,
|
||||||
'maintainerformset': maintainerformset,
|
'maintainerformset': maintainerformset,
|
||||||
'deplistlayers': deplistlayers,
|
'deplistlayers': deplistlayers,
|
||||||
|
'allow_base_type': allow_base_type,
|
||||||
'return_url': return_url,
|
'return_url': return_url,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -391,6 +391,10 @@
|
||||||
$('#idx_vcs_web_type').change(auto_web_type_field)
|
$('#idx_vcs_web_type').change(auto_web_type_field)
|
||||||
auto_web_fields(null)
|
auto_web_fields(null)
|
||||||
|
|
||||||
|
{% if not allow_base_type %}
|
||||||
|
$("#id_layer_type option[value='A']").remove();
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
firstfield = $("#edit_layer_form input:text, #edit_layer_form textarea").first();
|
firstfield = $("#edit_layer_form input:text, #edit_layer_form textarea").first();
|
||||||
if( ! firstfield.val() )
|
if( ! firstfield.val() )
|
||||||
firstfield.focus()
|
firstfield.focus()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user