示例#1
0
def package_retire(package, collection):
    ''' Gives the possibility to orphan or take a package. '''

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

    for acl in package_acl:
        if acl.collection.branchname == collection:
            if acl.point_of_contact == 'orphan':
                try:
                    pkgdblib.update_pkg_status(
                        session=SESSION,
                        pkg_name=package.name,
                        clt_name=acl.collection.branchname,
                        status='Deprecated',
                        user=flask.g.fas_user)
                    flask.flash('This package has been retired on branch: %s' %
                                collection)
                except pkgdblib.PkgdbException, err:
                    flask.flash(err.message, 'error')
                break
            else:
                flask.flash('This package has not been orphaned on '
                            'branch: %s' % collection)
示例#2
0
def api_packager_acl(packagername=None):
    ''' List the pending ACL action of the user.

    :arg username: String of the packager name.

    '''
    httpcode = 200
    output = {}

    packagername = flask.request.args.get('packagername', None) or packagername
    if packagername:
        packagers = pkgdblib.get_acl_packager(
            SESSION,
            packager=packagername,
        )
        SESSION.commit()
        output['output'] = 'ok'
        output['acls'] = [pkg.to_json() for pkg in packagers]
    else:
        output = {'output': 'notok', 'error': 'Invalid request'}
        httpcode = 500

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout
示例#3
0
def package_orphan(package, collection):
    ''' Gives the possibility to orphan or take a package. '''

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

    for acl in package_acl:
        if acl.collection.branchname == collection:
            try:
                pkgdblib.update_pkg_poc(session=SESSION,
                                        pkg_name=package.name,
                                        clt_name=acl.collection.branchname,
                                        pkg_poc='orphan',
                                        user=flask.g.fas_user)
                flask.flash(
                    'You are no longer point of contact on branch: %s' %
                    collection)
            except pkgdblib.PkgdbException, err:
                flask.flash(err.message, 'error')
            break
