Repository: fedora-infra/bodhi

Issue:
No indication when override already exists
When trying to create a buildroot override, there is no warning when one already exists. It just silently fails and the Submit button turns green again. It would be nice if an indication of an already existing override was given, or even better would be to extend the expiration of the existing override to the given date.



Discussion:
I get this too -- no feedback at all (positive or negative) when you attempt to create an override that already exists (someone else already created it)


Resolving patch:
diff --git a/bodhi/services/overrides.py b/bodhi/services/overrides.py
--- a/bodhi/services/overrides.py
+++ b/bodhi/services/overrides.py
@@ -193,13 +193,17 @@ def save_override(request):
                 })
             for build in builds:
                 log.info("Creating a new buildroot override: %s" % build.nvr)
-                overrides.append(BuildrootOverride.new(
-                    request,
-                    build=build,
-                    submitter=submitter,
-                    notes=data['notes'],
-                    expiration_date=data['expiration_date'],
-                ))
+                if BuildrootOverride.get(build.id, request.db):
+                    request.errors.add('body', 'builds', 'Buildroot override for %s already exists' % build.nvr)
+                    return
+                else:
+                    overrides.append(BuildrootOverride.new(
+                        request,
+                        build=build,
+                        submitter=submitter,
+                        notes=data['notes'],
+                        expiration_date=data['expiration_date'],
+                    ))
 
             if len(builds) > 1:
                 result = dict(overrides=overrides)


Test patch:
diff --git a/bodhi/tests/functional/test_overrides.py b/bodhi/tests/functional/test_overrides.py
--- a/bodhi/tests/functional/test_overrides.py
+++ b/bodhi/tests/functional/test_overrides.py
@@ -208,6 +208,39 @@ def test_create_override(self, publish):
                           expiration_date.strftime("%Y-%m-%d %H:%M:%S"))
         self.assertEquals(o['expired_date'], None)
 
+    @mock.patch('bodhi.notifications.publish')
+    def test_create_duplicate_override(self, publish):
+        release = Release.get(u'F17', self.db)
+        package = Package(name=u'not-bodhi')
+        self.db.add(package)
+        build = Build(nvr=u'not-bodhi-2.0-2.fc17', package=package,
+                      release=release)
+        self.db.add(build)
+        self.db.flush()
+
+        expiration_date = datetime.utcnow() + timedelta(days=1)
+
+        data = {'nvr': build.nvr, 'notes': u'blah blah blah',
+                'expiration_date': expiration_date,
+                'csrf_token': self.get_csrf_token()}
+        res = self.app.post('/overrides/', data)
+
+        publish.assert_called_once_with(
+            topic='buildroot_override.tag', msg=mock.ANY)
+        self.assertEquals(len(publish.call_args_list), 1)
+
+        o = res.json_body
+        self.assertEquals(o['build_id'], build.id)
+        self.assertEquals(o['notes'], 'blah blah blah')
+        self.assertEquals(o['expiration_date'],
+                          expiration_date.strftime("%Y-%m-%d %H:%M:%S"))
+        self.assertEquals(o['expired_date'], None)
+
+        # Submit it again
+        res = self.app.post('/overrides/', data, status=400)
+        self.assertEquals(res.json_body['errors'][0]['description'],
+                'Buildroot override for %s already exists' % build.nvr)
+
     @mock.patch('bodhi.notifications.publish')
     def test_create_override_multiple_nvr(self, publish):
         release = Release.get(u'F17', self.db)