Esempio n. 1
0
def package_request_branch(namespace, package, full=True):
    ''' Gives the possibility to request a new branch for this package. '''

    if not bool(full) or str(full) in ['0', 'False']:
        full = False

    try:
        package_acl = pkgdblib.get_acl_package(
            SESSION, namespace, package)
        package = pkgdblib.search_package(
            SESSION, namespace, package, limit=1)[0]
    except (NoResultFound, IndexError):
        SESSION.rollback()
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')

    branches = [
        pkg.collection.branchname
        for pkg in package_acl
        if pkg.collection.status != 'EOL'
    ]

    collections = pkgdb2.lib.search_collection(
        SESSION, '*', 'Under Development')
    collections.extend(pkgdb2.lib.search_collection(SESSION, '*', 'Active'))

    # List the possible branches that this package does not already have.
    branches_possible = [
        collec.branchname
        for collec in collections
        if collec.branchname not in branches]

    # Further limit that list to only the branches allowed for this namespace.
    namespace_policy = APP.config.get('PKGDB2_NAMESPACE_POLICY')
    policy = namespace_policy.get(pkg.package.namespace)
    if policy:
        branches_possible = [b for b in branches_possible if b in policy]

    form = pkgdb2.forms.BranchForm(collections=branches_possible)

    if form.validate_on_submit():
        for branch in form.branches.data:
            try:
                msg = pkgdblib.add_new_branch_request(
                    session=SESSION,
                    namespace=package.namespace,
                    pkg_name=package.name,
                    clt_to=branch,
                    user=flask.g.fas_user)
                SESSION.commit()
                flask.flash(msg)
            except pkgdblib.PkgdbException, err:  # pragma: no cover
                flask.flash(str(err), 'error')
                SESSION.rollback()
            except SQLAlchemyError, err:  # pragma: no cover
                APP.logger.exception(err)
                flask.flash(
                    'Could not save the request to the database for '
                    'branch: %s' % branch, 'error')
                SESSION.rollback()
Esempio n. 2
0
def package_request_branch(namespace, package, full=True):
    ''' Gives the possibility to request a new branch for this package. '''

    if not bool(full) or str(full) in ['0', 'False']:
        full = False

    try:
        package_acl = pkgdblib.get_acl_package(SESSION, namespace, package)
        package = pkgdblib.search_package(SESSION, namespace, package,
                                          limit=1)[0]
    except (NoResultFound, IndexError):
        SESSION.rollback()
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')

    branches = [
        pkg.collection.branchname for pkg in package_acl
        if pkg.collection.status != 'EOL'
    ]

    collections = pkgdb2.lib.search_collection(SESSION, '*',
                                               'Under Development')
    collections.extend(pkgdb2.lib.search_collection(SESSION, '*', 'Active'))
    branches_possible = [
        collec.branchname for collec in collections
        if collec.branchname not in branches
    ]

    form = pkgdb2.forms.BranchForm(collections=branches_possible)

    if form.validate_on_submit():
        for branch in form.branches.data:
            try:
                msg = pkgdblib.add_new_branch_request(
                    session=SESSION,
                    namespace=package.namespace,
                    pkg_name=package.name,
                    clt_to=branch,
                    user=flask.g.fas_user)
                SESSION.commit()
                flask.flash(msg)
            except pkgdblib.PkgdbException, err:  # pragma: no cover
                flask.flash(str(err), 'error')
                SESSION.rollback()
            except SQLAlchemyError, err:  # pragma: no cover
                APP.logger.exception(err)
                flask.flash(
                    'Could not save the request to the database for '
                    'branch: %s' % branch, 'error')
                SESSION.rollback()