示例#4
0
def comaintain_package(package):
    if not 'packager' in flask.g.fas_user.groups:
        flask.flash(
            'You must be a packager to apply to be a comaintainer',
            'errors')
        return flask.redirect(flask.url_for(
            '.package_info', package=package))

    pkg = pkgdblib.search_package(SESSION, pkg_name=package, limit=1)[0]
    pkg_acls = ['commit', 'watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]

    try:
        for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
            acl_status = 'Awaiting Review'
            if acl in APP.config['AUTO_APPROVE']:
                acl_status = 'Approved'
            pkgdblib.set_acl_package(
                SESSION,
                pkg_name=package,
                clt_name=collec,
                pkg_user=flask.g.fas_user.username,
                acl=acl,
                status=acl_status,
                user=flask.g.fas_user,
            )
        SESSION.commit()
        flask.flash('ACLs updated')
        return flask.redirect(
            flask.url_for('.package_info',
                          package=package))
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        flask.flash(err.message, 'error')
示例#5
0
def api_packager_list(pattern=None):
    ''' List packagers.

    :kwarg pattern: String of the pattern to use to list find packagers.
        If no pattern is provided, it returns the list of all packagers.

    '''
    httpcode = 200
    output = {}

    pattern = flask.request.args.get('pattern', None) or pattern
    if pattern:
        packagers = pkgdblib.search_packagers(
            SESSION,
            pattern=pattern,
        )
        packagers = [pkg[0] for pkg in packagers]
        SESSION.commit()
        output['output'] = 'ok'
        output['packagers'] = packagers
    else:
        output = {'output': 'notok', 'error': 'Invalid request'}
        httpcode = 500

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout
示例#6
0
def packager_info(packager):
    ''' Display the information about the specified packager. '''

    packages = []
    packages_co = []
    try:
        packages_co = pkgdblib.get_package_maintained(SESSION,
                                                      packager=packager)
    except NoResultFound:
        SESSION.rollback()

    # clean co-maintained packages and split out PoC packages
    cnt = 0
    while cnt < len(packages_co):
        maint = []
        for acls in packages_co[cnt].listings:
            maint.append(acls.point_of_contact)
        if packager in maint:
            packages.append(packages_co[cnt])
            del (packages_co[cnt])
            cnt -= 1
        cnt += 1

    if not packages and not packages_co:
        flask.flash('No packager of this name found.', 'errors')
        return flask.render_template('msg.html')

    return flask.render_template(
        'packager.html',
        packager=packager,
        packages=packages,
        packages_co=packages_co,
    )
示例#7
0
def package_retire(package, collection):
    ''' Gives the possibility to orphan or take a package. '''

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

    for acl in package_acl:
        if acl.collection.branchname == collection:
            if acl.point_of_contact == 'orphan':
                try:
                    pkgdblib.update_pkg_status(
                        session=SESSION,
                        pkg_name=package.name,
                        pkg_branch=acl.collection.branchname,
                        status='Retired',
                        user=flask.g.fas_user
                    )
                    flask.flash(
                        'This package has been retired on branch: %s'
                        % collection)
                except pkgdblib.PkgdbException, err:
                    flask.flash(err.message, 'error')
                    SESSION.rollback()
                break
            else:
                flask.flash(
                    'This package has not been orphaned on '
                    'branch: %s' % collection)
示例#8
0
def comaintain_package(package):
    if not 'packager' in flask.g.fas_user.groups:
        flask.flash('You must be a packager to apply to be a comaintainer',
                    'errors')
        return flask.redirect(flask.url_for('.package_info', package=package))

    pkg = pkgdblib.search_package(SESSION, pkg_name=package, limit=1)[0]
    pkg_acls = ['commit', 'watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]

    try:
        for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
            acl_status = 'Awaiting Review'
            if acl in APP.config['AUTO_APPROVE']:
                acl_status = 'Approved'
            pkgdblib.set_acl_package(
                SESSION,
                pkg_name=package,
                clt_name=collec,
                pkg_user=flask.g.fas_user.username,
                acl=acl,
                status=acl_status,
                user=flask.g.fas_user,
            )
        SESSION.commit()
        flask.flash('ACLs updated')
        return flask.redirect(flask.url_for('.package_info', package=package))
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        flask.flash(err.message, 'error')
示例#9
0
def packager_info(packager):
    ''' Display the information about the specified packager. '''

    packages = []
    packages_co = []
    try:
        packages_co = pkgdblib.get_package_maintained(
            SESSION,
            packager=packager
        )
    except NoResultFound:
        SESSION.rollback()

    # clean co-maintained packages and split out PoC packages
    cnt = 0
    while cnt < len(packages_co):
        maint = []
        for acls in packages_co[cnt].listings:
            maint.append(acls.point_of_contact)
        if packager in maint:
            packages.append(packages_co[cnt])
            del(packages_co[cnt])
            cnt -= 1
        cnt += 1

    if not packages and not packages_co:
        flask.flash('No packager of this name found.', 'errors')
        return flask.render_template('msg.html')

    return flask.render_template(
        'packager.html',
        packager=packager,
        packages=packages,
        packages_co=packages_co,
    )
示例#10
0
def api_packager_list(pattern=None):
    ''' List packagers.

    :kwarg pattern: String of the pattern to use to list find packagers.
        If no pattern is provided, it returns the list of all packagers.

    '''
    httpcode = 200
    output = {}

    pattern = flask.request.args.get('pattern', None) or pattern
    if pattern:
        packagers = pkgdblib.search_packagers(SESSION,
                                              pattern=pattern,
                                              )
        packagers = [pkg[0] for pkg in packagers]
        SESSION.commit()
        output['output'] = 'ok'
        output['packagers'] = packagers
    else:
        output = {'output': 'notok', 'error': 'Invalid request'}
        httpcode = 500

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout
示例#11
0
def watch_package(package):
    ''' Request watch* ACLs on a package.
    Anyone can request these ACLs, no need to be a packager.
    '''
    try:
        pkg = pkgdblib.search_package(SESSION, pkg_name=package, limit=1)[0]
    except IndexError:
        flask.flash('No package found by this name', 'error')
        return flask.redirect(
            flask.url_for('.package_info', package=package))

    pkg_acls = ['watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]
    try:
        for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
            pkgdblib.set_acl_package(
                SESSION,
                pkg_name=package,
                pkg_branch=collec,
                pkg_user=flask.g.fas_user.username,
                acl=acl,
                status='Approved',
                user=flask.g.fas_user,
            )
        SESSION.commit()
        flask.flash('ACLs updated')
    # Let's keep this in although we should never see it
    except pkgdblib.PkgdbException, err:  # pragma: no cover
        SESSION.rollback()
        flask.flash(err.message, 'error')
示例#12
0
def package_orphan(package, collection):
    ''' Gives the possibility to orphan or take a package. '''

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

    for acl in package_acl:
        if acl.collection.branchname == collection:
            try:
                pkgdblib.update_pkg_poc(
                    session=SESSION,
                    pkg_name=package.name,
                    clt_name=acl.collection.branchname,
                    pkg_poc='orphan',
                    user=flask.g.fas_user
                )
                flask.flash(
                    'You are no longer point of contact on branch: %s'
                    % collection)
            except pkgdblib.PkgdbException, err:
                flask.flash(err.message, 'error')
            break
示例#13
0
def collection_new():
    ''' Page to create a new collection. '''

    clt_status = pkgdb.lib.get_status(SESSION, 'clt_status')['clt_status']
    form = pkgdb.forms.AddCollectionForm(clt_status=clt_status)
    if form.validate_on_submit():
        clt_name = form.collection_name.data
        clt_version = form.collection_version.data
        clt_status = form.collection_status.data
        clt_branchname = form.collection_branchname.data
        clt_disttag = form.collection_distTag.data
        clt_gitbranch = form.collection_git_branch_name.data

        try:
            message = pkgdblib.add_collection(
                SESSION,
                clt_name=clt_name,
                clt_version=clt_version,
                clt_status=clt_status,
                clt_branchname=clt_branchname,
                clt_disttag=clt_disttag,
                clt_gitbranch=clt_gitbranch,
                user=flask.g.fas_user,
            )
            SESSION.commit()
            flask.flash(message)
            return flask.redirect(flask.url_for('.list_collections'))
        # In theory we should never hit this
        except pkgdblib.PkgdbException, err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(err.message, 'errors')
示例#14
0
def api_packager_list(pattern=None):
    '''
List packagers
--------------
    List packagers based on a pattern. If no pattern is provided, return
    all the packagers.

    ::

        /api/packagers/<pattern>/

        /api/packagers/?pattern=<pattern>

    :kwarg pattern: String of the pattern to use to list find packagers.
        If no pattern is provided, it returns the list of all packagers.


    Sample response:

    ::

        /api/packagers/rem*

        {
          "output": "ok",
          "packagers": [
            "remi"
          ]
        }

        /api/packagers/?pattern=pi*

        {
          "output": "ok",
          "packagers": [
            "pilcher",
            "pingou"
          ]
        }
    '''
    httpcode = 200
    output = {}

    pattern = flask.request.args.get('pattern', None) or pattern
    if pattern:
        packagers = pkgdblib.search_packagers(SESSION,
                                              pattern=pattern,
                                              )
        packagers = [pkg[0] for pkg in packagers]
        SESSION.commit()
        output['output'] = 'ok'
        output['packagers'] = packagers
    else:
        output = {'output': 'notok', 'error': 'Invalid request'}
        httpcode = 500

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout
示例#15
0
def package_info(package):
    ''' Display the information about the specified package. '''

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

    package_acls = []
    branch_admin = []
    is_poc = False
    for pkg in package_acl:
        tmp = {}
        tmp['collection'] = '%s %s' % (pkg.collection.name,
                                       pkg.collection.version)
        tmp['branchname'] = pkg.collection.branchname
        tmp['point_of_contact'] = pkg.point_of_contact
        if hasattr(flask.g, 'fas_user') and flask.g.fas_user and \
                pkg.point_of_contact == flask.g.fas_user.username:
            is_poc = True
        acls = {}
        for acl in pkg.acls:
            tmp2 = {'acl': acl.acl, 'status': acl.status}
            if acl.fas_name in acls:
                acls[acl.fas_name].append(tmp2)
            else:
                acls[acl.fas_name] = [tmp2]
        ## This list is a little hacky, but we would have to save ACLs
        ## in their own table otherwise.
        planned_acls = set(['approveacls', 'commit', 'watchbugzilla',
                            'watchcommits'])
        seen_acls = set([aclobj['acl'] for aclobj in acls[acl.fas_name]])
        for aclname in planned_acls - seen_acls:
            acls[acl.fas_name].append({'acl': aclname, 'status': ''})
        tmp['acls'] = acls
        package_acls.append(tmp)
        if is_pkg_admin(flask.g.fas_user, package.name,
                        pkg.collection.branchname):
            branch_admin.append(pkg.collection.branchname)

    return flask.render_template(
        'package.html',
        package=package,
        package_acl=package_acls,
        branch_admin=branch_admin,
        is_poc=is_poc,
    )
示例#16
0
def package_info(package):
    ''' Display the information about the specified package. '''

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

    package_acls = []
    branch_admin = []
    is_poc = False
    for pkg in package_acl:
        tmp = {}
        tmp['collection'] = '%s %s' % (pkg.collection.name,
                                       pkg.collection.version)
        tmp['branchname'] = pkg.collection.branchname
        tmp['point_of_contact'] = pkg.point_of_contact
        if hasattr(flask.g, 'fas_user') and flask.g.fas_user and \
                pkg.point_of_contact == flask.g.fas_user.username:
            is_poc = True
        acls = {}
        for acl in pkg.acls:
            tmp2 = {'acl': acl.acl, 'status': acl.status}
            if acl.fas_name in acls:
                acls[acl.fas_name].append(tmp2)
            else:
                acls[acl.fas_name] = [tmp2]
        ## This list is a little hacky, but we would have to save ACLs
        ## in their own table otherwise.
        planned_acls = set(
            ['approveacls', 'commit', 'watchbugzilla', 'watchcommits'])
        seen_acls = set([aclobj['acl'] for aclobj in acls[acl.fas_name]])
        for aclname in planned_acls - seen_acls:
            acls[acl.fas_name].append({'acl': aclname, 'status': ''})
        tmp['acls'] = acls
        package_acls.append(tmp)
        if is_pkg_admin(flask.g.fas_user, package.name,
                        pkg.collection.branchname):
            branch_admin.append(pkg.collection.branchname)

    return flask.render_template(
        'package.html',
        package=package,
        package_acl=package_acls,
        branch_admin=branch_admin,
        is_poc=is_poc,
    )
示例#17
0
def update_acl(package, user, branch=None):
    ''' Update the acls for a specific user on a package. '''

    pending_acls = pkgdblib.get_acl_user_package(SESSION,
                                                 user,
                                                 package,
                                                 status=None)
    if branch is not None:
        pending_acls2 = []
        for acls in pending_acls:
            if acls['collection'] == branch:
                pending_acls2.append(acls)
        pending_acls = pending_acls2

    collections = set([item['collection'] for item in pending_acls])
    status = pkgdb.lib.get_status(SESSION, ['pkg_acl', 'pkg_status'])

    form = pkgdb.forms.UpdateAclPackageForm(
        collections=collections,
        pkg_acl_list=status['pkg_acl'],
        pkg_status=status['pkg_status'],
    )

    if form.validate_on_submit():
        pkg_branchs = form.pkg_branch.data
        pkg_acls = form.pkg_acl.data
        acl_status = form.acl_status.data

        try:
            branch_out = []
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
                if collec in branch_out:
                    continue

                if acl_status == 'Awaiting Review' and \
                        acl in APP.config['AUTO_APPROVE']:
                    acl_status = 'Approved'

                pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=package,
                    clt_name=collec,
                    pkg_user=user,
                    acl=acl,
                    status=acl_status,
                    user=flask.g.fas_user,
                )
                flask.flash('ACLs updated')
            SESSION.commit()
            return flask.redirect(
                flask.url_for('.package_info', package=package))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'errors')
示例#18
0
def update_acl(package, user, branch=None):
    ''' Update the acls for a specific user on a package. '''

    pending_acls = pkgdblib.get_acl_user_package(
        SESSION, user, package, status=None)
    if branch is not None:
        pending_acls2 = []
        for acls in pending_acls:
            if acls['collection'] == branch:
                pending_acls2.append(acls)
        pending_acls = pending_acls2

    collections = set([item['collection'] for item in pending_acls])
    status = pkgdb.lib.get_status(SESSION, ['pkg_acl', 'pkg_status'])

    form = pkgdb.forms.UpdateAclPackageForm(
        collections=collections,
        pkg_acl_list=status['pkg_acl'],
        pkg_status=status['pkg_status'],
        )

    if form.validate_on_submit():
        pkg_branchs = form.pkg_branch.data
        pkg_acls = form.pkg_acl.data
        acl_status = form.acl_status.data

        try:
            branch_out = []
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
                if collec in branch_out:
                    continue

                if acl_status == 'Awaiting Review' and \
                        acl in APP.config['AUTO_APPROVE']:
                    acl_status = 'Approved'

                pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=package,
                    clt_name=collec,
                    pkg_user=user,
                    acl=acl,
                    status=acl_status,
                    user=flask.g.fas_user,
                )
                flask.flash('ACLs updated')
            SESSION.commit()
            return flask.redirect(
                flask.url_for('.package_info',
                              package=package))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'errors')
