def edit_project_chroot(ownername, projectname, chrootname): copr = get_copr(ownername, projectname) data = rename_fields(get_form_compatible_data()) form = forms.ModifyChrootForm(data, meta={'csrf': False}) chroot = ComplexLogic.get_copr_chroot_safe(copr, chrootname) if not form.validate_on_submit(): raise BadRequest(form.errors) buildroot_pkgs = repos = comps_xml = comps_name = with_opts = without_opts = None if "buildroot_pkgs" in data: buildroot_pkgs = form.buildroot_pkgs.data if "repos" in data: repos = form.repos.data if "with_opts" in data: with_opts = form.with_opts.data if "without_opts" in data: without_opts = form.without_opts.data if form.upload_comps.has_file(): comps_xml = form.upload_comps.data.stream.read() comps_name = form.upload_comps.data.filename if form.delete_comps.data: CoprChrootsLogic.remove_comps(flask.g.user, chroot) CoprChrootsLogic.update_chroot(flask.g.user, chroot, buildroot_pkgs, repos, comps=comps_xml, comps_name=comps_name, with_opts=with_opts, without_opts=without_opts) db.session.commit() return flask.jsonify(to_dict(chroot))
def process_chroot_update(copr, chroot_name): form = forms.ChrootForm() chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name) if not flask.g.user.can_build_in(copr): raise AccessRestricted( "You are not allowed to modify chroots in project {0}." .format(copr.name)) if form.validate_on_submit(): if "submit" in flask.request.form: action = flask.request.form["submit"] if action == "update": comps_name = comps_xml = None module_md_name = module_md = None if form.comps.has_file(): comps_xml = form.comps.data.stream.read() comps_name = form.comps.data.filename if form.module_md.has_file(): module_md = form.module_md.data.stream.read() module_md_name = form.module_md.data.filename coprs_logic.CoprChrootsLogic.update_chroot( flask.g.user, chroot, form.buildroot_pkgs.data, comps=comps_xml, comps_name=comps_name, module_md=module_md, module_md_name=module_md_name ) elif action == "delete_comps": CoprChrootsLogic.remove_comps(flask.g.user, chroot) elif action == "delete_module_md": CoprChrootsLogic.remove_module_md(flask.g.user, chroot) flask.flash( "Buildroot {0} in project {1} has been updated successfully.".format( chroot_name, copr.name)) db.session.commit() return flask.redirect(url_for_copr_edit(copr)) else: flask.flash("You are not allowed to modify chroots.") return render_chroot_edit(copr, chroot_name)
def process_chroot_update(copr, chroot_name): form = forms.ChrootForm() chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name) if not flask.g.user.can_build_in(copr): raise AccessRestricted( "You are not allowed to modify chroots in project {0}." .format(copr.name)) if form.validate_on_submit(): if "submit" in flask.request.form: action = flask.request.form["submit"] if action == "update": comps_name = comps_xml = None if form.comps.has_file(): comps_xml = form.comps.data.stream.read() comps_name = form.comps.data.filename coprs_logic.CoprChrootsLogic.update_chroot( flask.g.user, chroot, form.buildroot_pkgs.data, comps=comps_xml, comps_name=comps_name) elif action == "delete_comps": CoprChrootsLogic.remove_comps(flask.g.user, chroot) flask.flash( "Buildroot {0} in project {1} has been updated successfully.".format( chroot_name, copr.name)) db.session.commit() return flask.redirect(url_for_copr_edit(copr)) else: flask.flash("You are not allowed to modify chroots.") return render_chroot_edit(copr, chroot_name)