Beispiel #1
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(str(err), 'error')
Beispiel #2
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(str(err), 'error')
Beispiel #3
0
def pending_acl_deny():
    ''' Deny all the pending acls for the user logged in. '''
    form = pkgdb2.forms.ConfirmationForm()

    if form.validate_on_submit():
        pending_acls = pkgdblib.get_pending_acl_user(SESSION,
                                                     flask.g.fas_user.username)
        try:
            for acl in pending_acls:
                pkgdblib.set_acl_package(SESSION,
                                         namespace=acl['namespace'],
                                         pkg_name=acl['package'],
                                         pkg_branch=acl['collection'],
                                         pkg_user=acl['user'],
                                         acl=acl['acl'],
                                         status='Denied',
                                         user=flask.g.fas_user)

            SESSION.commit()
            flask.flash('All ACLs denied')
            # Let's keep this in although we should never see it
        except PkgdbException as err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(str(err), 'error')

    return flask.redirect(flask.url_for('.pending_acl'))
Beispiel #4
0
def pending_acl_deny():
    ''' Deny all the pending acls for the user logged in. '''
    form = pkgdb2.forms.ConfirmationForm()

    if form.validate_on_submit():
        pending_acls = pkgdblib.get_pending_acl_user(
            SESSION, flask.g.fas_user.username)
        try:
            for acl in pending_acls:
                pkgdblib.set_acl_package(
                    SESSION,
                    namespace=acl['namespace'],
                    pkg_name=acl['package'],
                    pkg_branch=acl['collection'],
                    pkg_user=acl['user'],
                    acl=acl['acl'],
                    status='Denied',
                    user=flask.g.fas_user
                )

            SESSION.commit()
            flask.flash('All ACLs denied')
            # Let's keep this in although we should never see it
        except pkgdblib.PkgdbException, err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(str(err), 'error')
Beispiel #5
0
def giveup_acl(namespace, package, acl):
    ''' Request acls for a specific package. '''
    form = pkgdb2.forms.ConfirmationForm()

    if form.validate_on_submit():
        pkg_acl = pkgdblib.get_status(SESSION, 'pkg_acl')['pkg_acl']
        if acl not in pkg_acl:
            flask.flash('Invalid ACL provided %s.' % acl, 'errors')
            return flask.render_template('msg.html')

        try:
            pkg = pkgdblib.search_package(
                SESSION, namespace=namespace, 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', namespace=namespace, package=package))

        pkg_branchs = set([
            pkglist.collection.branchname
            for pkglist in pkg.listings
            if pkglist.collection.status in
            ['Active', 'Under Development'] and flask.g.fas_user.username in
            [tmpacl.fas_name for tmpacl in pkglist.acls]
        ])

        if not pkg_branchs:
            flask.flash(
                'No active branches found for you for the ACL: %s' % acl,
                'error')
            return flask.redirect(flask.url_for(
                '.package_info', namespace=namespace, package=package))

        for branch in pkg_branchs:
            print package, namespace, branch, acl, flask.g.fas_user.username
            try:
                pkgdblib.set_acl_package(
                    SESSION,
                    namespace=namespace,
                    pkg_name=package,
                    pkg_branch=branch,
                    pkg_user=flask.g.fas_user.username,
                    acl=acl,
                    status='Obsolete',
                    user=flask.g.fas_user,
                )
                flask.flash(
                    'Your ACL %s is obsoleted on branch %s of package %s'
                    % (acl, branch, package))
            except pkgdblib.PkgdbException, err:  # pragma: no cover
                flask.flash(str(err), 'error')
                SESSION.rollback()

        try:
            SESSION.commit()
        # Keep it in, but normally we shouldn't hit this
        except pkgdblib.PkgdbException, err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(str(err), 'error')
Beispiel #6
0
def package_give_acls(namespace, package):
    ''' Give acls to a specified user for a specific package. '''

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

    collections = [
        pkglist.collection for pkglist in pkg.listings
        if pkglist.collection.status != 'EOL'
    ]

    acls = pkgdblib.get_status(SESSION)

    form = pkgdb2.forms.SetAclPackageForm(
        collections_obj=collections,
        pkg_acl=acls['pkg_acl'],
        acl_status=acls['acl_status'],
        namespaces=acls['namespaces'],
    )
    form.pkgname.data = package
    if str(form.namespace.data) in ['None', '']:
        form.namespace.data = 'rpms'

    if form.validate_on_submit():
        pkg_branchs = form.branches.data
        pkg_acls = form.acl.data
        pkg_user = form.user.data
        acl_status = form.acl_status.data

        try:
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
                if acl in APP.config['AUTO_APPROVE']:
                    acl_status = 'Approved'

                pkgdblib.set_acl_package(
                    SESSION,
                    namespace=namespace,
                    pkg_name=package,
                    pkg_branch=collec,
                    pkg_user=pkg_user,
                    acl=acl,
                    status=acl_status,
                    user=flask.g.fas_user,
                )
            SESSION.commit()
            flask.flash('ACLs updated')
            return flask.redirect(
                flask.url_for('.package_info',
                              namespace=namespace,
                              package=package))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(str(err), 'error')
Beispiel #7
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]

    # Make sure the requester does not already have commit
    pkg_branchs2 = []
    for pkg_branch in pkg_branchs:
        if pkgdblib.has_acls(SESSION, flask.g.fas_user.username, pkg.name,
                             pkg_branch, 'commit'):
            flask.flash(
                'You are already a co-maintainer on %s' % pkg_branch,
                'error')
        else:
            pkg_branchs2.append(pkg_branch)
    pkg_branchs = pkg_branchs2

    if not pkg_branchs:
        return flask.redirect(flask.url_for('.package_info', package=package))

    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(str(err), 'error')