示例#19
0
def package_take(package, collection):
    ''' Make someone Point of contact of an orphaned package. '''

    try:
        pkgdblib.unorphan_package(session=SESSION,
                                  pkg_name=package,
                                  clt_name=collection,
                                  pkg_user=flask.g.fas_user.username,
                                  user=flask.g.fas_user)
        SESSION.commit()
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        flask.flash(err.message, 'error')
示例#20
0
def package_take(package, collection):
    ''' Make someone Point of contact of an orphaned package. '''

    try:
        pkgdblib.unorphan_package(
            session=SESSION,
            pkg_name=package,
            clt_name=collection,
            pkg_user=flask.g.fas_user.username,
            user=flask.g.fas_user
        )
        SESSION.commit()
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        flask.flash(err.message, 'error')
示例#21
0
def collection_info(collection):
    ''' Display the information about the specified collection. '''

    collections = []
    try:
        collection = pkgdblib.search_collection(SESSION, collection)[0]
    except NoResultFound:
        SESSION.rollback()
    except IndexError:
        flask.flash('No collection of this name found.', 'errors')
        return flask.render_template('msg.html')

    return flask.render_template(
        'collection.html',
        collection=collection,
    )
示例#22
0
def collection_info(collection):
    ''' Display the information about the specified collection. '''

    collections = []
    try:
        collection = pkgdblib.search_collection(SESSION, collection)[0]
    except NoResultFound:
        SESSION.rollback()
    except IndexError:
        flask.flash('No collection of this name found.', 'errors')
        return flask.render_template('msg.html')

    return flask.render_template(
        'collection.html',
        collection=collection,
    )
