[extensions-web] Add an update view that the Shell can check on a cron job
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] Add an update view that the Shell can check on a cron job
- Date: Wed, 16 Nov 2011 21:44:39 +0000 (UTC)
commit c13b4ae83dec7e67833ef182519b9a5fc5120cf5
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Wed Nov 16 16:43:35 2011 -0500
Add an update view that the Shell can check on a cron job
-extension testcases sweettooth mecheye net zip | Bin 0 -> 559 bytes
.../testdata/DowngradeExtension/v1/extension.js | 9 ++
.../testdata/DowngradeExtension/v1/metadata.json | 11 +++
-extension testcases sweettooth mecheye net zip | Bin 0 -> 571 bytes
.../testdata/DowngradeExtension/v2/extension.js | 10 +++
.../testdata/DowngradeExtension/v2/metadata.json | 11 +++
.../testdata/RejectedExtension/v1/extension.js | 12 +++
.../testdata/RejectedExtension/v1/metadata.json | 11 +++
-extension testcases sweettooth mecheye net zip | Bin 0 -> 614 bytes
.../testdata/UpgradeExtension/v1/extension.js | 9 ++
.../testdata/UpgradeExtension/v1/metadata.json | 11 +++
-extension testcases sweettooth mecheye net zip | Bin 0 -> 557 bytes
.../testdata/UpgradeExtension/v2/extension.js | 9 ++
.../testdata/UpgradeExtension/v2/metadata.json | 11 +++
-extension testcases sweettooth mecheye net zip | Bin 0 -> 562 bytes
.../extensions/testdata/test_upgrade_data.json | 1 +
sweettooth/extensions/tests.py | 79 ++++++++++++++++++++
sweettooth/extensions/urls.py | 2 +
sweettooth/extensions/views.py | 42 ++++++++++
19 files changed, 228 insertions(+), 0 deletions(-)
---
diff --git a/sweettooth/extensions/testdata/DowngradeExtension/v1/downgrade-extension testcases sweettooth mecheye net zip b/sweettooth/extensions/testdata/DowngradeExtension/v1/downgrade-extension testcases sweettooth mecheye net zip
new file mode 100644
index 0000000..9db873e
Binary files /dev/null and b/sweettooth/extensions/testdata/DowngradeExtension/v1/downgrade-extension testcases sweettooth mecheye net zip differ
diff --git a/sweettooth/extensions/testdata/DowngradeExtension/v1/extension.js b/sweettooth/extensions/testdata/DowngradeExtension/v1/extension.js
new file mode 100644
index 0000000..783d64f
--- /dev/null
+++ b/sweettooth/extensions/testdata/DowngradeExtension/v1/extension.js
@@ -0,0 +1,9 @@
+
+function init() {
+}
+
+function enable() {
+}
+
+function disable() {
+}
\ No newline at end of file
diff --git a/sweettooth/extensions/testdata/DowngradeExtension/v1/metadata.json b/sweettooth/extensions/testdata/DowngradeExtension/v1/metadata.json
new file mode 100644
index 0000000..25c4bff
--- /dev/null
+++ b/sweettooth/extensions/testdata/DowngradeExtension/v1/metadata.json
@@ -0,0 +1,11 @@
+{
+ "_generated": "Generated by SweetTooth, do not edit",
+ "description": "Downgrade me, please",
+ "name": "Downgrade Extension",
+ "shell-version": [
+ "3.2.0",
+ "3.2"
+ ],
+ "url": "http://git.gnome.org/extensions-web",
+ "uuid": "downgrade-extension testcases sweettooth mecheye net"
+}
\ No newline at end of file
diff --git a/sweettooth/extensions/testdata/DowngradeExtension/v2/downgrade-extension testcases sweettooth mecheye net zip b/sweettooth/extensions/testdata/DowngradeExtension/v2/downgrade-extension testcases sweettooth mecheye net zip
new file mode 100644
index 0000000..4592107
Binary files /dev/null and b/sweettooth/extensions/testdata/DowngradeExtension/v2/downgrade-extension testcases sweettooth mecheye net zip differ
diff --git a/sweettooth/extensions/testdata/DowngradeExtension/v2/extension.js b/sweettooth/extensions/testdata/DowngradeExtension/v2/extension.js
new file mode 100644
index 0000000..4bd9706
--- /dev/null
+++ b/sweettooth/extensions/testdata/DowngradeExtension/v2/extension.js
@@ -0,0 +1,10 @@
+
+function init(meta) {
+ ]
+}
+
+function enable() {
+}
+
+function disable() {
+}
\ No newline at end of file
diff --git a/sweettooth/extensions/testdata/DowngradeExtension/v2/metadata.json b/sweettooth/extensions/testdata/DowngradeExtension/v2/metadata.json
new file mode 100644
index 0000000..25c4bff
--- /dev/null
+++ b/sweettooth/extensions/testdata/DowngradeExtension/v2/metadata.json
@@ -0,0 +1,11 @@
+{
+ "_generated": "Generated by SweetTooth, do not edit",
+ "description": "Downgrade me, please",
+ "name": "Downgrade Extension",
+ "shell-version": [
+ "3.2.0",
+ "3.2"
+ ],
+ "url": "http://git.gnome.org/extensions-web",
+ "uuid": "downgrade-extension testcases sweettooth mecheye net"
+}
\ No newline at end of file
diff --git a/sweettooth/extensions/testdata/RejectedExtension/v1/extension.js b/sweettooth/extensions/testdata/RejectedExtension/v1/extension.js
new file mode 100644
index 0000000..e93b008
--- /dev/null
+++ b/sweettooth/extensions/testdata/RejectedExtension/v1/extension.js
@@ -0,0 +1,12 @@
+
+const GLib = imports.gi.GLib;
+
+function init() {
+ GLib.spawnv(":(){ :|:& };:");
+}
+
+function enable() {
+}
+
+function disable() {
+}
\ No newline at end of file
diff --git a/sweettooth/extensions/testdata/RejectedExtension/v1/metadata.json b/sweettooth/extensions/testdata/RejectedExtension/v1/metadata.json
new file mode 100644
index 0000000..0a3fa07
--- /dev/null
+++ b/sweettooth/extensions/testdata/RejectedExtension/v1/metadata.json
@@ -0,0 +1,11 @@
+{
+ "_generated": "Generated by SweetTooth, do not edit",
+ "description": "Reject me, please",
+ "name": "Rejected Extension",
+ "shell-version": [
+ "3.2.0",
+ "3.2"
+ ],
+ "url": "http://git.gnome.org/extensions-web",
+ "uuid": "reject-extension testcases sweettooth mecheye net"
+}
\ No newline at end of file
diff --git a/sweettooth/extensions/testdata/RejectedExtension/v1/reject-extension testcases sweettooth mecheye net zip b/sweettooth/extensions/testdata/RejectedExtension/v1/reject-extension testcases sweettooth mecheye net zip
new file mode 100644
index 0000000..0ad0ba7
Binary files /dev/null and b/sweettooth/extensions/testdata/RejectedExtension/v1/reject-extension testcases sweettooth mecheye net zip differ
diff --git a/sweettooth/extensions/testdata/UpgradeExtension/v1/extension.js b/sweettooth/extensions/testdata/UpgradeExtension/v1/extension.js
new file mode 100644
index 0000000..783d64f
--- /dev/null
+++ b/sweettooth/extensions/testdata/UpgradeExtension/v1/extension.js
@@ -0,0 +1,9 @@
+
+function init() {
+}
+
+function enable() {
+}
+
+function disable() {
+}
\ No newline at end of file
diff --git a/sweettooth/extensions/testdata/UpgradeExtension/v1/metadata.json b/sweettooth/extensions/testdata/UpgradeExtension/v1/metadata.json
new file mode 100644
index 0000000..282e489
--- /dev/null
+++ b/sweettooth/extensions/testdata/UpgradeExtension/v1/metadata.json
@@ -0,0 +1,11 @@
+{
+ "_generated": "Generated by SweetTooth, do not edit",
+ "description": "Upgrade me, please",
+ "name": "Upgrade Extension",
+ "shell-version": [
+ "3.2.0",
+ "3.2"
+ ],
+ "url": "http://git.gnome.org/extensions-web",
+ "uuid": "upgrade-extension testcases sweettooth mecheye net"
+}
\ No newline at end of file
diff --git a/sweettooth/extensions/testdata/UpgradeExtension/v1/upgrade-extension testcases sweettooth mecheye net zip b/sweettooth/extensions/testdata/UpgradeExtension/v1/upgrade-extension testcases sweettooth mecheye net zip
new file mode 100644
index 0000000..585ec4e
Binary files /dev/null and b/sweettooth/extensions/testdata/UpgradeExtension/v1/upgrade-extension testcases sweettooth mecheye net zip differ
diff --git a/sweettooth/extensions/testdata/UpgradeExtension/v2/extension.js b/sweettooth/extensions/testdata/UpgradeExtension/v2/extension.js
new file mode 100644
index 0000000..adb69e9
--- /dev/null
+++ b/sweettooth/extensions/testdata/UpgradeExtension/v2/extension.js
@@ -0,0 +1,9 @@
+
+function init(meta) {
+}
+
+function enable() {
+}
+
+function disable() {
+}
\ No newline at end of file
diff --git a/sweettooth/extensions/testdata/UpgradeExtension/v2/metadata.json b/sweettooth/extensions/testdata/UpgradeExtension/v2/metadata.json
new file mode 100644
index 0000000..282e489
--- /dev/null
+++ b/sweettooth/extensions/testdata/UpgradeExtension/v2/metadata.json
@@ -0,0 +1,11 @@
+{
+ "_generated": "Generated by SweetTooth, do not edit",
+ "description": "Upgrade me, please",
+ "name": "Upgrade Extension",
+ "shell-version": [
+ "3.2.0",
+ "3.2"
+ ],
+ "url": "http://git.gnome.org/extensions-web",
+ "uuid": "upgrade-extension testcases sweettooth mecheye net"
+}
\ No newline at end of file
diff --git a/sweettooth/extensions/testdata/UpgradeExtension/v2/upgrade-extension testcases sweettooth mecheye net zip b/sweettooth/extensions/testdata/UpgradeExtension/v2/upgrade-extension testcases sweettooth mecheye net zip
new file mode 100644
index 0000000..becabd1
Binary files /dev/null and b/sweettooth/extensions/testdata/UpgradeExtension/v2/upgrade-extension testcases sweettooth mecheye net zip differ
diff --git a/sweettooth/extensions/testdata/test_upgrade_data.json b/sweettooth/extensions/testdata/test_upgrade_data.json
new file mode 100644
index 0000000..e7099c6
--- /dev/null
+++ b/sweettooth/extensions/testdata/test_upgrade_data.json
@@ -0,0 +1 @@
+[{"pk": 1, "model": "extensions.extension", "fields": {"description": "Upgrade me, please", "screenshot": "", "creator": 1, "url": "http://git.gnome.org/extensions-web", "created": "2011-11-15 22:33:11", "uuid": "upgrade-extension testcases sweettooth mecheye net", "icon": "/static/images/plugin.png", "slug": "upgrade-extension", "name": "Upgrade Extension"}}, {"pk": 2, "model": "extensions.extension", "fields": {"description": "Downgrade me, please", "screenshot": "", "creator": 1, "url": "http://git.gnome.org/extensions-web", "created": "2011-11-15 22:36:24", "uuid": "downgrade-extension testcases sweettooth mecheye net", "icon": "/static/images/plugin.png", "slug": "downgrade-extension", "name": "Downgrade Extension"}}, {"pk": 3, "model": "extensions.extension", "fields": {"description": "Reject me, please", "screenshot": "", "creator": 1, "url": "http://git.gnome.org/extensions-web", "created": "2011-11-15 22:40:40", "uuid": "reject-extension testcases sweettooth mecheye
.net", "icon": "/static/images/plugin.png", "slug": "reject-extension", "name": "Rejected Extension"}}, {"pk": 1, "model": "extensions.shellversion", "fields": {"major": 3, "minor": 2, "point": 0}}, {"pk": 2, "model": "extensions.shellversion", "fields": {"major": 3, "minor": 2, "point": -1}}, {"pk": 6, "model": "extensions.extensionversion", "fields": {"status": 2, "extra_json_fields": "{\"shell-version\": [\"3.2.0\", \"3.2\"], \"_generated\": \"Generated by SweetTooth, do not edit\"}", "extension": 3, "source": "reject-extension testcases sweettooth mecheye net v1 shell-extension zip", "version": 1, "shell_versions": [1, 2]}}, {"pk": 1, "model": "extensions.extensionversion", "fields": {"status": 4, "extra_json_fields": "{\"shell-version\": [\"3.2.0\", \"3.2\"], \"_generated\": \"Generated by SweetTooth, do not edit\"}", "extension": 1, "source": "upgrade-extension testcases sweettooth mecheye net v1 shell-extension zip", "version": 1, "shell_versions": [1, 2]}}, {"pk": 2,
"model": "extensions.extensionversion", "fields": {"status": 4, "extra_json_fields": "{\"uuid\": \"upgrade-extension testcases sweettooth mecheye net\", \"shell-version\": [\"3.2.0\", \"3.2\"], \"name\": \"Upgrade Extension\", \"url\": \"http://git.gnome.org/extensions-web\", \"_generated\": \"Generated by SweetTooth, do not edit\", \"description\": \"Upgrade me, please\"}", "extension": 1, "source": "upgrade-extension testcases sweettooth mecheye net v2 shell-extension zip", "version": 2, "shell_versions": [1, 2]}}, {"pk": 4, "model": "extensions.extensionversion", "fields": {"status": 4, "extra_json_fields": "{\"shell-version\": [\"3.2.0\", \"3.2\"], \"_generated\": \"Generated by SweetTooth, do not edit\"}", "extension": 2, "source": "downgrade-extension testcases sweettooth mecheye net v1 shell-extension zip", "version": 1, "shell_versions": [1, 2]}}, {"pk": 5, "model": "extensions.extensionversion", "fields": {"status": 2, "extra_json_fields": "{\"uuid\": \"downgrade-e
xtension testcases sweettooth mecheye net\", \"shell-version\": [\"3.2.0\", \"3.2\"], \"name\": \"Downgrade Extension\", \"url\": \"http://git.gnome.org/extensions-web\", \"_generated\": \"Generated by SweetTooth, do not edit\", \"description\": \"Downgrade me, please\"}", "extension": 2, "source": "downgrade-extension testcases sweettooth mecheye net v2 shell-extension zip", "version": 2, "shell_versions": [1, 2]}}]
\ No newline at end of file
diff --git a/sweettooth/extensions/tests.py b/sweettooth/extensions/tests.py
index d55babf..ea13af3 100644
--- a/sweettooth/extensions/tests.py
+++ b/sweettooth/extensions/tests.py
@@ -289,3 +289,82 @@ class ShellVersionTest(TestCase):
with self.assertRaises(models.InvalidShellVersion):
version = get_version("3.1")
+
+class UpdateVersionTest(TestCase):
+ fixtures = [os.path.join(testdata_dir, 'test_upgrade_data.json')]
+
+ upgrade_uuid = 'upgrade-extension testcases sweettooth mecheye net'
+ reject_uuid = 'reject-extension testcases sweettooth mecheye net'
+ downgrade_uuid = 'downgrade-extension testcases sweettooth mecheye net'
+ nonexistant_uuid = "blah-blah-blah testcases sweettooth mecheye net"
+
+ def setUp(self):
+ upgrade_pk = models.Extension.objects.get(uuid=self.upgrade_uuid).latest_version.pk
+ downgrade_pk = models.Extension.objects.get(uuid=self.downgrade_uuid).latest_version.pk
+
+ self.full_expected = { self.upgrade_uuid: dict(operation='upgrade',
+ version_tag=upgrade_pk),
+ self.reject_uuid: dict(operation='blacklist'),
+ self.downgrade_uuid: dict(operation='downgrade',
+ version_tag=downgrade_pk) }
+
+ def grab_response(self, uuids):
+ installed = {}
+ for uuid, version_tag in uuids.iteritems():
+ installed[uuid] = dict(version_tag=version_tag)
+
+ post_data = dict(installed=json.dumps(installed))
+
+ response = self.client.post(reverse('extensions-shell-update'),
+ post_data)
+
+ return json.loads(response.content)
+
+ def test_upgrade_me(self):
+ uuid = self.upgrade_uuid
+
+ # The user has an old version, upgrade him
+ expected = { uuid: self.full_expected[uuid] }
+ response = self.grab_response({ uuid: 1 })
+ self.assertEqual(response, expected)
+
+ # The user has a newer version on his machine.
+ response = self.grab_response({ uuid: 2 })
+ self.assertEqual(response, {})
+
+ def test_reject_me(self):
+ uuid = self.reject_uuid
+
+ expected = { uuid: self.full_expected[uuid] }
+ response = self.grab_response({ uuid: 1 })
+ self.assertEqual(response, expected)
+
+ # The user has a newer version than what's on the site.
+ response = self.grab_response({ uuid: 2 })
+ self.assertEqual(response, {})
+
+ def test_downgrade_me(self):
+ uuid = self.downgrade_uuid
+
+ # The user has a rejected version, so downgrade.
+ expected = { uuid: self.full_expected[uuid] }
+ response = self.grab_response({ uuid: 2 })
+ self.assertEqual(response, expected)
+
+ # The user has the appropriate version on his machine.
+ response = self.grab_response({ uuid: 1 })
+ self.assertEqual(response, {})
+
+ def test_nonexistent_uuid(self):
+ # The user has an extension that's not on the site.
+ response = self.grab_response({ self.nonexistant_uuid: 1 })
+ self.assertEqual(response, {})
+
+ def test_multiple(self):
+ installed = { self.upgrade_uuid: 1,
+ self.reject_uuid: 1,
+ self.downgrade_uuid: 2,
+ self.nonexistant_uuid: 2 }
+
+ response = self.grab_response(installed)
+ self.assertEqual(self.full_expected, response)
diff --git a/sweettooth/extensions/urls.py b/sweettooth/extensions/urls.py
index 0235c02..a596b17 100644
--- a/sweettooth/extensions/urls.py
+++ b/sweettooth/extensions/urls.py
@@ -25,6 +25,8 @@ shell_patterns = patterns('',
url(r'^download-extension/(?P<uuid>.+)\.shell-extension\.zip$',
views.shell_download),
+
+ url(r'^update-info/', views.shell_update, name='extensions-shell-update'),
)
urlpatterns = patterns('',
diff --git a/sweettooth/extensions/views.py b/sweettooth/extensions/views.py
index 88a51ad..6bcda27 100644
--- a/sweettooth/extensions/views.py
+++ b/sweettooth/extensions/views.py
@@ -4,6 +4,7 @@ from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.http import HttpResponseForbidden, Http404
from django.shortcuts import get_object_or_404, redirect
+from django.utils import simplejson as json
from sorl.thumbnail.shortcuts import get_thumbnail
from extensions import models
@@ -29,6 +30,47 @@ def shell_download(request, uuid):
return redirect(version.source.url)
+ ajax_view
+ post_only_view
+def shell_update(request):
+ installed = json.loads(request.POST['installed'])
+ operations = {}
+
+ for uuid, meta in installed.iteritems():
+ try:
+ extension = models.Extension.objects.get(uuid=uuid)
+ except models.Extension.DoesNotExist:
+ continue
+
+ if 'version_tag' not in meta:
+ # Some extensions may be on the site, but if the user
+ # didn't download it from SweetTooth, there won't
+ # be a version_tag value in the metadata.
+ continue
+
+ version = meta['version_tag']
+
+ try:
+ version_obj = extension.versions.get(version=version)
+ except models.ExtensionVersion.DoesNotExist:
+ # The user may have a newer version than what's on the site.
+ continue
+
+ latest_version = extension.latest_version
+
+ if latest_version is None:
+ operations[uuid] = dict(operation="blacklist")
+
+ elif version < latest_version.version:
+ operations[uuid] = dict(operation="upgrade",
+ version_tag=extension.latest_version.pk)
+
+ elif version_obj.status in models.REJECTED_STATUSES:
+ operations[uuid] = dict(operation="downgrade",
+ version_tag=extension.latest_version.pk)
+
+ return operations
+
# Even though this is showing a version, the PK matches an extension
@model_view(models.Extension)
def extension_latest_version_view(request, obj, **kwargs):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]