Beispiel #8
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')
Beispiel #9
0
def giveup_acl(package, acl):
    ''' Request acls for a specific package. '''
    form = pkgdb2.forms.ConfirmationForm()

    if form.validate_on_submit():
        pkg_acl = pkgdblib.get_status(SESSION, 'pkg_acl')['pkg_acl']
        if acl not in pkg_acl:
            flask.flash('Invalid ACL provided %s.' % acl, 'errors')
            return flask.render_template('msg.html')

        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_branchs = set([
            pkglist.collection.branchname
            for pkglist in pkg.listings
            if pkglist.collection.status in
            ['Active', 'Under Development'] and flask.g.fas_user.username in
            [tmpacl.fas_name for tmpacl in pkglist.acls]
        ])

        if not pkg_branchs:
            flask.flash(
                'No active branches found for you for the ACL: %s' % acl,
                'error')
            return flask.redirect(
                flask.url_for('.package_info', package=package))

        for branch in pkg_branchs:
            try:
                pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=package,
                    pkg_branch=branch,
                    pkg_user=flask.g.fas_user.username,
                    acl=acl,
                    status='Obsolete',
                    user=flask.g.fas_user,
                )
                flask.flash(
                    'Your ACL %s is obsoleted on branch %s of package %s'
                    % (acl, branch, package))
            except pkgdblib.PkgdbException, err:
                flask.flash(str(err), 'error')
                SESSION.rollback()

        try:
            SESSION.commit()
        # Keep it in, but normally we shouldn't hit this
        except pkgdblib.PkgdbException, err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(str(err), 'error')
Beispiel #10
0
def package_give_acls(namespace, package):
    ''' Give acls to a specified user for a specific package. '''

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

    collections = [
        pkglist.collection
        for pkglist in pkg.listings
        if pkglist.collection.status != 'EOL']

    acls = pkgdblib.get_status(SESSION)

    form = pkgdb2.forms.SetAclPackageForm(
        collections_obj=collections,
        pkg_acl=acls['pkg_acl'],
        acl_status=acls['acl_status'],
        namespaces=acls['namespaces'],
    )
    form.pkgname.data = package
    if str(form.namespace.data) in ['None', '']:
        form.namespace.data = 'rpms'

    if form.validate_on_submit():
        pkg_branchs = form.branches.data
        pkg_acls = form.acl.data
        pkg_user = form.user.data
        acl_status = form.acl_status.data

        try:
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
                if acl in APP.config['AUTO_APPROVE']:
                    acl_status = 'Approved'

                pkgdblib.set_acl_package(
                    SESSION,
                    namespace=namespace,
                    pkg_name=package,
                    pkg_branch=collec,
                    pkg_user=pkg_user,
                    acl=acl,
                    status=acl_status,
                    user=flask.g.fas_user,
                )
            SESSION.commit()
            flask.flash('ACLs updated')
            return flask.redirect(flask.url_for(
                '.package_info', namespace=namespace, package=package))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(str(err), 'error')
Beispiel #11
0
def request_acl(namespace, package):
    ''' Request acls for a specific package. '''

    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')

    collections = [
        acl.collection for acl in package_acl
        if acl.collection.status in ['Active', 'Under Development']
    ]

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

    form = pkgdb2.forms.RequestAclPackageForm(collections=collections,
                                              pkg_acl_list=pkg_acl)
    if form.validate_on_submit():
        pkg_branchs = form.branches.data
        pkg_acls = form.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,
                    namespace=namespace,
                    pkg_name=package.name,
                    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')
            return flask.redirect(
                flask.url_for('.package_info',
                              namespace=package.namespace,
                              package=package.name))

        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(str(err), 'error')
Beispiel #12
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')
Beispiel #13
0
def request_acl_all_branch(namespace, package, acl):
    ''' Request the specified ACL on all branches of the specified package.
    '''
    form = pkgdb2.forms.ConfirmationForm()

    if form.validate_on_submit():
        pkg_acl = pkgdblib.get_status(SESSION, 'pkg_acl')['pkg_acl']
        if acl not in pkg_acl:
            flask.flash('Invalid ACL provided %s.' % acl, 'errors')
            return flask.render_template('msg.html')

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

        pkg_branchs = set([
            pkglist.collection.branchname
            for pkglist in pkg.listings
            if pkglist.collection.status in ['Active', 'Under Development']
                and pkglist.status == 'Approved'
        ])

        for branch in pkg_branchs:
            acl_status = 'Awaiting Review'
            pkger_grp = APP.config.get('PKGER_GROUP', 'packager')
            if acl in APP.config['AUTO_APPROVE']:
                acl_status = 'Approved'
            elif pkger_grp not in flask.g.fas_user.groups:
                flask.flash(
                    'You must be a %s to apply to the ACL: %s on %s' % (
                        pkger_grp, acl, package), 'error')

            try:
                pkgdblib.set_acl_package(
                    SESSION,
                    namespace=namespace,
                    pkg_name=package,
                    pkg_branch=branch,
                    pkg_user=flask.g.fas_user.username,
                    acl=acl,
                    status=acl_status,
                    user=flask.g.fas_user,
                )
                flask.flash(
                    'ACL %s requested on branch %s' % (acl, branch))
                SESSION.commit()
            except PkgdbException as err:
                SESSION.rollback()
                flask.flash(str(err), 'error')

    return flask.redirect(flask.url_for(
        '.package_info', namespace=namespace, package=package))