示例#23
0
def package_new():
    ''' Page to create a new package. '''

    collections = pkgdb.lib.search_collection(
        SESSION, '*', 'Under Development')
    collections.extend(pkgdb.lib.search_collection(SESSION, '*', 'Active'))
    pkg_status = pkgdb.lib.get_status(SESSION, 'pkg_status')['pkg_status']

    form = pkgdb.forms.AddPackageForm(
        collections=collections,
        pkg_status_list=pkg_status,
    )
    if form.validate_on_submit():
        pkg_name = form.pkg_name.data
        pkg_summary = form.pkg_summary.data
        pkg_description = form.pkg_description.data
        pkg_review_url = form.pkg_reviewURL.data
        pkg_status = form.pkg_status.data
        pkg_shouldopen = form.pkg_shouldopen.data
        pkg_critpath = form.pkg_critpath.data
        pkg_collection = form.pkg_collection.data
        pkg_poc = form.pkg_poc.data
        pkg_upstream_url = form.pkg_upstreamURL.data

        try:
            message = pkgdblib.add_package(
                SESSION,
                pkg_name=pkg_name,
                pkg_summary=pkg_summary,
                pkg_description=pkg_description,
                pkg_reviewURL=pkg_review_url,
                pkg_status=pkg_status,
                pkg_shouldopen=pkg_shouldopen,
                pkg_critpath=pkg_critpath,
                pkg_collection=pkg_collection,
                pkg_poc=pkg_poc,
                pkg_upstreamURL=pkg_upstream_url,
                user=flask.g.fas_user,
            )
            SESSION.commit()
            flask.flash(message)
            return flask.redirect(flask.url_for('.list_packages'))
        # Keep it in, but normally we shouldn't hit this
        except pkgdblib.PkgdbException, err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(err.message, 'error')
示例#24
0
def request_acl(package):
    ''' Request acls for a specific package. '''

    collections = pkgdb.lib.search_collection(
        SESSION, '*', 'Under Development')
    collections.extend(pkgdb.lib.search_collection(SESSION, '*', 'Active'))
    pkg_acl = pkgdb.lib.get_status(SESSION, 'pkg_acl')['pkg_acl']

    form = pkgdb.forms.RequestAclPackageForm(
        collections=collections,
        pkg_acl_list=pkg_acl
        )
    if form.validate_on_submit():
        pkg_branchs = form.pkg_branch.data
        pkg_acls = form.pkg_acl.data

        try:
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
                acl_status = 'Awaiting Review'
                if acl in APP.config['AUTO_APPROVE']:
                    acl_status = 'Approved'
                elif 'packager' not in flask.g.fas_user.groups:
                    flask.flash(
                        'You must be a packager to apply to the'
                        ' ACL: %s on %s' % (acl, collec), 'errors')
                    continue

                pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=package,
                    clt_name=collec,
                    pkg_user=flask.g.fas_user.username,
                    acl=acl,
                    status=acl_status,
                    user=flask.g.fas_user,
                )
            SESSION.commit()
            flask.flash('ACLs updated')
            return flask.redirect(
                flask.url_for('.package_info',
                              package=package))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'error')
