Esempio n. 1
0
def copr_fork_post(copr):
    form = forms.CoprForkFormFactory.create_form_cls(
        copr=copr, user=flask.g.user, groups=flask.g.user.user_groups)()
    if form.validate_on_submit():
        dstgroup = ([
            g for g in flask.g.user.user_groups if g.at_name == form.owner.data
        ] or [None])[0]
        if flask.g.user.name != form.owner.data and not dstgroup:
            return generic_error("There is no such group: {}".format(
                form.owner.data))

        fcopr, created = ComplexLogic.fork_copr(copr,
                                                flask.g.user,
                                                dstname=form.name.data,
                                                dstgroup=dstgroup)
        if created:
            msg = (
                "Forking project {} for you into {}. Please be aware that it may take a few minutes "
                "to duplicate a backend data.".format(copr.full_name,
                                                      fcopr.full_name))
        elif not created and form.confirm.data == True:
            msg = (
                "Updating packages in {} from {}. Please be aware that it may take a few minutes "
                "to duplicate a backend data.".format(copr.full_name,
                                                      fcopr.full_name))
        else:
            return render_copr_fork(copr, form, confirm=True)

        db.session.commit()
        flask.flash(msg)

        return flask.redirect(url_for_copr_details(fcopr))
    return render_copr_fork(copr, form)
Esempio n. 2
0
    def test_fork_copr_sends_actions(self, mc_flask_g, f_users, f_coprs, f_mock_chroots, f_builds, f_db):
        mc_flask_g.user.name = self.u2.name
        fc1, created = ComplexLogic.fork_copr(self.c1, self.u2, u"dstname")
        self.db.session.commit()

        actions = ActionsLogic.get_many(ActionTypeEnum("fork")).all()
        assert len(actions) == 1
        data = json.loads(actions[0].data)
        assert data["user"] == self.u2.name
        assert data["copr"] == "dstname"

        last_build, forked_build = self.c1.packages[0].last_build(successful=True), fc1.builds[0]
        assert data["builds_map"] == {str(forked_build.id): str(last_build.result_dir_name)}
Esempio n. 3
0
    def test_fork_copr_sends_actions(self, f_users, f_coprs, f_mock_chroots, f_builds, f_db):
        with app.app_context():
            with mock.patch('flask.g') as mc_flask_g:
                mc_flask_g.user.name = self.u2.name
                fc1, created = ComplexLogic.fork_copr(self.c1, self.u2, u"dstname")
                self.db.session.commit()

                actions = ActionsLogic.get_many(ActionTypeEnum("fork")).all()
                assert len(actions) == 1
                data = json.loads(actions[0].data)
                assert data["user"] == self.u2.name
                assert data["copr"] == "dstname"
                assert data["builds_map"] == {'srpm-builds': {'bar': '00000005'},'fedora-18-x86_64': {'bar': '00000005-hello-world'}}
Esempio n. 4
0
def api_copr_fork(copr):
    """ Fork the project and builds in it
    """
    form = forms.CoprForkFormFactory\
        .create_form_cls(copr=copr, user=flask.g.user, groups=flask.g.user.user_groups)(csrf_enabled=False)

    # I have no idea why there is by default form.confirm.data equal to True
    form.confirm.data = flask.request.form["confirm"] == "True"

    if form.validate_on_submit() and copr:
        try:
            dstgroup = ([
                g for g in flask.g.user.user_groups
                if g.at_name == form.owner.data
            ] or [None])[0]
            if flask.g.user.name != form.owner.data and not dstgroup:
                return LegacyApiError("There is no such group: {}".format(
                    form.owner.data))

            fcopr, created = ComplexLogic.fork_copr(copr,
                                                    flask.g.user,
                                                    dstname=form.name.data,
                                                    dstgroup=dstgroup)
            if created:
                msg = (
                    "Forking project {} for you into {}.\nPlease be aware that it may take a few minutes "
                    "to duplicate a backend data.".format(
                        copr.full_name, fcopr.full_name))
            elif not created and form.confirm.data == True:
                msg = (
                    "Updating packages in {} from {}.\nPlease be aware that it may take a few minutes "
                    "to duplicate a backend data.".format(
                        copr.full_name, fcopr.full_name))
            else:
                raise LegacyApiError(
                    "You are about to fork into existing project: {}\n"
                    "Please use --confirm if you really want to do this".
                    format(fcopr.full_name))

            output = {"output": "ok", "message": msg}
            db.session.commit()

        except (exceptions.ActionInProgressException,
                exceptions.InsufficientRightsException) as err:
            db.session.rollback()
            raise LegacyApiError(str(err))
    else:
        raise LegacyApiError("Invalid request")

    return flask.jsonify(output)