Beispiel #14
0
def request_acl(package):
    ''' Request acls for a specific package. '''

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

    collections = [
        acl.collection
        for acl in package_acl
        if acl.collection.status in ['Active', 'Under Development']
    ]

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

    form = pkgdb2.forms.RequestAclPackageForm(
        collections=collections,
        pkg_acl_list=pkg_acl
    )
    if form.validate_on_submit():
        pkg_branchs = form.branches.data
        pkg_acls = form.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.name,
                    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')
            return flask.redirect(
                flask.url_for('.package_info',
                              package=package.name))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(str(err), 'error')
Beispiel #15
0
def request_acl_all_branch(namespace, package, acl):
    ''' Request the specified ACL on all branches of the specified package.
    '''
    form = pkgdb2.forms.ConfirmationForm()

    if form.validate_on_submit():
        pkg_acl = pkgdblib.get_status(SESSION, 'pkg_acl')['pkg_acl']
        if acl not in pkg_acl:
            flask.flash('Invalid ACL provided %s.' % acl, 'errors')
            return flask.render_template('msg.html')

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

        pkg_branchs = set([
            pkglist.collection.branchname for pkglist in pkg.listings
            if pkglist.collection.status in ['Active', 'Under Development']
            and pkglist.status == 'Approved'
        ])

        for branch in pkg_branchs:
            acl_status = 'Awaiting Review'
            pkger_grp = APP.config.get('PKGER_GROUP', 'packager')
            if acl in APP.config['AUTO_APPROVE']:
                acl_status = 'Approved'
            elif pkger_grp not in flask.g.fas_user.groups:
                flask.flash(
                    'You must be a %s to apply to the ACL: %s on %s' %
                    (pkger_grp, acl, package), 'error')

            try:
                pkgdblib.set_acl_package(
                    SESSION,
                    namespace=namespace,
                    pkg_name=package,
                    pkg_branch=branch,
                    pkg_user=flask.g.fas_user.username,
                    acl=acl,
                    status=acl_status,
                    user=flask.g.fas_user,
                )
                flask.flash('ACL %s requested on branch %s' % (acl, branch))
                SESSION.commit()
            except PkgdbException as err:
                SESSION.rollback()
                flask.flash(str(err), 'error')

    return flask.redirect(
        flask.url_for('.package_info', namespace=namespace, package=package))
Beispiel #16
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]

    # Make sure the requester does not already have commit
    pkg_branchs2 = []
    for pkg_branch in pkg_branchs:
        if pkgdblib.has_acls(SESSION, flask.g.fas_user.username, pkg.name,
                             pkg_branch, 'commit'):
            flask.flash('You are already a co-maintainer on %s' % pkg_branch,
                        'error')
        else:
            pkg_branchs2.append(pkg_branch)
    pkg_branchs = pkg_branchs2

    if not pkg_branchs:
        return flask.redirect(flask.url_for('.package_info', package=package))

    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(str(err), 'error')
Beispiel #17
0
def dropcommit_package(namespace, package):
    ''' Obsolete commit ACLs on a package.
    This method can only be used for the user itself.
    '''
    form = pkgdb2.forms.ConfirmationForm()

    if form.validate_on_submit():
        try:
            pkg = pkgdblib.search_package(SESSION,
                                          namespace=namespace,
                                          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',
                              namespace=namespace,
                              package=package))

        pkg_acls = ['commit']
        pkg_branchs = set()
        for pkglist in pkg.listings:
            if pkglist.collection.status in ['Active', 'Under Development']:
                for acl in pkglist.acls:
                    if acl.fas_name == flask.g.fas_user.username and \
                            acl.acl == 'commit' and acl.status == 'Approved':
                        pkg_branchs.add(pkglist.collection.branchname)

        try:
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
                pkgdblib.set_acl_package(
                    SESSION,
                    namespace=namespace,
                    pkg_name=package,
                    pkg_branch=collec,
                    pkg_user=flask.g.fas_user.username,
                    acl=acl,
                    status='Obsolete',
                    user=flask.g.fas_user,
                )
            SESSION.commit()
            flask.flash('ACLs updated')
        # Let's keep this in although we should never see it
        except PkgdbException as err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(str(err), 'error')
    return flask.redirect(
        flask.url_for('.package_info', namespace=namespace, package=package))
