예제 #1
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)

    pending_acls2 = []
    if branch is not None:
        for acls in pending_acls:
            if acls['collection'] == branch:
                pending_acls2.append(acls)
    else:
        for acls in pending_acls:
            if acls['collection_status'] != 'EOL':
                pending_acls2.append(acls)
    pending_acls = pending_acls2

    collections = set([item['collection'] for item in pending_acls])
    status = pkgdblib.get_status(SESSION, ['pkg_acl', 'acl_status'])

    form = pkgdb2.forms.UpdateAclPackageForm(
        collections=collections,
        pkg_acl_list=status['pkg_acl'],
        acl_status=status['acl_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:
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):

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

                pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=package,
                    pkg_branch=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))
        # Let's keep this in although we should never see it
        except pkgdblib.PkgdbException, err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(str(err), 'errors')
예제 #2
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)

    pending_acls2 = []
    if branch is not None:
        for acls in pending_acls:
            if acls['collection'] == branch:
                pending_acls2.append(acls)
    else:
        for acls in pending_acls:
            if acls['collection_status'] != 'EOL':
                pending_acls2.append(acls)
    pending_acls = pending_acls2

    collections = set([item['collection'] for item in pending_acls])
    status = pkgdblib.get_status(SESSION, ['pkg_acl', 'acl_status'])

    form = pkgdb2.forms.UpdateAclPackageForm(
        collections=collections,
        pkg_acl_list=status['pkg_acl'],
        acl_status=status['acl_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:
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):

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

                pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=package,
                    pkg_branch=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))
        # Let's keep this in although we should never see it
        except pkgdblib.PkgdbException, err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(str(err), 'errors')