Esempio n. 5
0
 def test_fork_copr_projects_with_more_builds(self, mc_flask_g, f_users, f_fork_prepare, f_db):
     mc_flask_g.user.name = self.u2.name
     fc2, created = ComplexLogic.fork_copr(self.c2, self.u2, u"dstname")
     self.db.session.commit()
     actions = ActionsLogic.get_many(ActionTypeEnum("fork")).all()
     assert len(actions) == 1
     data = json.loads(actions[0].data)
     assert data["user"] == self.u2.name
     assert data["copr"] == "dstname"
     assert data["builds_map"] == {
         'srpm-builds': {'00000008-whatsupthere-world': '00000012', '00000006-hello-world': '00000013',
                         '00000010-new-package': '00000014', '00000011-new-package': '00000015'},
         'fedora-17-x86_64': {'8-whatsupthere-world': '00000012-whatsupthere-world',
                              '6-hello-world': '00000013-hello-world',
                              '10-new-package': '00000014-new-package'},
         'fedora-17-i386': {'8-whatsupthere-world': '00000012-whatsupthere-world',
                            '6-hello-world': '00000013-hello-world',
                            '11-new-package': '00000015-new-package'}}
Esempio n. 6
0
def copr_fork_post(copr):
    form = forms.CoprForkFormFactory.create_form_cls(copr=copr, user=flask.g.user, groups=flask.g.user.user_groups)()
    if form.validate_on_submit():
        dstgroup = ([g for g in flask.g.user.user_groups if g.at_name == form.owner.data] or [None])[0]
        if flask.g.user.name != form.owner.data and not dstgroup:
            return generic_error("There is no such group: {}".format(form.owner.data))

        fcopr = CoprsLogic.get_by_group_id(dstgroup.id, form.name.data).first() if dstgroup \
            else CoprsLogic.filter_without_group_projects(CoprsLogic.get(flask.g.user.name, form.name.data)).first()

        if not fcopr:
            fcopr = ComplexLogic.fork_copr(copr, flask.g.user, dstname=form.name.data, dstgroup=dstgroup)
            db.session.commit()

            flask.flash("Forking project {} for you into {}. Please be aware that it may take a few minutes "
                        "to duplicate a backend data.".format(copr.full_name, fcopr.full_name))

        return flask.redirect(url_for_copr_details(fcopr))
    return render_copr_fork(copr, form)
Esempio n. 7
0
    def test_fork_copr_sends_actions(self, mc_flask_g, f_users, f_coprs, f_mock_chroots, f_builds, f_db):
        mc_flask_g.user.name = self.u2.name
        fc1, created = ComplexLogic.fork_copr(self.c1, self.u2, u"dstname")
        self.db.session.commit()

        actions = ActionsLogic.get_many(ActionTypeEnum("gen_gpg_key")).all()
        assert len(actions) == 1
        data = json.loads(actions[0].data)
        assert data["username"] == self.u2.name
        assert data["projectname"] == "dstname"

        actions = ActionsLogic.get_many(ActionTypeEnum("fork")).all()
        assert len(actions) == 1
        data = json.loads(actions[0].data)
        assert data["user"] == self.u2.name
        assert data["copr"] == "dstname"

        last_build, forked_build = self.c1.packages[0].builds[1], fc1.builds[0]
        assert data["builds_map"] == {str(forked_build.id): str(last_build.result_dir_name)}