Beispiel #18
0
def dropcommit_package(namespace, package):
    ''' Obsolete commit ACLs on a package.
    This method can only be used for the user itself.
    '''
    form = pkgdb2.forms.ConfirmationForm()

    if form.validate_on_submit():
        try:
            pkg = pkgdblib.search_package(
                SESSION, namespace=namespace, 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', namespace=namespace, package=package))

        pkg_acls = ['commit']
        pkg_branchs = set()
        for pkglist in pkg.listings:
            if pkglist.collection.status in [
                    'Active', 'Under Development']:
                for acl in pkglist.acls:
                    if acl.fas_name == flask.g.fas_user.username and \
                            acl.acl == 'commit' and acl.status == 'Approved':
                        pkg_branchs.add(pkglist.collection.branchname)

        try:
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
                pkgdblib.set_acl_package(
                    SESSION,
                    namespace=namespace,
                    pkg_name=package,
                    pkg_branch=collec,
                    pkg_user=flask.g.fas_user.username,
                    acl=acl,
                    status='Obsolete',
                    user=flask.g.fas_user,
                )
            SESSION.commit()
            flask.flash('ACLs updated')
        # Let's keep this in although we should never see it
        except PkgdbException as err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(str(err), 'error')
    return flask.redirect(flask.url_for(
        '.package_info', namespace=namespace, package=package))
Beispiel #19
0
def watch_package(namespace, package):
    ''' Request watch* ACLs on a package.
    Anyone can request these ACLs, no need to be a packager.
    '''
    form = pkgdb2.forms.ConfirmationForm()

    if form.validate_on_submit():
        try:
            pkg = pkgdblib.search_package(SESSION,
                                          namespace=namespace,
                                          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',
                              namespace=namespace,
                              package=package))

        pkg_acls = ['watchcommits', 'watchbugzilla']
        pkg_branchs = set([
            pkglist.collection.branchname for pkglist in pkg.listings
            if pkglist.collection.status in ['Active', 'Under Development']
            and pkglist.status == 'Approved'
        ])
        try:
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
                pkgdblib.set_acl_package(
                    SESSION,
                    namespace=namespace,
                    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 PkgdbException as err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(str(err), 'error')
    return flask.redirect(
        flask.url_for('.package_info', namespace=namespace, package=package))
Beispiel #20
0
def request_acl(package):
    ''' Request acls for a specific package. '''

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

    form = pkgdb2.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,
                    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')
            return flask.redirect(
                flask.url_for('.package_info',
                              package=package))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(str(err), 'error')
Beispiel #21
0
def watch_package(namespace, package):
    ''' Request watch* ACLs on a package.
    Anyone can request these ACLs, no need to be a packager.
    '''
    form = pkgdb2.forms.ConfirmationForm()

    if form.validate_on_submit():
        try:
            pkg = pkgdblib.search_package(
                SESSION, namespace=namespace, 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', namespace=namespace, package=package))

        pkg_acls = ['watchcommits', 'watchbugzilla']
        pkg_branchs = set([
            pkglist.collection.branchname
            for pkglist in pkg.listings
            if pkglist.collection.status in ['Active', 'Under Development']
                and pkglist.status == 'Approved'
        ])
        try:
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
                pkgdblib.set_acl_package(
                    SESSION,
                    namespace=namespace,
                    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 PkgdbException as err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(str(err), 'error')
    return flask.redirect(flask.url_for(
        '.package_info', namespace=namespace, package=package))
Beispiel #22
0
def request_acl(package):
    ''' Request acls for a specific package. '''

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

    form = pkgdb2.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,
                    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')
            return flask.redirect(
                flask.url_for('.package_info', package=package))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(str(err), 'error')
Beispiel #23
0
def unwatch_package(package):
    ''' Obsolete watch* ACLs on a package.
    This method can only be used for the user itself.
    '''
    form = pkgdb2.forms.ConfirmationForm()

    if form.validate_on_submit():
        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 = set([
            pkglist.collection.branchname
            for pkglist in pkg.listings
            if pkglist.collection.status in ['Active', 'Under Development']])
        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='Obsolete',
                    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(str(err), 'error')
Beispiel #24
0
def unwatch_package(package):
    ''' Obsolete watch* ACLs on a package.
    This method can only be used for the user itself.
    '''
    form = pkgdb2.forms.ConfirmationForm()

    if form.validate_on_submit():
        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 = set([
            pkglist.collection.branchname
            for pkglist in pkg.listings
            if pkglist.collection.status in ['Active', 'Under Development']])
        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='Obsolete',
                    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(str(err), 'error')
Beispiel #25
0
def api_acl_update():
    """
Update package ACL
------------------
    Update the ACL for a given package.

    ::

        /api/package/acl/

    Accept POST queries only.

    :arg pkgname: String of the package name.
    :arg branches: List of strings with the name of the branches to change,
        update.
    :arg 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 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 = pkgdblib.get_status(SESSION, ["pkg_acl", "acl_status"])
    collections = pkgdblib.search_collection(SESSION, "*", "Under Development")
    collections.extend(pkgdblib.search_collection(SESSION, "*", "Active"))

    form = forms.SetAclPackageForm(
        csrf_enabled=False,
        collections=[col.branchname for col in collections],
        pkg_acl=status["pkg_acl"],
        acl_status=status["acl_status"],
    )

    if form.validate_on_submit():
        pkg_name = form.pkgname.data
        pkg_branch = form.branches.data
        pkg_acl = form.acl.data
        acl_status = form.acl_status.data
        pkg_user = form.user.data

        try:
            messages = []
            for (branch, acl) in itertools.product(pkg_branch, pkg_acl):

                acl_status2 = acl_status

                if acl_status2 == "Awaiting Review" and acl in APP.config["AUTO_APPROVE"]:
                    acl_status2 = "Approved"

                message = pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=pkg_name,
                    pkg_branch=branch,
                    acl=acl,
                    status=acl_status2,
                    pkg_user=pkg_user,
                    user=flask.g.fas_user,
                )
                if message:
                    messages.append(message)
                else:
                    messages.append("Nothing to update on branch: %s for acl: %s" % (branch, acl))
            SESSION.commit()
            output["output"] = "ok"
            output["messages"] = messages
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            output["output"] = "notok"
            output["error"] = str(err)
            httpcode = 500
Beispiel #26
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 = pkgdblib.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.split(',')
        acl_status = form.acl_status.data
        pkg_user = form.pkg_user.data

        try:
            messages = []
            for (acl, branch) in itertools.product(pkg_acl, pkg_branch):
                message = pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=pkg_name,
                    pkg_branch=branch,
                    acl=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'] = str(err)
            httpcode = 500
Beispiel #27
0
def comaintain_package(namespace, package):
    ''' Asks for ACLs to co-maintain a package.
    You need to be a packager to request co-maintainership.
    '''
    form = pkgdb2.forms.ConfirmationForm()

    if form.validate_on_submit():
        # This is really wearing belt and suspenders, the decorator above
        # should take care of this
        pkger_grp = APP.config.get('PKGER_GROUP', 'packager')
        if pkger_grp not in flask.g.fas_user.groups:  # pragma: no cover
            flask.flash(
                'You must be a %s to apply to be a comaintainer' % pkger_grp,
                'errors')
            return flask.redirect(flask.url_for(
                '.package_info', package=package))

        try:
            pkg = pkgdblib.search_package(
                SESSION, namespace=namespace, 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', namespace=namespace, package=package))

        pkg_acls = ['commit', 'watchcommits', 'watchbugzilla']
        pkg_branchs = set([
            pkglist.collection.branchname
            for pkglist in pkg.listings
            if pkglist.collection.status in ['Active', 'Under Development']
                and pkglist.status == 'Approved'
        ])

        # Make sure the requester does not already have commit
        pkg_branchs2 = []
        for pkg_branch in pkg_branchs:
            if pkgdblib.has_acls(
                    SESSION, flask.g.fas_user.username, pkg.namespace,
                    pkg.name, acl='commit', branch=pkg_branch):
                flask.flash(
                    'You are already a co-maintainer on %s' % pkg_branch,
                    'error')
            else:
                pkg_branchs2.append(pkg_branch)
        pkg_branchs = pkg_branchs2

        if not pkg_branchs:
            return flask.redirect(flask.url_for(
                '.package_info', namespace=namespace, package=package))

        try:
            msgs = []
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
                acl_status = 'Awaiting Review'
                if acl in APP.config['AUTO_APPROVE']:
                    acl_status = 'Approved'
                msg = pkgdblib.set_acl_package(
                    SESSION,
                    namespace=namespace,
                    pkg_name=package,
                    pkg_branch=collec,
                    pkg_user=flask.g.fas_user.username,
                    acl=acl,
                    status=acl_status,
                    user=flask.g.fas_user,
                )
                if msg:
                    msgs.append(msg)

            SESSION.commit()
            if msgs:
                flask.flash('ACLs updated')
            else:
                flask.flash('Nothing to update')
        # Let's keep this in although we should never see it
        except PkgdbException as err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(str(err), 'error')
    return flask.redirect(flask.url_for(
        '.package_info', namespace=namespace, package=package))
Beispiel #28
0
def update_acl(package, update_acl):
    ''' Update the acls of 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')

    statues = pkgdblib.get_status(SESSION)
    planned_acls = set(statues['pkg_acl'])
    acl_status = list(set(statues['acl_status']))
    acl_status.insert(0, '')

    if update_acl not in planned_acls:
        flask.flash('Invalid ACL to update.', 'errors')
        return flask.redirect(
            flask.url_for('.package_info', package=package.name))

    branches = {}
    branches_inv = {}
    commit_acls = {}
    admins = {}
    committers = []

    for pkg in package_acl:
        if pkg.collection.status == 'EOL':  # pragma: no cover
            continue

        collection_name = '%s %s' % (pkg.collection.name,
                                     pkg.collection.version)

        if collection_name not in branches:
            branches[collection_name] = pkg.collection.branchname

        if pkg.collection.branchname not in branches_inv:
            branches_inv[pkg.collection.branchname] = collection_name

        for acl in pkg.acls:

            if acl.acl == 'approveacls' and acl.status == 'Approved':
                if acl.fas_name not in admins:
                    admins[acl.fas_name] = set()
                admins[acl.fas_name].add(collection_name)

            if acl.acl != update_acl:
                continue

            committers.append(acl.fas_name)
            if acl.fas_name not in commit_acls:
                commit_acls[acl.fas_name] = {}
            if collection_name not in commit_acls[acl.fas_name]:
                commit_acls[acl.fas_name][collection_name] = {}

            commit_acls[acl.fas_name][collection_name][acl.acl] = \
                acl.status

        for aclname in planned_acls:
            for user in commit_acls:
                if collection_name in commit_acls[user] and \
                        aclname not in commit_acls[user][collection_name]:
                    commit_acls[user][collection_name][aclname] = None

    # If the user is not an admin, he/she can only access his/her ACLs
    username = flask.g.fas_user.username
    if username not in admins and not is_pkgdb_admin(flask.g.fas_user):
        tmp = {username: []}
        if username in commit_acls:
            tmp = {username: commit_acls[username]}
        commit_acls = tmp

    form = pkgdb2.forms.ConfirmationForm()

    if form.validate_on_submit():
        sub_acls = flask.request.values.getlist('acls')
        sub_users = flask.request.values.getlist('user')
        sub_branches = flask.request.values.getlist('branch')
        changed = False

        if sub_acls and len(sub_acls) == (len(sub_users) * len(sub_branches)):
            cnt = 0
            for cnt_u in range(len(sub_users)):
                for cnt_b in range(len(sub_branches)):
                    lcl_acl = sub_acls[cnt]
                    lcl_user = sub_users[cnt_u]
                    lcl_branch = sub_branches[cnt_b]

                    if lcl_acl not in acl_status:
                        flask.flash('Invalid ACL: %s' % lcl_acl, 'error')
                        cnt += 1
                        continue

                    if lcl_user not in commit_acls:
                        flask.flash('Invalid user: %s' % lcl_user, 'error')
                        cnt += 1
                        continue

                    if lcl_branch not in branches_inv or (
                            branches_inv[lcl_branch] in commit_acls[lcl_user]
                            and commit_acls[lcl_user][branches_inv[lcl_branch]]
                        [update_acl] == lcl_acl):
                        cnt += 1
                        continue

                    if not lcl_acl:
                        if branches_inv[lcl_branch] \
                                not in commit_acls[lcl_user]:
                            cnt += 1
                            continue
                        elif branches_inv[lcl_branch] \
                                in commit_acls[lcl_user] \
                                and username != lcl_user:
                            flask.flash('Only the user can remove his/her ACL',
                                        'error')
                            cnt += 1
                            continue

                    try:
                        pkgdblib.set_acl_package(
                            SESSION,
                            pkg_name=package.name,
                            pkg_branch=lcl_branch,
                            pkg_user=lcl_user,
                            acl=update_acl,
                            status=lcl_acl,
                            user=flask.g.fas_user,
                        )
                        SESSION.commit()
                        flask.flash("%s's %s ACL updated on %s" %
                                    (lcl_user, update_acl, lcl_branch))
                        changed = True
                    except pkgdblib.PkgdbException, err:
                        SESSION.rollback()
                        flask.flash(str(err), 'error')
                    cnt += 1

            SESSION.commit()
            if not changed:
                flask.flash('Nothing to update')
            return flask.redirect(
                flask.url_for('.package_info', package=package.name))
        else:
            flask.flash('Invalid input submitted', 'error')
Beispiel #29
0
def comaintain_package(namespace, package):
    ''' Asks for ACLs to co-maintain a package.
    You need to be a packager to request co-maintainership.
    '''
    form = pkgdb2.forms.ConfirmationForm()

    if form.validate_on_submit():
        # This is really wearing belt and suspenders, the decorator above
        # should take care of this
        pkger_grp = APP.config.get('PKGER_GROUP', 'packager')
        if pkger_grp not in flask.g.fas_user.groups:  # pragma: no cover
            flask.flash(
                'You must be a %s to apply to be a comaintainer' % pkger_grp,
                'errors')
            return flask.redirect(
                flask.url_for('.package_info', package=package))

        try:
            pkg = pkgdblib.search_package(SESSION,
                                          namespace=namespace,
                                          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',
                              namespace=namespace,
                              package=package))

        pkg_acls = ['commit', 'watchcommits', 'watchbugzilla']
        pkg_branchs = set([
            pkglist.collection.branchname for pkglist in pkg.listings
            if pkglist.collection.status in ['Active', 'Under Development']
            and pkglist.status == 'Approved'
        ])

        # Make sure the requester does not already have commit
        pkg_branchs2 = []
        for pkg_branch in pkg_branchs:
            if pkgdblib.has_acls(SESSION,
                                 flask.g.fas_user.username,
                                 pkg.namespace,
                                 pkg.name,
                                 acl='commit',
                                 branch=pkg_branch):
                flask.flash(
                    'You are already a co-maintainer on %s' % pkg_branch,
                    'error')
            else:
                pkg_branchs2.append(pkg_branch)
        pkg_branchs = pkg_branchs2

        if not pkg_branchs:
            return flask.redirect(
                flask.url_for('.package_info',
                              namespace=namespace,
                              package=package))

        try:
            msgs = []
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
                acl_status = 'Awaiting Review'
                if acl in APP.config['AUTO_APPROVE']:
                    acl_status = 'Approved'
                msg = pkgdblib.set_acl_package(
                    SESSION,
                    namespace=namespace,
                    pkg_name=package,
                    pkg_branch=collec,
                    pkg_user=flask.g.fas_user.username,
                    acl=acl,
                    status=acl_status,
                    user=flask.g.fas_user,
                )
                if msg:
                    msgs.append(msg)

            SESSION.commit()
            if msgs:
                flask.flash('ACLs updated')
            else:
                flask.flash('Nothing to update')
        # Let's keep this in although we should never see it
        except PkgdbException as err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(str(err), 'error')
    return flask.redirect(
        flask.url_for('.package_info', namespace=namespace, package=package))
Beispiel #30
0
def package_give(package, full=True):
    ''' Gives the PoC of a package to someone else. '''

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

    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')

    # 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
            elif acl.collection.status != 'EOL':
                collect_name.append(acl.collection.branchname)

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

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

    if form.validate_on_submit():
        collections = form.branches.data
        pkg_poc = form.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,
                    pkg_branch=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,
                                             pkg_branch=pkg_collection,
                                             pkg_user=pkg_poc,
                                             acl=acl,
                                             status='Approved',
                                             user=flask.g.fas_user)

                SESSION.commit()
        except pkgdblib.PkgdbBugzillaException, err:  # pragma: no cover
            APP.logger.exception(err)
            flask.flash(str(err), 'error')
            SESSION.rollback()
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(str(err), 'error')
Beispiel #31
0
def api_acl_update():
    '''
    Update package ACL
    ------------------
    Update the ACL for a given package.

    ::

        /api/package/acl/

    Accepts POST queries only.

    :arg pkgname: String of the package name.
    :arg branches: List of strings with the name of the branches to change,
        update.
    :arg 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 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.
    :kwarg namespace: The namespace of the packages (defaults to ``rpms``).

    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 = pkgdblib.get_status(
        SESSION, ['pkg_acl', 'acl_status', 'namespaces'])
    collections = pkgdblib.search_collection(
        SESSION, '*', 'Under Development')
    collections.extend(pkgdblib.search_collection(SESSION, '*', 'Active'))

    form = forms.SetAclPackageForm(
        csrf_enabled=False,
        collections=[col.branchname for col in collections],
        pkg_acl=status['pkg_acl'],
        acl_status=status['acl_status'],
        namespaces=status['namespaces'],
    )

    if str(form.namespace.data) in ['None', '']:
        form.namespace.data = 'rpms'

    if form.validate_on_submit():
        namespace = form.namespace.data
        pkg_name = form.pkgname.data
        pkg_branch = form.branches.data
        pkg_acl = form.acl.data
        acl_status = form.acl_status.data
        pkg_user = form.user.data

        try:
            messages = []
            for (branch, acl) in itertools.product(pkg_branch, pkg_acl):

                acl_status2 = acl_status

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

                message = pkgdblib.set_acl_package(
                    SESSION,
                    namespace=namespace,
                    pkg_name=pkg_name,
                    pkg_branch=branch,
                    acl=acl,
                    status=acl_status2,
                    pkg_user=pkg_user,
                    user=flask.g.fas_user,
                )
                if message:
                    messages.append(message)
                else:
                    messages.append(
                        'Nothing to update on branch: %s for acl: %s' %
                        (branch, acl))
            SESSION.commit()
            output['output'] = 'ok'
            output['messages'] = messages
        except PkgdbException as err:
            SESSION.rollback()
            output['output'] = 'notok'
            output['error'] = str(err)
            httpcode = 500
    else:
        output['output'] = 'notok'
        output['error'] = 'Invalid input submitted'
        if form.errors:
            detail = []
            for error in form.errors:
                detail.append('%s: %s' % (error,
                              '; '.join(form.errors[error])))
            output['error_detail'] = detail
        httpcode = 500

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout
Beispiel #32
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 = pkgdblib.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.split(',')
        acl_status = form.acl_status.data
        pkg_user = form.pkg_user.data

        try:
            messages = []
            for (acl, branch) in itertools.product(pkg_acl, pkg_branch):
                message = pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=pkg_name,
                    pkg_branch=branch,
                    acl=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'] = str(err)
            httpcode = 500
Beispiel #33
0
def update_acl(namespace, package, update_acl):
    ''' Update the acls of a package. '''

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

    statues = pkgdblib.get_status(SESSION)
    planned_acls = set(statues['pkg_acl'])
    acl_status = list(set(statues['acl_status']))
    acl_status.insert(0, '')

    if update_acl not in planned_acls:
        flask.flash('Invalid ACL to update.', 'errors')
        return flask.redirect(flask.url_for(
            '.package_info',
            namespace=package.namespace,
            package=package.name)
        )

    branches = {}
    branches_inv = {}
    commit_acls = {}
    admins = {}
    committers = []

    for pkg in package_acl:
        if pkg.collection.status == 'EOL':  # pragma: no cover
            continue

        collection_name = '%s %s' % (
            pkg.collection.name, pkg.collection.version)

        if collection_name not in branches:
            branches[collection_name] = pkg.collection.branchname

        if pkg.collection.branchname not in branches_inv:
            branches_inv[pkg.collection.branchname] = collection_name

        for acl in pkg.acls:

            if acl.acl == 'approveacls' and acl.status == 'Approved':
                if acl.fas_name not in admins:
                    admins[acl.fas_name] = set()
                admins[acl.fas_name].add(collection_name)

            if acl.acl != update_acl:
                continue

            committers.append(acl.fas_name)
            if acl.fas_name not in commit_acls:
                commit_acls[acl.fas_name] = {}
            if collection_name not in commit_acls[acl.fas_name]:
                commit_acls[acl.fas_name][collection_name] = {}

            commit_acls[acl.fas_name][collection_name][acl.acl] = \
                acl.status

        for aclname in planned_acls:
            for user in commit_acls:
                if collection_name in commit_acls[user] and \
                        aclname not in commit_acls[user][collection_name]:
                    commit_acls[user][collection_name][aclname] = None

    # If the user is not an admin, he/she can only access his/her ACLs
    username = flask.g.fas_user.username
    if username not in admins and not is_pkgdb_admin(flask.g.fas_user):
        tmp = {username: []}
        if username in commit_acls:
            tmp = {username: commit_acls[username]}
        commit_acls = tmp

    form = pkgdb2.forms.ConfirmationForm()

    if form.validate_on_submit():
        sub_acls = flask.request.values.getlist('acls')
        sub_users = flask.request.values.getlist('user')
        sub_branches = flask.request.values.getlist('branch')
        changed = False

        if sub_acls and len(sub_acls) == (len(sub_users) * len(sub_branches)):
            cnt = 0
            for cnt_u in range(len(sub_users)):
                for cnt_b in range(len(sub_branches)):
                    lcl_acl = sub_acls[cnt]
                    lcl_user = sub_users[cnt_u]
                    lcl_branch = sub_branches[cnt_b]

                    if lcl_acl not in acl_status:
                        flask.flash('Invalid ACL: %s' % lcl_acl, 'error')
                        cnt += 1
                        continue

                    if lcl_user not in commit_acls:
                        flask.flash('Invalid user: %s' % lcl_user, 'error')
                        cnt += 1
                        continue

                    if lcl_branch not in branches_inv or (
                        branches_inv[lcl_branch] in commit_acls[lcl_user]
                            and commit_acls[lcl_user][
                                branches_inv[lcl_branch]][
                                    update_acl] == lcl_acl):
                        cnt += 1
                        continue

                    if not lcl_acl:
                        if branches_inv[lcl_branch] \
                                not in commit_acls[lcl_user]:
                            cnt += 1
                            continue
                        elif branches_inv[lcl_branch] \
                                in commit_acls[lcl_user] \
                                and username != lcl_user:
                            flask.flash(
                                'Only the user can remove his/her ACL',
                                'error')
                            cnt += 1
                            continue

                    try:
                        pkgdblib.set_acl_package(
                            SESSION,
                            namespace=namespace,
                            pkg_name=package.name,
                            pkg_branch=lcl_branch,
                            pkg_user=lcl_user,
                            acl=update_acl,
                            status=lcl_acl,
                            user=flask.g.fas_user,
                        )
                        SESSION.commit()
                        flask.flash("%s's %s ACL updated on %s" % (
                            lcl_user, update_acl, lcl_branch))
                        changed = True
                    except PkgdbException as err:
                        SESSION.rollback()
                        flask.flash(str(err), 'error')
                    cnt += 1

            SESSION.commit()
            if not changed:
                flask.flash('Nothing to update')
            return flask.redirect(flask.url_for(
                '.package_info',
                namespace=package.namespace,
                package=package.name)
            )
        else:
            flask.flash('Invalid input submitted', 'error')

    return flask.render_template(
        'acl_update.html',
        acl=update_acl,
        acl_status=acl_status,
        package=package,
        form=form,
        branches=branches,
        commit_acls=commit_acls,
        admins=admins,
        committers=committers,
    )
Beispiel #34
0
def package_give(namespace, package, full=True):
    ''' Gives the PoC of a package to someone else. '''

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

    packagename = package
    package = None
    try:
        package_acl = pkgdblib.get_acl_package(
            SESSION, namespace, packagename)
        package = pkgdblib.search_package(
            SESSION, namespace, packagename, limit=1)[0]
    except (NoResultFound, IndexError):
        SESSION.rollback()
        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
            elif acl.collection.status != 'EOL':
                collect_name.append(acl.collection.branchname)

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

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

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

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

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

                SESSION.commit()
        except pkgdblib.exceptions.PkgdbBugzillaException as err:  # pragma: no cover
            APP.logger.exception(err)
            flask.flash(str(err), 'error')
            SESSION.rollback()
        except PkgdbException as err:
            SESSION.rollback()
            flask.flash(str(err), 'error')

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

    return flask.render_template(
        'package_give.html',
        full=full,
        form=form,
        packagename=packagename,
        namespace=namespace,
    )