示例#25
0
def comaintain_package(package):
    ''' Asks for ACLs to co-maintain a package.
    You need to be a packager to request co-maintainership.
    '''
    # This is really wearing belt and suspenders, the decorator above
    # should take care of this
    if not 'packager' in flask.g.fas_user.groups:  # pragma: no cover
        flask.flash(
            'You must be a packager to apply to be a comaintainer',
            'errors')
        return flask.redirect(flask.url_for(
            '.package_info', package=package))

    try:
        pkg = pkgdblib.search_package(SESSION, pkg_name=package, limit=1)[0]
    except IndexError:
        flask.flash('No package found by this name', 'error')
        return flask.redirect(
            flask.url_for('.package_info', package=package))

    pkg_acls = ['commit', 'watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]

    try:
        for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
            acl_status = 'Awaiting Review'
            if acl in APP.config['AUTO_APPROVE']:
                acl_status = 'Approved'
            pkgdblib.set_acl_package(
                SESSION,
                pkg_name=package,
                pkg_branch=collec,
                pkg_user=flask.g.fas_user.username,
                acl=acl,
                status=acl_status,
                user=flask.g.fas_user,
            )
        SESSION.commit()
        flask.flash('ACLs updated')
    # Let's keep this in although we should never see it
    except pkgdblib.PkgdbException, err:  # pragma: no cover
        SESSION.rollback()
        flask.flash(err.message, 'error')
示例#26
0
def collection_edit(collection):
    ''' Allows to edit the information about the specified collection. '''

    try:
        collection = pkgdblib.search_collection(SESSION, collection)[0]
    except IndexError:
        flask.flash('No collection of this name found.', 'errors')
        return flask.render_template('msg.html')

    clt_status = pkgdb.lib.get_status(SESSION, 'clt_status')['clt_status']
    form = pkgdb.forms.AddCollectionForm(
        clt_status=clt_status
    )

    if form.validate_on_submit():
        clt_name = form.collection_name.data
        clt_version = form.collection_version.data
        clt_status = form.collection_status.data
        clt_branchname = form.collection_branchname.data
        clt_disttag = form.collection_distTag.data
        clt_gitbranch = form.collection_git_branch_name.data

        try:
            pkgdblib.edit_collection(
                SESSION,
                collection=collection,
                clt_name=clt_name,
                clt_version=clt_version,
                clt_status=clt_status,
                clt_branchname=clt_branchname,
                clt_disttag=clt_disttag,
                clt_gitbranch=clt_gitbranch,
                user=flask.g.fas_user,
            )
            SESSION.commit()
            flask.flash('Collection "%s" edited' % clt_branchname)
            return flask.redirect(flask.url_for(
                '.collection_info', collection=collection.branchname))
        # In theory we should never hit this
        except pkgdblib.PkgdbException, err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(err.message, 'errors')
示例#27
0
def request_acl(package):
    ''' Request acls for a specific package. '''

    collections = pkgdb.lib.search_collection(SESSION, '*',
                                              'Under Development')
    collections.extend(pkgdb.lib.search_collection(SESSION, '*', 'Active'))
    pkg_acl = pkgdb.lib.get_status(SESSION, 'pkg_acl')['pkg_acl']

    form = pkgdb.forms.RequestAclPackageForm(collections=collections,
                                             pkg_acl_list=pkg_acl)
    if form.validate_on_submit():
        pkg_branchs = form.pkg_branch.data
        pkg_acls = form.pkg_acl.data

        try:
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
                acl_status = 'Awaiting Review'
                if acl in APP.config['AUTO_APPROVE']:
                    acl_status = 'Approved'
                elif 'packager' not in flask.g.fas_user.groups:
                    flask.flash(
                        'You must be a packager to apply to the'
                        ' ACL: %s on %s' % (acl, collec), 'errors')
                    continue

                pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=package,
                    clt_name=collec,
                    pkg_user=flask.g.fas_user.username,
                    acl=acl,
                    status=acl_status,
                    user=flask.g.fas_user,
                )
            SESSION.commit()
            flask.flash('ACLs updated')
            return flask.redirect(
                flask.url_for('.package_info', package=package))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'error')
示例#28
0
def package_new():
    ''' Page to create a new package. '''

    collections = pkgdb.lib.search_collection(SESSION, '*',
                                              'Under Development')
    collections.extend(pkgdb.lib.search_collection(SESSION, '*', 'Active'))
    pkg_status = pkgdb.lib.get_status(SESSION, 'pkg_status')['pkg_status']

    form = pkgdb.forms.AddPackageForm(
        collections=collections,
        pkg_status_list=pkg_status,
    )
    if form.validate_on_submit():
        pkg_name = form.pkg_name.data
        pkg_summary = form.pkg_summary.data
        pkg_reviewURL = form.pkg_reviewURL.data
        pkg_status = form.pkg_status.data
        pkg_shouldopen = form.pkg_shouldopen.data
        pkg_collection = form.pkg_collection.data
        pkg_poc = form.pkg_poc.data
        pkg_upstreamURL = form.pkg_upstreamURL.data

        try:
            message = pkgdblib.add_package(
                SESSION,
                pkg_name=pkg_name,
                pkg_summary=pkg_summary,
                pkg_reviewURL=pkg_reviewURL,
                pkg_status=pkg_status,
                pkg_shouldopen=pkg_shouldopen,
                pkg_collection=pkg_collection,
                pkg_poc=pkg_poc,
                pkg_upstreamURL=pkg_upstreamURL,
                user=flask.g.fas_user,
            )
            SESSION.commit()
            flask.flash(message)
            return flask.redirect(flask.url_for('.list_packages'))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'error')
示例#29
0
def watch_package(package):
    pkg = pkgdblib.search_package(SESSION, pkg_name=package)[0]
    pkg_acls = ['watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]
    try:
        for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
            pkgdblib.set_acl_package(
                SESSION,
                pkg_name=package,
                clt_name=collec,
                pkg_user=flask.g.fas_user.username,
                acl=acl,
                status='Approved',
                user=flask.g.fas_user,
            )
        SESSION.commit()
        flask.flash('ACLs updated')
        return flask.redirect(flask.url_for('.package_info', package=package))
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        flask.flash(err.message, 'error')
示例#30
0
def collection_new():
    ''' Page to create a new collection. '''

    clt_status = pkgdb.lib.get_status(SESSION, 'clt_status')['clt_status']
    form = pkgdb.forms.AddCollectionForm(clt_status=clt_status)
    if form.validate_on_submit():
        clt_name = form.collection_name.data
        clt_version = form.collection_version.data
        clt_status = form.collection_status.data
        clt_publishurl = form.collection_publishURLTemplate.data
        clt_pendingurl = form.collection_pendingURLTemplate.data
        clt_summary = form.collection_summary.data
        clt_description = form.collection_description.data
        clt_branchname = form.collection_branchname.data
        clt_disttag = form.collection_distTag.data
        clt_gitbranch = form.collection_git_branch_name.data

        try:
            message = pkgdblib.add_collection(
                SESSION,
                clt_name=clt_name,
                clt_version=clt_version,
                clt_status=clt_status,
                clt_publishurl=clt_publishurl,
                clt_pendingurl=clt_pendingurl,
                clt_summary=clt_summary,
                clt_description=clt_description,
                clt_branchname=clt_branchname,
                clt_disttag=clt_disttag,
                clt_gitbranch=clt_gitbranch,
                user=flask.g.fas_user,
            )
            SESSION.commit()
            flask.flash(message)
            return flask.redirect(flask.url_for('.list_collections'))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'errors')
