Exemplo n.º 1
0
def copr_modify(copr):
    form = forms.CoprModifyForm(csrf_enabled=False)

    if not form.validate_on_submit():
        raise LegacyApiError("Invalid request: bad request parameters")

    # .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
    if form.disable_createrepo.raw_data and len(
            form.disable_createrepo.raw_data):
        copr.disable_createrepo = form.disable_createrepo.data

    try:
        CoprsLogic.update(flask.g.user, copr)
        db.session.commit()
    except (exceptions.ActionInProgressException,
            exceptions.InsufficientRightsException) as e:
        db.session.rollback()
        raise LegacyApiError("Invalid request: {}".format(e))

    output = {
        'output': 'ok',
        'description': copr.description,
        'instructions': copr.instructions,
        'repos': copr.repos,
    }

    return flask.jsonify(output)
Exemplo n.º 2
0
 def test_update_raises_if_copr_has_unfinished_actions(self, f_users,
                                                       f_coprs, f_actions,
                                                       f_db):
     self.c1.name = "foo"
     with pytest.raises(ActionInProgressException):
         CoprsLogic.update(self.u1, self.c1)
     self.db.session.rollback()
Exemplo n.º 3
0
def copr_modify(copr):
    form = forms.CoprModifyForm(csrf_enabled=False)

    if not form.validate_on_submit():
        raise LegacyApiError("Invalid request: bad request parameters")

    # .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
    if form.disable_createrepo.raw_data and len(form.disable_createrepo.raw_data):
        copr.disable_createrepo = form.disable_createrepo.data

    try:
        CoprsLogic.update(flask.g.user, copr)
        db.session.commit()
    except (exceptions.ActionInProgressException, exceptions.InsufficientRightsException) as e:
        db.session.rollback()
        raise LegacyApiError("Invalid request: {}".format(e))

    output = {
        'output': 'ok',
        'description': copr.description,
        'instructions': copr.instructions,
        'repos': copr.repos,
    }

    return flask.jsonify(output)
Exemplo n.º 4
0
def edit_project(ownername, projectname):
    copr = get_copr(ownername, projectname)
    data = rename_fields(get_form_compatible_data())
    form = forms.CoprModifyForm(data, meta={'csrf': False})

    if not form.validate_on_submit():
        raise BadRequest(form.errors)
    validate_chroots(get_input_dict(), MockChrootsLogic.get_multiple())

    for field in form:
        if field.data is None or field.name in ["csrf_token", "chroots"]:
            continue
        if field.name not in data.keys():
            continue
        setattr(copr, field.name, field.data)

    if form.chroots.data:
        CoprChrootsLogic.update_from_names(flask.g.user, copr,
                                           form.chroots.data)

    try:
        CoprsLogic.update(flask.g.user, copr)
        if copr.group:  # load group.id
            _ = copr.group.id
        db.session.commit()
    except (ActionInProgressException, InsufficientRightsException,
            NonAdminCannotDisableAutoPrunning) as ex:
        db.session.rollback()
        raise ex

    return flask.jsonify(to_dict(copr))
Exemplo n.º 5
0
def copr_modify(copr):
    form = forms.CoprModifyForm(meta={'csrf': False})

    if not form.validate_on_submit():
        raise LegacyApiError("Invalid request: {0}".format(form.errors))

    # .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
    if form.disable_createrepo.raw_data and len(
            form.disable_createrepo.raw_data):
        copr.disable_createrepo = form.disable_createrepo.data

    if "unlisted_on_hp" in flask.request.form:
        copr.unlisted_on_hp = form.unlisted_on_hp.data
    if "build_enable_net" in flask.request.form:
        copr.build_enable_net = form.build_enable_net.data
    if "auto_prune" in flask.request.form:
        copr.auto_prune = form.auto_prune.data
    if "use_bootstrap_container" in flask.request.form:
        copr.use_bootstrap_container = form.use_bootstrap_container.data
    if "chroots" in flask.request.form:
        coprs_logic.CoprChrootsLogic.update_from_names(flask.g.user, copr,
                                                       form.chroots.data)

    try:
        CoprsLogic.update(flask.g.user, copr)
        if copr.group:  # load group.id
            _ = copr.group.id
        db.session.commit()
    except (exceptions.ActionInProgressException,
            exceptions.InsufficientRightsException,
            exceptions.NonAdminCannotDisableAutoPrunning) as e:
        db.session.rollback()
        raise LegacyApiError("Invalid request: {}".format(e))

    output = {
        'output': 'ok',
        'description': copr.description,
        'instructions': copr.instructions,
        'repos': copr.repos,
        'chroots': [c.name for c in copr.mock_chroots],
    }

    return flask.jsonify(output)
Exemplo n.º 6
0
 def test_update_raises_if_copr_has_unfinished_actions(
         self, f_users, f_coprs, f_actions, f_db):
     self.c1.name = "foo"
     with pytest.raises(ActionInProgressException):
         CoprsLogic.update(self.u1, self.c1)
     self.db.session.rollback()