I've yet to update the API documentation page [0], I'll send the relevant patch
if this one passes the review.
[0]
http://copr-fe.cloud.fedoraproject.org/api/
I've also enhanced copr-cli to make use of this newly exposed API, I'll send that
patch in a little bit.
---
Allows for:
* modification of description, instructions and repos of a copr
via POST to $copr_api_url/coprs/<username>/<coprname>/modify
* adding packages to minimal buildroot of a chroot via POST to
$copr_api_url/coprs/<username>/<coprname>/modify/<chroot>
* reading what packages are currently added to minimal buildroot of a chroot
via POST to $copr_api_url/coprs/<username>/<coprname>/details/<chroot>
---
coprs_frontend/coprs/forms.py | 15 ++++
coprs_frontend/coprs/views/api_ns/api_general.py | 90 +++++++++++++++++++++++-
2 files changed, 104 insertions(+), 1 deletion(-)
diff --git a/coprs_frontend/coprs/forms.py b/coprs_frontend/coprs/forms.py
index c5dfa42..62711d5 100644
--- a/coprs_frontend/coprs/forms.py
+++ b/coprs_frontend/coprs/forms.py
@@ -250,3 +250,18 @@ class PermissionsFormFactory(object):
coerce=int))
return F
+
+class CoprModifyForm(wtf.Form):
+ description = wtforms.TextAreaField('Description',
+ validators=[wtforms.validators.Optional()])
+
+ instructions = wtforms.TextAreaField('Instructions',
+ validators=[wtforms.validators.Optional()])
+
+ repos = wtforms.TextAreaField('Repos',
+ validators=[UrlListValidator(),
+ wtforms.validators.Optional()],
+ filters=[StringListFilter()])
+
+class ModifyChrootForm(wtf.Form):
+ buildroot_pkgs = wtforms.TextField('Additional packages to be always present in
minimal buildroot')
diff --git a/coprs_frontend/coprs/views/api_ns/api_general.py
b/coprs_frontend/coprs/views/api_ns/api_general.py
index 6dcdaa6..8ecdc29 100644
--- a/coprs_frontend/coprs/views/api_ns/api_general.py
+++ b/coprs_frontend/coprs/views/api_ns/api_general.py
@@ -156,7 +156,6 @@ def copr_new_build(username, coprname):
output = {'output': 'notok', 'error':
'Copr with name {0} does not exist.'.format(coprname)}
httpcode = 500
-
else:
if form.validate_on_submit() and flask.g.user.can_build_in(copr):
# we're checking authorization above for now
@@ -203,3 +202,92 @@ def build_status(build_id):
jsonout.status_code = httpcode
return jsonout
+(a)api_ns.route('/coprs/<username>/<coprname>/modify/',
methods=["POST"])
+@api_login_required
+def copr_modify(username, coprname):
+ form = forms.CoprModifyForm(csrf_enabled=False)
+ copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first()
+
+ if copr is None:
+ output = {'output': 'notok', 'error': 'Invalid copr
name or username'}
+ httpcode = 500
+ elif not form.validate_on_submit():
+ output = {'output': 'notok', 'error': 'Invalid
request'}
+ httpcode = 500
+ else:
+ # .raw_data needs to be inspected to figure out whether the field
+ # was not sent or was sent empty
+ if form.description.raw_data and len(form.description.raw_data):
+ copr.description = form.description.data
+ if form.instructions.raw_data and len(form.instructions.raw_data):
+ copr.instructions = form.instructions.data
+ if form.repos.raw_data and len(form.repos.raw_data):
+ copr.repos = form.repos.data
+
+ try:
+ coprs_logic.CoprsLogic.update(flask.g.user, copr)
+ except (exceptions.ActionInProgressException,
exceptions.InsufficientRightsException) as e:
+ db.session.rollback()
+
+ output = {'output': 'notok', 'error': str(e)}
+ httpcode = 500
+ else:
+ db.session.commit()
+
+ output = {'output': 'ok',
+ 'description': copr.description,
+ 'instructions': copr.instructions,
+ 'repos': copr.repos}
+ httpcode = 200
+
+ jsonout = flask.jsonify(output)
+ jsonout.status_code = httpcode
+ return jsonout
+
+@api_ns.route('/coprs/<username>/<coprname>/modify/<chrootname>/',
methods=["POST"])
+@api_login_required
+def copr_modify_chroot(username, coprname, chrootname):
+ form = forms.ModifyChrootForm(csrf_enabled=False)
+ copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first()
+ chroot = coprs_logic.MockChrootsLogic.get_from_name(chrootname,
active_only=True).first()
+
+ if copr is None:
+ output = {'output': 'notok', 'error': 'Invalid copr
name or username'}
+ httpcode = 500
+ elif chroot is None:
+ output = {'output': 'notok', 'error': 'Invalid chroot
name'}
+ httpcode = 500
+ elif not form.validate_on_submit():
+ output = {'output': 'notok', 'error': 'Invalid
request'}
+ httpcode = 500
+ else:
+ coprs_logic.CoprChrootsLogic.update_buildroot_pkgs(copr, chroot,
form.buildroot_pkgs.data)
+ db.session.commit()
+
+ ch = copr.check_copr_chroot(chroot)
+ output = {'output': 'ok', 'buildroot_pkgs':
ch.buildroot_pkgs}
+ httpcode = 200
+
+ jsonout = flask.jsonify(output)
+ jsonout.status_code = httpcode
+ return jsonout
+
+@api_ns.route('/coprs/<username>/<coprname>/details/<chrootname>/',
methods=["POST"])
+def copr_chroot_details(username, coprname, chrootname):
+ copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first()
+ chroot = coprs_logic.MockChrootsLogic.get_from_name(chrootname,
active_only=True).first()
+
+ if copr is None:
+ output = {'output': 'notok', 'error': 'Invalid copr
name or username'}
+ httpcode = 500
+ elif chroot is None:
+ output = {'output': 'notok', 'error': 'Invalid chroot
name'}
+ httpcode = 500
+ else:
+ ch = copr.check_copr_chroot(chroot)
+ output = {'output': 'ok', 'buildroot_pkgs':
ch.buildroot_pkgs}
+ httpcode = 200
+
+ jsonout = flask.jsonify(output)
+ jsonout.status_code = httpcode
+ return jsonout
--
1.8.4.2