示例#31
0
def collection_new():
    ''' Page to create a new collection. '''

    clt_status = pkgdb.lib.get_status(SESSION, 'clt_status')['clt_status']
    form = pkgdb.forms.AddCollectionForm(clt_status=clt_status)
    if form.validate_on_submit():
        clt_name = form.collection_name.data
        clt_version = form.collection_version.data
        clt_status = form.collection_status.data
        clt_publishurl = form.collection_publishURLTemplate.data
        clt_pendingurl = form.collection_pendingURLTemplate.data
        clt_summary = form.collection_summary.data
        clt_description = form.collection_description.data
        clt_branchname = form.collection_branchname.data
        clt_disttag = form.collection_distTag.data
        clt_gitbranch = form.collection_git_branch_name.data

        try:
            message = pkgdblib.add_collection(
                SESSION,
                clt_name=clt_name,
                clt_version=clt_version,
                clt_status=clt_status,
                clt_publishurl=clt_publishurl,
                clt_pendingurl=clt_pendingurl,
                clt_summary=clt_summary,
                clt_description=clt_description,
                clt_branchname=clt_branchname,
                clt_disttag=clt_disttag,
                clt_gitbranch=clt_gitbranch,
                user=flask.g.fas_user,
            )
            SESSION.commit()
            flask.flash(message)
            return flask.redirect(flask.url_for('.list_collections'))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'errors')
示例#32
0
def watch_package(package):
    pkg = pkgdblib.search_package(SESSION, pkg_name=package)[0]
    pkg_acls = ['watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]
    try:
        for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
            pkgdblib.set_acl_package(
                SESSION,
                pkg_name=package,
                clt_name=collec,
                pkg_user=flask.g.fas_user.username,
                acl=acl,
                status='Approved',
                user=flask.g.fas_user,
            )
        SESSION.commit()
        flask.flash('ACLs updated')
        return flask.redirect(
            flask.url_for('.package_info',
                          package=package))
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        flask.flash(err.message, 'error')
示例#33
0
def api_packager_acl(packagername=None):
    ''' List the pending ACL action of the user.

    :arg username: String of the packager name.

    '''
    httpcode = 200
    output = {}

    packagername = flask.request.args.get('packagername', None) or packagername
    if packagername:
        packagers = pkgdblib.get_acl_packager(SESSION,
                                              packager=packagername,
                                              )
        SESSION.commit()
        output['output'] = 'ok'
        output['acls'] = [pkg.to_json() for pkg in packagers]
    else:
        output = {'output': 'notok', 'error': 'Invalid request'}
        httpcode = 500

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout
示例#34
0
def collection_edit(collection):
    ''' Allows to edit the information about the specified collection. '''

    collections = []
    try:
        collection = pkgdblib.search_collection(SESSION, collection)[0]
    except NoResultFound:
        SESSION.rollback()
    except IndexError:
        flask.flash('No collection of this name found.', 'errors')
        return flask.render_template('msg.html')

    clt_status = pkgdb.lib.get_status(SESSION, 'clt_status')['clt_status']
    form = pkgdb.forms.AddCollectionForm(
        clt_status=clt_status
    )

    if form.validate_on_submit():
        clt_name = form.collection_name.data
        clt_version = form.collection_version.data
        clt_status = form.collection_status.data
        clt_publishurl = form.collection_publishURLTemplate.data
        clt_pendingurl = form.collection_pendingURLTemplate.data
        clt_summary = form.collection_summary.data
        clt_description = form.collection_description.data
        clt_branchname = form.collection_branchname.data
        clt_disttag = form.collection_distTag.data
        clt_gitbranch = form.collection_git_branch_name.data

        try:
            pkgdblib.edit_collection(
                SESSION,
                collection=collection,
                clt_name=clt_name,
                clt_version=clt_version,
                clt_status=clt_status,
                clt_publishurl=clt_publishurl,
                clt_pendingurl=clt_pendingurl,
                clt_summary=clt_summary,
                clt_description=clt_description,
                clt_branchname=clt_branchname,
                clt_disttag=clt_disttag,
                clt_gitbranch=clt_gitbranch,
                user=flask.g.fas_user,
            )
            SESSION.commit()
            flask.flash('Collection "%s" edited' % clt_name)
            return flask.redirect(flask.url_for(
                '.collection_info', collection=collection.branchname))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'errors')
示例#35
0
def collection_edit(collection):
    ''' Allows to edit the information about the specified collection. '''

    collections = []
    try:
        collection = pkgdblib.search_collection(SESSION, collection)[0]
    except NoResultFound:
        SESSION.rollback()
    except IndexError:
        flask.flash('No collection of this name found.', 'errors')
        return flask.render_template('msg.html')

    clt_status = pkgdb.lib.get_status(SESSION, 'clt_status')['clt_status']
    form = pkgdb.forms.AddCollectionForm(clt_status=clt_status)

    if form.validate_on_submit():
        clt_name = form.collection_name.data
        clt_version = form.collection_version.data
        clt_status = form.collection_status.data
        clt_publishurl = form.collection_publishURLTemplate.data
        clt_pendingurl = form.collection_pendingURLTemplate.data
        clt_summary = form.collection_summary.data
        clt_description = form.collection_description.data
        clt_branchname = form.collection_branchname.data
        clt_disttag = form.collection_distTag.data
        clt_gitbranch = form.collection_git_branch_name.data

        try:
            pkgdblib.edit_collection(
                SESSION,
                collection=collection,
                clt_name=clt_name,
                clt_version=clt_version,
                clt_status=clt_status,
                clt_publishurl=clt_publishurl,
                clt_pendingurl=clt_pendingurl,
                clt_summary=clt_summary,
                clt_description=clt_description,
                clt_branchname=clt_branchname,
                clt_disttag=clt_disttag,
                clt_gitbranch=clt_gitbranch,
                user=flask.g.fas_user,
            )
            SESSION.commit()
            flask.flash('Collection "%s" edited' % clt_name)
            return flask.redirect(
                flask.url_for('.collection_info',
                              collection=collection.branchname))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'errors')
