def chroot_update(username, coprname, chrootname): form = forms.ChrootForm() copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first() if not copr: return page_not_found( "Projec with name {0} does not exist.".format(coprname)) try: chroot = coprs_logic.MockChrootsLogic.get_from_name( chrootname, active_only=True).first() except ValueError as e: return page_not_found(str(e)) if form.validate_on_submit() and flask.g.user.can_build_in(copr): coprs_logic.CoprChrootsLogic.update_buildroot_pkgs( copr, chroot, form.buildroot_pkgs.data) flask.flash("Buildroot {0} for project {1} was updated".format( chrootname, coprname)) db.session.commit() return flask.redirect( flask.url_for("coprs_ns.copr_edit", username=username, coprname=copr.name)) else: if form.validate_on_submit(): flask.flash("You are not allowed to modify chroots.") else: return chroot_edit(username, coprname, chrootname)
def chroot_edit(username, coprname, chrootname): copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first() if not copr: return page_not_found( "Project with name {0} does not exist.".format(coprname)) try: chroot = coprs_logic.MockChrootsLogic.get_from_name( chrootname, active_only=True).first() except ValueError as e: return page_not_found(str(e)) if not chroot: return page_not_found( "Chroot name {0} does not exist.".format(chrootname)) form = forms.ChrootForm(buildroot_pkgs=copr.buildroot_pkgs(chroot)) # FIXME - test if chroot belongs to copr if flask.g.user.can_build_in(copr): return flask.render_template("coprs/detail/edit_chroot.html", form=form, copr=copr, chroot=chroot) else: return page_not_found( "You are not allowed to modify chroots in project {0}.".format( coprname))
def render_chroot_edit(copr, chroot_name): chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name) # todo: get COPR_chroot, not mock chroot, WTF?! # form = forms.ChrootForm(buildroot_pkgs=copr.buildroot_pkgs(chroot)) form = forms.ChrootForm(buildroot_pkgs=chroot.buildroot_pkgs) # FIXME - test if chroot belongs to copr if flask.g.user.can_build_in(copr): return render_template("coprs/detail/edit_chroot.html", form=form, copr=copr, chroot=chroot) else: raise AccessRestricted( "You are not allowed to modify chroots in project {0}." .format(copr.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 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)