[copr] master: [cli & api] delete a project (0fe4640)
by asamalik@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 0fe4640234f7e1b24a6de09cc23e6f11ab6cea25
Author: Adam Samalik <asamalik(a)redhat.com>
Date: Thu Apr 24 10:29:20 2014 +0200
[cli & api] delete a project
>---------------------------------------------------------------
cli/copr_cli/main.py | 15 +++++++++
cli/copr_cli/subcommands.py | 20 +++++++++++
cli/man/copr-cli.1.asciidoc | 5 ++-
frontend/coprs_frontend/coprs/templates/api.html | 18 ++++++++++
.../coprs/views/api_ns/api_general.py | 34 ++++++++++++++++++++
5 files changed, 91 insertions(+), 1 deletions(-)
diff --git a/cli/copr_cli/main.py b/cli/copr_cli/main.py
index 50d8a06..477ac0e 100644
--- a/cli/copr_cli/main.py
+++ b/cli/copr_cli/main.py
@@ -33,6 +33,14 @@ def action_create(args):
args.instructions, args.repos,
args.initial_pkgs)
+def action_delete(args):
+ """ Method called when the 'delete' action has been selected by the
+ user.
+
+ :param args: argparse arguments provided by the user
+ """
+ subcommands.delete(args.copr)
+
def action_list(args):
""" Method called when the 'list' action has been selected by the
@@ -97,6 +105,13 @@ def setup_parser():
help="Instructions for the copr")
parser_create.set_defaults(func=action_create)
+ # create the parser for the "delete" command
+ parser_delete = subparsers.add_parser("delete",
+ help="Deletes the entire project")
+ parser_delete.add_argument("copr",
+ help="Name of your project to be deleted.")
+ parser_delete.set_defaults(func=action_delete)
+
# create the parser for the "build" command
parser_build = subparsers.add_parser("build",
help="Build packages to a "
diff --git a/cli/copr_cli/subcommands.py b/cli/copr_cli/subcommands.py
index 2a74ea0..15c9ebd 100644
--- a/cli/copr_cli/subcommands.py
+++ b/cli/copr_cli/subcommands.py
@@ -161,6 +161,26 @@ def create(name, chroots=[], description=None, instructions=None,
print(output["message"])
+def delete(copr):
+ """ Delete the entire project.
+ """
+ user = get_user()
+ username = user["username"]
+
+ copr_api_url = get_api_url()
+ URL = "{0}/coprs/{1}/{2}/delete/".format(
+ copr_api_url,
+ username,
+ copr)
+
+ data = {"verify": "yes"}
+
+ req = requests.post(URL,
+ auth=(user["login"], user["token"]),
+ data=data)
+ output = _get_data(req, user, copr)
+
+
def _fetch_status(build_id):
user = get_user()
copr_api_url = get_api_url()
diff --git a/cli/man/copr-cli.1.asciidoc b/cli/man/copr-cli.1.asciidoc
index 518b456..ef9ada9 100644
--- a/cli/man/copr-cli.1.asciidoc
+++ b/cli/man/copr-cli.1.asciidoc
@@ -38,7 +38,10 @@ then your projects are listed.
create::
Create a new project.
-build ::
+delete::
+Delete an entire project.
+
+build::
Build packages for a specified project.
status::
diff --git a/frontend/coprs_frontend/coprs/templates/api.html b/frontend/coprs_frontend/coprs/templates/api.html
index 66f7f48..df37ec0 100644
--- a/frontend/coprs_frontend/coprs/templates/api.html
+++ b/frontend/coprs_frontend/coprs/templates/api.html
@@ -174,6 +174,24 @@ copr_url = http://copr.fedoraproject.org
packages to build in this new project</li>
</ul>
+ <h3>Delete an entire project</h3>
+
+ <p><span style="font-style:italic">Login required</span></p>
+
+ <h4>URL:</h4>
+ <pre style="font-size:120%">/api/coprs/<username>/<projectname>/delete/</pre>
+
+ <h4>URL parameters:</h4>
+ <ul>
+ <li><b>username</b> – Your username </li>
+ <li><b>projectname</b> – Name of the project you want to delete.</li>
+ </ul>
+
+ <h4>Parameters sent by POST:</h4>
+ <ul>
+ <li><b>verify</b> – This needs to be "yes"</li>
+ </ul>
+
<h3>Add new build</h3>
<p><span style="font-style:italic">Login required</span></p>
diff --git a/frontend/coprs_frontend/coprs/views/api_ns/api_general.py b/frontend/coprs_frontend/coprs/views/api_ns/api_general.py
index b3bcd7b..4de29bb 100644
--- a/frontend/coprs_frontend/coprs/views/api_ns/api_general.py
+++ b/frontend/coprs_frontend/coprs/views/api_ns/api_general.py
@@ -122,6 +122,40 @@ def api_new_copr(username):
return jsonout
+(a)api_ns.route("/coprs/<username>/<coprname>/delete/", methods=["POST"])
+@api_login_required
+def api_copr_delete(username, coprname):
+ """ Deletes selected user's project
+ """
+ form = forms.CoprDeleteForm(csrf_enabled=False)
+ copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first()
+ httpcode = 200
+
+ if form.validate_on_submit() and copr:
+ builds_query = builds_logic.BuildsLogic.get_multiple(
+ flask.g.user, copr=copr)
+ try:
+ for build in builds_query:
+ builds_logic.BuildsLogic.delete_build(flask.g.user, build)
+ coprs_logic.CoprsLogic.delete(flask.g.user, copr)
+ except (exceptions.ActionInProgressException,
+ exceptions.InsufficientRightsException) as err:
+ output = {"output": "notok", "error": err}
+ httpcode = 500
+ db.session.rollback()
+ else:
+ message = "Project {0} has been deleted.".format(coprname)
+ output = {"output": "ok", "message": message}
+ db.session.commit()
+ else:
+ output = {"output": "notok", "error": "Invalid request"}
+ httpcode = 500
+
+ jsonout = flask.jsonify(output)
+ jsonout.status_code = httpcode
+ return jsonout
+
+
@api_ns.route("/coprs/")
@api_ns.route("/coprs/<username>/")
def api_coprs_by_owner(username=None):