示例#36
0
        if acl.collection.branchname == collection:
            try:
                pkgdblib.update_pkg_poc(session=SESSION,
                                        pkg_name=package.name,
                                        clt_name=acl.collection.branchname,
                                        pkg_poc='orphan',
                                        user=flask.g.fas_user)
                flask.flash(
                    'You are no longer point of contact on branch: %s' %
                    collection)
            except pkgdblib.PkgdbException, err:
                flask.flash(err.message, 'error')
            break

    try:
        SESSION.commit()
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        flask.flash(err.message, 'error')

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


@UI.route('/package/<package>/<collection>/retire', methods=('GET', 'POST'))
@packager_login_required
def package_retire(package, collection):
    ''' Gives the possibility to orphan or take a package. '''

    packagename = package
    package = None
    try:
示例#37
0
def package_give(package):
    ''' Gives the PoC of a package to someone else. '''

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

    # Restrict the branch to the one current user is PoC of (unless admin
    # or group)
    collect_name = []
    for acl in package_acl:
        if acl.point_of_contact != flask.g.fas_user.username and \
                not is_pkgdb_admin(flask.g.fas_user) and \
                not acl.point_of_contact.startswith('group::'):
            pass
        else:
            if acl.point_of_contact.startswith('group::'):
                group = acl.point_of_contact.split('group::')[0]
                if group not in flask.g.fas_user.groups:
                    pass
            else:
                collect_name.append(acl.collection.branchname)

    form = pkgdb.forms.GivePoCForm(collections=collect_name)

    acls = ['commit', 'watchbugzilla', 'watchcommits', 'approveacls']

    if form.validate_on_submit():
        collections = form.pkg_branch.data
        pkg_poc = form.pkg_poc.data
        if pkg_poc.startswith('group::'):
            acls = ['commit', 'watchbugzilla', 'watchcommits']

        try:
            for pkg_collection in collections:
                message = pkgdblib.update_pkg_poc(
                    SESSION,
                    pkg_name=packagename,
                    clt_name=pkg_collection,
                    pkg_poc=pkg_poc,
                    user=flask.g.fas_user,
                )
                flask.flash(message)

                for acl in acls:
                    pkgdblib.set_acl_package(SESSION,
                                             pkg_name=packagename,
                                             clt_name=pkg_collection,
                                             pkg_user=pkg_poc,
                                             acl=acl,
                                             status='Approved',
                                             user=flask.g.fas_user)

                SESSION.commit()
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'error')

        return flask.redirect(
            flask.url_for('.package_info', package=packagename))
示例#38
0
def package_give(package):
    ''' Gives the PoC of a package to someone else. '''


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

    # Restrict the branch to the one current user is PoC of (unless admin
    # or group)
    collect_name = []
    for acl in package_acl:
        if acl.point_of_contact != flask.g.fas_user.username and \
                not is_pkgdb_admin(flask.g.fas_user) and \
                not acl.point_of_contact.startswith('group::'):
            pass
        else:
            if acl.point_of_contact.startswith('group::'):
                group = acl.point_of_contact.split('group::')[0]
                if group not in flask.g.fas_user.groups:
                    pass
            else:
                collect_name.append(acl.collection.branchname)

    form = pkgdb.forms.GivePoCForm(collections=collect_name)

    acls = ['commit', 'watchbugzilla', 'watchcommits', 'approveacls']

    if form.validate_on_submit():
        collections = form.pkg_branch.data
        pkg_poc = form.pkg_poc.data
        if pkg_poc.startswith('group::'):
            acls = ['commit', 'watchbugzilla', 'watchcommits']

        try:
            for pkg_collection in collections:
                message = pkgdblib.update_pkg_poc(
                    SESSION,
                    pkg_name=packagename,
                    clt_name=pkg_collection,
                    pkg_poc=pkg_poc,
                    user=flask.g.fas_user,
                )
                flask.flash(message)

                for acl in acls:
                    pkgdblib.set_acl_package(
                        SESSION,
                        pkg_name=packagename,
                        clt_name=pkg_collection,
                        pkg_user=pkg_poc,
                        acl=acl,
                        status='Approved',
                        user=flask.g.fas_user
                    )

                SESSION.commit()
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'error')

        return flask.redirect(
            flask.url_for('.package_info', package=packagename)
        )
示例#39
0
                pkgdblib.update_pkg_poc(
                    session=SESSION,
                    pkg_name=package.name,
                    clt_name=acl.collection.branchname,
                    pkg_poc='orphan',
                    user=flask.g.fas_user
                )
                flask.flash(
                    'You are no longer point of contact on branch: %s'
                    % collection)
            except pkgdblib.PkgdbException, err:
                flask.flash(err.message, 'error')
            break

    try:
        SESSION.commit()
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        flask.flash(err.message, 'error')

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


@UI.route('/package/<package>/<collection>/retire', methods=('GET', 'POST'))
@packager_login_required
def package_retire(package, collection):
    ''' Gives the possibility to orphan or take a package. '''

    packagename = package
    package = None
示例#40
0
def api_collection_status(collection):
    '''
Update collection status
------------------------
    Update the status of collection.

    ::

        /api/collection/<collection branchname>/status/

    Accept POST query only.

    :arg collection_branchname: String of the collection branch name to change.
    :arg collection_status: String of the status to change the collection to

    Sample response:

    ::

        {
          "output": "ok",
          "messages": ["Collection updated to \"EOL\""]
        }

        {
          "output": "notok",
          "error": ["You are not allowed to edit collections"]
        }

    '''
    httpcode = 200
    output = {}

    clt_status = pkgdblib.get_status(SESSION, 'clt_status')['clt_status']

    form = forms.CollectionStatusForm(
        csrf_enabled=False,
        clt_status=clt_status,
    )
    if form.validate_on_submit():
        clt_branchname = form.collection_branchname.data
        clt_status = form.collection_status.data

        if collection == clt_branchname:
            try:
                message = pkgdblib.update_collection_status(
                    SESSION,
                    clt_branchname,
                    clt_status,
                    user=flask.g.fas_user
                )
                SESSION.commit()
                output['output'] = 'ok'
                output['messages'] = [message]
            except pkgdblib.PkgdbException, err:
                SESSION.rollback()
                output['output'] = 'notok'
                output['error'] = err.message
                httpcode = 500
        else:
            output['output'] = 'notok'
            output['error'] = "You're trying to update the " \
                              "wrong collection"
            httpcode = 500
