From 2b62d67387fd3536fdcd1bf64f79d7750adc6bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0abata?= Date: Fri, 8 Jul 2016 14:29:42 +0200 Subject: [PATCH] Check whether the module already exists in the database MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Petr Ĺ abata --- README.rst | 1 + rida.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/README.rst b/README.rst index da4e2f25..96ebb84d 100644 --- a/README.rst +++ b/README.rst @@ -124,6 +124,7 @@ Possible response codes are for various requests include: - HTTP 403 Forbidden - The SCM URL is not pointing to a whitelisted SCM server. - HTTP 404 Not Found - The requested URL has no handler associated with it or the requested resource doesn't exist. +- HTTP 409 Conflict - The submitted module's NVR already exists. - HTTP 422 Unprocessable Entity - The submitted modulemd file is not valid or the module components cannot be retrieved - HTTP 500 Internal Server Error - An unknown error occured. diff --git a/rida.py b/rida.py index 26419bc4..588bed2e 100755 --- a/rida.py +++ b/rida.py @@ -99,6 +99,9 @@ def submit_build(): mmd.loads(yaml) except: return "Invalid modulemd", 422 + if db.session.query(rida.database.Module).filter_by(name=mmd.name, + version=mmd.version, release=mmd.release).first(): + return "Module already exists", 409 module = rida.database.Module(name=mmd.name, version=mmd.version, release=mmd.release, state="init", modulemd=yaml) db.session.add(module)