Esempio n. 3
0
def api_branch_request(package, namespace='rpms'):
    '''
    New branch request
    ------------------
    Request a new branch for package in pkgdb.

    ::

        /api/request/branch/<namespace>/<package>

    Accepts POST queries only.

    :arg package: The name of the package
    :arg branches: The list of branches desired for this package.
    :arg namespace: The namespace of the package
        (default to ``rpms``).


    Sample response:

    ::

        {
          'messages': [
            'Branch f17 created for user pingou',
          ],
          'output': 'ok'
        }

        {
          "messages": [
            "Branch el6 requested for user pingou"
          ],
          "output": "ok"
        }

        {
          "output": "notok",
          'error': 'User "pingou" is not in the packager group',
        }

        {
          "error": "Invalid input submitted",
          "error_detail": [
            "branches: 'foobar' is not a valid choice for this field",
          ],
          "output": "notok"
        }

    '''
    httpcode = 200
    output = {}
    try:
        package_acl = pkgdblib.get_acl_package(SESSION, namespace, package)
        package = pkgdblib.search_package(
            SESSION, namespace, package, limit=1)[0]
    except (NoResultFound, IndexError):
        SESSION.rollback()
        output['output'] = 'notok'
        output['error'] = 'No package found: %s/%s' % (namespace, package)
        httpcode = 404
    else:

        branches = [
            pkg.collection.branchname
            for pkg in package_acl
            if pkg.collection.status != 'EOL'
        ]

        collections = pkgdblib.search_collection(
            SESSION, '*', 'Under Development')
        collections.extend(pkgdblib.search_collection(
            SESSION, '*', 'Active'))
        branches_possible = [
            collec.branchname
            for collec in collections
            if collec.branchname not in branches]

        form = forms.BranchForm(
            collections=branches_possible,
            csrf_enabled=False,
        )

        if form.validate_on_submit():
            try:
                messages = []
                for branch in form.branches.data:
                    msg = pkgdblib.add_new_branch_request(
                        session=SESSION,
                        namespace=namespace,
                        pkg_name=package.name,
                        clt_to=branch,
                        user=flask.g.fas_user)
                    if msg:
                        messages.append(msg)
                SESSION.commit()
                output['output'] = 'ok'
                output['messages'] = messages
            except pkgdblib.PkgdbException, err:  # pragma: no cover
                SESSION.rollback()
                output['output'] = 'notok'
                output['error'] = str(err)
                httpcode = 400
            except SQLAlchemyError, err:  # pragma: no cover
                SESSION.rollback()
                APP.logger.exception(err)
                output['output'] = 'notok'
                output['error'] = 'Could not save the request to the '\
                    'database for branch: %s' % branch
                httpcode = 400
Esempio n. 4
0
def package_request_branch(namespace, package, full=True):
    ''' Gives the possibility to request a new branch for this package. '''

    if not bool(full) or str(full) in ['0', 'False']:
        full = False

    try:
        package_acl = pkgdblib.get_acl_package(SESSION, namespace, package)
        package = pkgdblib.search_package(SESSION, namespace, package,
                                          limit=1)[0]
    except (NoResultFound, IndexError):
        SESSION.rollback()
        flask.flash('No package of this name found.', 'errors')
        return flask.render_template('msg.html')

    branches = [
        pkg.collection.branchname for pkg in package_acl
        if pkg.collection.status != 'EOL'
    ]

    collections = pkgdb2.lib.search_collection(SESSION, '*',
                                               'Under Development')
    collections.extend(pkgdb2.lib.search_collection(SESSION, '*', 'Active'))

    # List the possible branches that this package does not already have.
    branches_possible = [
        collec.branchname for collec in collections
        if collec.branchname not in branches
    ]

    # Further limit that list to only the branches allowed for this namespace.
    namespace_policy = APP.config.get('PKGDB2_NAMESPACE_POLICY')
    policy = namespace_policy.get(pkg.package.namespace)
    if policy:
        branches_possible = [b for b in branches_possible if b in policy]

    form = pkgdb2.forms.BranchForm(collections=branches_possible)

    if form.validate_on_submit():
        for branch in form.branches.data:
            try:
                msg = pkgdblib.add_new_branch_request(
                    session=SESSION,
                    namespace=package.namespace,
                    pkg_name=package.name,
                    clt_to=branch,
                    user=flask.g.fas_user)
                SESSION.commit()
                flask.flash(msg)
            except PkgdbException as err:  # pragma: no cover
                flask.flash(str(err), 'error')
                SESSION.rollback()
            except SQLAlchemyError as err:  # pragma: no cover
                APP.logger.exception(err)
                flask.flash(
                    'Could not save the request to the database for '
                    'branch: %s' % branch, 'error')
                SESSION.rollback()

        return flask.redirect(
            flask.url_for('.package_info',
                          namespace=package.namespace,
                          package=package.name))

    return flask.render_template(
        'request_branch.html',
        full=full,
        package=package,
        form=form,
        action='request_branch',
    )