示例#41
0
def api_collection_new():
    '''
New collection
--------------
    Create a new collection.

    ::

        /api/collection/new/

    Accept POST queries only.

    :arg collection_name: String of the collection name to be created.
    :arg collection_version: String of the version of the collection.
    :arg collection_status: String of the name of the user owner of the
        collection.
    :arg collection_publishURLTemplate:
    :arg collection_pendingURLTemplate:
    :arg collection_summary: A summary description of the collection.
    :arg collection_description: A description of the collection.
    :arg collection_branchname: The short name of the collection (ie: F-18).
    :arg collection_distTag: The dist tag used by rpm for this collection
        (ie: .fc18).
    :arg collection_git_branch_name: The git branch name for this collection
        (ie: f18).

    Sample response:

    ::

        {
          "output": "ok",
          "messages": ["Collection F-20 created"]
        }

        {
          "output": "notok",
          "error": ["You are not allowed to create collections"]
        }

    '''
    httpcode = 200
    output = {}

    clt_status = pkgdblib.get_status(SESSION, 'clt_status')['clt_status']

    form = forms.AddCollectionForm(
        csrf_enabled=False,
        clt_status=clt_status,
    )
    if form.validate_on_submit():
        clt_name = form.collection_name.data
        clt_version = form.collection_version.data
        clt_status = form.collection_status.data
        clt_branchname = form.collection_branchname.data
        clt_disttag = form.collection_distTag.data
        clt_gitbranch = form.collection_git_branch_name.data

        try:
            message = pkgdblib.add_collection(
                SESSION,
                clt_name=clt_name,
                clt_version=clt_version,
                clt_status=clt_status,
                clt_branchname=clt_branchname,
                clt_disttag=clt_disttag,
                clt_gitbranch=clt_gitbranch,
                user=flask.g.fas_user,
            )
            SESSION.commit()
            output['output'] = 'ok'
            output['messages'] = [message]
        # Apparently we're pretty tight on checks and looks like we cannot
        # raise this exception in a normal situation
        except pkgdblib.PkgdbException, err:  # pragma: no cover
            SESSION.rollback()
            output['output'] = 'notok'
            output['error'] = err.message
            httpcode = 500
示例#42
0
def api_acl_reassign():
    '''
Reassign packages
-----------------
    Reassign the specified packages from one user to another.

    ::

        /api/package/acl/reassign/

    Accept POST queries only.

    :arg packages: List of strings of the package name to reassign.
    :arg branches: List of strings of the branchname of the Collection on
        which to reassign the point of contact.
    :arg user_target: User name of the new point of contact.

    Sample response:

    ::

        {
          "output": "ok",
          "messages": ["User: $USER changed poc of package: $PACKAGE from "
                       "$PREVIOUS_POC to $NEW_POC on branch: $BRANCH"]
        }

        {
          "output": "notok",
          "error": ["You are not allowed to change the point of contact."]
        }

    '''
    httpcode = 200
    output = {}

    packages = flask.request.form.get('packages', '').split(',')
    branches = flask.request.form.get('branches', '').split(',')
    user_target = flask.request.form.get('user_target', None)

    if not packages or not branches or not user_target:
        output['output'] = 'notok'
        output['error'] = 'Invalid input submitted'
        httpcode = 500

    else:
        try:
            messages = []
            for (package, branch) in itertools.product(packages, branches):
                messages.append(
                    pkgdblib.update_pkg_poc(
                        session=SESSION,
                        pkg_name=package,
                        pkg_branch=branch,
                        pkg_poc=user_target,
                        user=flask.g.fas_user
                    )
                )
            SESSION.commit()
            output['output'] = 'ok'
            output['messages'] = messages
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            output['output'] = 'notok'
            output['error'] = err.message
            httpcode = 500
示例#43
0
def api_acl_update():
    '''
Update package ACL
------------------
    Update the ACL for a given package.

    ::

        /api/package/acl/

    Accept POST queries only.

    :arg pkg_name: String of the package name.
    :arg pkg_branch: List of strings with the name of the branches to change,
        update.
    :arg pkg_acl: List of strings of the ACL to change/update. Possible acl
        are: 'commit', 'build', 'watchbugzilla', 'watchcommits',
        'approveacls', 'checkout'.
    :arg acl_status: String of the type of action required. Possible status
        are: 'Approved', 'Awaiting Review', 'Denied', 'Obsolete', 'Removed'.
    :kwarg pkg_user: the name of the user that is the target of this ACL
        change/update. This will only work if: 1) you are an admin,
        2) you are changing one of your package.

    Sample response:

    ::

        {
          "output": "ok",
          "messages": ["user: $USER set acl: $ACL of package: $PACKAGE "
                       "from: $PREVIOUS_STATUS to $NEW_STATUS on branch: "
                       "$BRANCH"]
        }

        {
          "output": "notok",
          "error": ["You are not allowed to update ACLs of someone else."]
        }

     '''
    httpcode = 200
    output = {}

    status = pkgdb.lib.get_status(SESSION, ['pkg_acl', 'acl_status'])

    form = forms.SetAclPackageForm(
        csrf_enabled=False,
        pkg_acl=status['pkg_acl'],
        acl_status=status['acl_status'],
    )
    if form.validate_on_submit():
        pkg_name = form.pkg_name.data
        pkg_branch = form.pkg_branch.data.split(',')
        pkg_acl = form.pkg_acl.data
        acl_status = form.acl_status.data
        pkg_user = form.pkg_user.data

        try:
            messages = []
            for branch in pkg_branch:
                message = pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=pkg_name,
                    pkg_branch=branch,
                    acl=pkg_acl,
                    status=acl_status,
                    pkg_user=pkg_user,
                    user=flask.g.fas_user,
                )
                messages.append(message)
            SESSION.commit()
            output['output'] = 'ok'
            output['messages'] = messages
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            output['output'] = 'notok'
            output['error'] = err.message
            httpcode = 500