Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow uploading new version without changing name
Browse files Browse the repository at this point in the history
Xpirix committed Nov 13, 2023
1 parent f55c449 commit c1c706b
Showing 5 changed files with 22 additions and 24 deletions.
12 changes: 0 additions & 12 deletions qgis-app/plugins/forms.py
Original file line number Diff line number Diff line change
@@ -132,18 +132,6 @@ def clean(self):
self.cleaned_data.get("version")
)
self.instance.server = self.cleaned_data.get("server")
# Check if name update is allowed and names match
if not self.instance.plugin.allow_update_name:
if (
self.cleaned_data.get("name")
and self.cleaned_data.get("name")
!= self.instance.plugin.name
):
raise ValidationError(
_(
f"Plugin name mismatch: the plugin name in the metadata.txt file ({self.cleaned_data.get('name')}) is different from the plugin name ({self.instance.plugin.name})."
)
)

# Check plugin folder name
if (
27 changes: 16 additions & 11 deletions qgis-app/plugins/tests/test_rename_plugin.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
from django.contrib.auth.models import User
from django.core.files.uploadedfile import SimpleUploadedFile
from plugins.models import Plugin, PluginVersion
from plugins.forms import PackageUploadForm, PluginVersionForm
from plugins.forms import PluginVersionForm

def do_nothing(*args, **kwargs):
pass
@@ -48,6 +48,8 @@ def setUp(self):
})

self.plugin = Plugin.objects.get(name='Test Plugin')
self.plugin.name = "New name Test Plugin"
self.plugin.save()

@patch("plugins.tasks.generate_plugins_xml.delay", new=do_nothing)
@patch("plugins.validator._check_url_link", new=do_nothing)
@@ -67,29 +69,32 @@ def test_plugin_rename(self):
self.assertEqual(response.status_code, 200)
self.assertFalse(response.context['form'].is_valid())

# Test POST request without rename permission
valid_plugin = os.path.join(TESTFILE_DIR, "valid_plugin_rename.zip_")
# Test POST request without allowing name from metadata
valid_plugin = os.path.join(TESTFILE_DIR, "valid_plugin_0.0.2.zip_")
with open(valid_plugin, "rb") as file:
uploaded_file = SimpleUploadedFile(
"valid_plugin_rename.zip", file.read(),
"valid_plugin_0.0.2.zip_", file.read(),
content_type="application/zip_")

response = self.client.post(self.url_add_version, {
'package': uploaded_file,
'experimental': False,
'changelog': ''
})
self.assertEqual(response.status_code, 200)
self.assertFalse(response.context['form'].is_valid())
self.assertEqual(response.status_code, 302)
self.assertTrue(PluginVersion.objects.filter(
plugin__name='New name Test Plugin',
version='0.0.2').exists()
)

# Test POST request with rename permission
# Test POST request with allowing name from metadata
self.plugin.allow_update_name = True
self.plugin.save()

valid_plugin = os.path.join(TESTFILE_DIR, "valid_plugin_rename.zip_")
valid_plugin = os.path.join(TESTFILE_DIR, "valid_plugin_0.0.3.zip_")
with open(valid_plugin, "rb") as file:
uploaded_file = SimpleUploadedFile(
"valid_plugin_rename.zip", file.read(),
"valid_plugin_0.0.3.zip_", file.read(),
content_type="application/zip_")
response = self.client.post(self.url_add_version, {
'package': uploaded_file,
@@ -98,8 +103,8 @@ def test_plugin_rename(self):
})
self.assertEqual(response.status_code, 302)
self.assertTrue(PluginVersion.objects.filter(
plugin__name='New name Test Plugin',
version='0.0.2').exists()
plugin__name='Test Plugin',
version='0.0.3').exists()
)

def tearDown(self):
Binary file not shown.
Binary file not shown.
7 changes: 6 additions & 1 deletion qgis-app/plugins/views.py
Original file line number Diff line number Diff line change
@@ -814,8 +814,13 @@ def _main_plugin_update(request, plugin, form):
"""
Updates the main plugin object from version metadata
"""
# Check if update name from metadata is allowed
metadata_fields = ["author", "email", "description", "about", "homepage", "tracker"]
if plugin.allow_update_name:
metadata_fields.insert(0, "name")

# Update plugin from metadata
for f in ["name", "author", "email", "description", "about", "homepage", "tracker"]:
for f in metadata_fields:
if form.cleaned_data.get(f):
setattr(plugin, f, form.cleaned_data.get(f))

0 comments on commit c1c706b

Please sign in to comment.