Esempio n. 8
0
def copr_fork_post(copr):
    form = forms.CoprForkFormFactory.create_form_cls(copr=copr, user=flask.g.user, groups=flask.g.user.user_groups)()
    if form.validate_on_submit():
        dstgroup = ([g for g in flask.g.user.user_groups if g.at_name == form.owner.data] or [None])[0]
        if flask.g.user.name != form.owner.data and not dstgroup:
            return generic_error("There is no such group: {}".format(form.owner.data))

        fcopr, created = ComplexLogic.fork_copr(copr, flask.g.user, dstname=form.name.data, dstgroup=dstgroup)
        if created:
            msg = ("Forking project {} for you into {}. Please be aware that it may take a few minutes "
                   "to duplicate a backend data.".format(copr.full_name, fcopr.full_name))
        elif not created and form.confirm.data == True:
            msg = ("Updating packages in {} from {}. Please be aware that it may take a few minutes "
                   "to duplicate a backend data.".format(copr.full_name, fcopr.full_name))
        else:
            return render_copr_fork(copr, form, confirm=True)

        db.session.commit()
        flask.flash(msg)

        return flask.redirect(url_for_copr_details(fcopr))
    return render_copr_fork(copr, form)
Esempio n. 9
0
def fork_project(ownername, projectname):
    copr = get_copr(ownername, projectname)

    # @FIXME we want "ownername" from the outside, but our internal Form expects "owner" instead
    data = get_form_compatible_data()
    data["owner"] = data.get("ownername")

    form = forms.CoprForkFormFactory \
        .create_form_cls(copr=copr, user=flask.g.user, groups=flask.g.user.user_groups)(data, meta={'csrf': False})

    if form.validate_on_submit() and copr:
        try:
            dstgroup = ([
                g for g in flask.g.user.user_groups
                if g.at_name == form.owner.data
            ] or [None])[0]
            if flask.g.user.name != form.owner.data and not dstgroup:
                return ObjectNotFound("There is no such group: {}".format(
                    form.owner.data))

            fcopr, created = ComplexLogic.fork_copr(copr,
                                                    flask.g.user,
                                                    dstname=form.name.data,
                                                    dstgroup=dstgroup)
            if not created and form.confirm.data != True:
                raise BadRequest(
                    "You are about to fork into existing project: {}\n"
                    "Please use --confirm if you really want to do this".
                    format(fcopr.full_name))
            db.session.commit()

        except (ActionInProgressException, InsufficientRightsException) as err:
            db.session.rollback()
            raise err
    else:
        raise BadRequest(form.errors)

    return flask.jsonify(to_dict(fcopr))
Esempio n. 10
0
def api_copr_fork(copr):
    """ Fork the project and builds in it
    """
    form = forms.CoprForkFormFactory\
        .create_form_cls(copr=copr, user=flask.g.user, groups=flask.g.user.user_groups)(csrf_enabled=False)

    # I have no idea why there is by default form.confirm.data equal to True
    form.confirm.data = flask.request.form["confirm"] == "True"

    if form.validate_on_submit() and copr:
        try:
            dstgroup = ([g for g in flask.g.user.user_groups if g.at_name == form.owner.data] or [None])[0]
            if flask.g.user.name != form.owner.data and not dstgroup:
                return LegacyApiError("There is no such group: {}".format(form.owner.data))

            fcopr, created = ComplexLogic.fork_copr(copr, flask.g.user, dstname=form.name.data, dstgroup=dstgroup)
            if created:
                msg = ("Forking project {} for you into {}.\nPlease be aware that it may take a few minutes "
                       "to duplicate a backend data.".format(copr.full_name, fcopr.full_name))
            elif not created and form.confirm.data == True:
                msg = ("Updating packages in {} from {}.\nPlease be aware that it may take a few minutes "
                       "to duplicate a backend data.".format(copr.full_name, fcopr.full_name))
            else:
                raise LegacyApiError("You are about to fork into existing project: {}\n"
                                     "Please use --confirm if you really want to do this".format(fcopr.full_name))

            output = {"output": "ok", "message": msg}
            db.session.commit()

        except (exceptions.ActionInProgressException,
                exceptions.InsufficientRightsException) as err:
            db.session.rollback()
            raise LegacyApiError(str(err))
    else:
        raise LegacyApiError("Invalid request")

    return flask.jsonify(output)