Example #1
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')
Example #2
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')
Example #3
0
def is_pkg_admin(session, user, package, branch=None):
    """ Is the user an admin for this package.
    Admin =
        - user has approveacls rights
        - user is a pkgdb admin
    """
    if not user:
        return False
    if is_pkgdb_admin(user):
        return True
    else:
        return pkgdblib.has_acls(
            session, user=user.username,
            package=package, acl='approveacls', branch=branch)
Example #4
0
def is_pkg_admin(session, user, package, branch):
    """ Is the user an admin for this package.
    Admin =
        - user has approveacls rights
        - user is a pkgdb admin
    """
    if not user:
        return False
    if is_pkgdb_admin(user):
        return True
    else:
        return pkgdblib.has_acls(session,
                                 user=user.username,
                                 package=package,
                                 branch=branch,
                                 acl='approveacls')
Example #5
0
def package_request_edit(action_id):
    """ Edit an Admin Action status
    """

    admin_action = pkgdblib.get_admin_action(SESSION, action_id)
    if not admin_action:
        flask.flash('No action found with this identifier.', 'errors')
        return flask.render_template('msg.html')

    package = None
    if admin_action.package:
        package = admin_action.package.name

    if admin_action.status in ['Accepted', 'Blocked', 'Denied']:
        return flask.render_template(
            'actions_update_ro.html',
            admin_action=admin_action,
            action_id=action_id,
        )

    if not is_authenticated() or not 'packager' in flask.g.fas_user.groups:
        return flask.render_template(
            'actions_update_ro.html',
            admin_action=admin_action,
            action_id=action_id,
        )

    # Check user is the pkg/pkgdb admin
    pkg_admin = pkgdblib.has_acls(SESSION, flask.g.fas_user.username, package,
                                  'approveacls')
    if not is_pkgdb_admin(flask.g.fas_user) \
            and not pkg_admin \
            and not admin_action.user == flask.g.fas_user.username:
        flask.flash(
            'Only package adminitrators (`approveacls`) and the requester '
            'can review pending branch requests', 'errors')
        if package:
            return flask.redirect(
                flask.url_for('.package_info', package=package))
        else:
            return flask.redirect(
                flask.url_for('.packager_requests',
                              packager=flask.g.fas_user.username))

    action_status = ['Pending', 'Awaiting Review', 'Blocked']
    if admin_action.user == flask.g.fas_user.username:
        action_status = ['Pending', 'Obsolete']
        if pkg_admin or admin_action.action == 'request.package':
            action_status.append('Awaiting Review')

    form = pkgdb2.forms.EditActionStatusForm(status=action_status,
                                             obj=admin_action)
    form.id.data = action_id

    if form.validate_on_submit():

        try:
            message = pkgdblib.edit_action_status(
                SESSION,
                admin_action,
                action_status=form.status.data,
                user=flask.g.fas_user,
                message=form.message.data,
            )
            SESSION.commit()
            flask.flash(message)
        except pkgdblib.PkgdbException, err:  # pragma: no cover
            # We can only reach here in two cases:
            # 1) the user is not an admin, but that's taken care of
            #    by the decorator
            # 2) we have a SQLAlchemy problem when storing the info
            #    in the DB which we cannot test
            SESSION.rollback()
            flask.flash(err, 'errors')
            return flask.render_template('msg.html')

        if package:
            return flask.redirect(
                flask.url_for('.package_info', package=package))
        else:
            return flask.redirect(
                flask.url_for('.packager_requests',
                              packager=flask.g.fas_user.username))
Example #6
0
def package_request_edit(action_id):
    """ Edit an Admin Action status
    """

    admin_action = pkgdblib.get_admin_action(SESSION, action_id)
    if not admin_action:
        flask.flash('No action found with this identifier.', 'errors')
        return flask.render_template('msg.html')

    package = None
    namespace = None
    if admin_action.package:
        package = admin_action.package.name
        namespace = admin_action.package.namespace

    if admin_action.status in ['Accepted', 'Blocked', 'Denied']:
        return flask.render_template(
            'actions_update_ro.html',
            admin_action=admin_action,
            action_id=action_id,
        )

    pkger_grp = APP.config.get('PKGER_GROUP', 'packager')
    if not is_authenticated() or not pkger_grp in flask.g.fas_user.groups:
        return flask.render_template(
            'actions_update_ro.html',
            admin_action=admin_action,
            action_id=action_id,
        )

    # Check user is the pkg/pkgdb admin
    pkg_admin = pkgdblib.has_acls(
        SESSION, flask.g.fas_user.username,
        namespace, package, 'approveacls')

    if not is_pkgdb_admin(flask.g.fas_user) \
            and not pkg_admin \
            and not admin_action.user == flask.g.fas_user.username:
        flask.flash(
            'Only package adminitrators (`approveacls`) and the requester '
            'can review pending branch requests', 'errors')
        if package:
            return flask.redirect(flask.url_for(
                '.package_info', namespace=namespace, package=package)
            )
        else:
            return flask.redirect(
                flask.url_for(
                    '.packager_requests',
                    packager=flask.g.fas_user.username)
            )

    action_status = ['Pending', 'Awaiting Review', 'Blocked']
    if admin_action.user == flask.g.fas_user.username:
        action_status = ['Pending', 'Obsolete']
        if pkg_admin or admin_action.action in [
                'request.package', 'request.unretire']:
            action_status.append('Awaiting Review')

    form = pkgdb2.forms.EditActionStatusForm(
        status=action_status,
        obj=admin_action
    )
    form.id.data = action_id

    if form.validate_on_submit():

        try:
            message = pkgdblib.edit_action_status(
                SESSION,
                admin_action,
                action_status=form.status.data,
                user=flask.g.fas_user,
                message=form.message.data,
            )
            SESSION.commit()
            flask.flash(message)
        except PkgdbException as err:  # pragma: no cover
            # We can only reach here in two cases:
            # 1) the user is not an admin, but that's taken care of
            #    by the decorator
            # 2) we have a SQLAlchemy problem when storing the info
            #    in the DB which we cannot test
            SESSION.rollback()
            flask.flash(err, 'errors')
            return flask.render_template('msg.html')

        if package:
            return flask.redirect(flask.url_for(
                '.package_info', namespace=namespace, package=package)
            )
        else:
            return flask.redirect(
                flask.url_for(
                    '.packager_requests',
                    packager=flask.g.fas_user.username)
            )

    return flask.render_template(
        'actions_update.html',
        admin_action=admin_action,
        action_id=action_id,
        form=form,
        package=package,
        tag='packages',
    )
Example #7
0
File: acls.py Project: voxik/pkgdb2
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))
Example #8
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))