Пример #1
0
def avatar(packager, size=64):
    """ Template filter to produce the libravatar of a given packager. """
    if is_authenticated() and packager == flask.g.fas_user.username:
        openid_template = "http://{packager}.id.fedoraproject.org/"
        openid = openid_template.format(packager=packager)
        avatar = pkgdblib.utils.avatar_url(packager, size)
        return """<form method="POST" action="https://www.libravatar.org/openid/login/">
            <input type="hidden" name="openid_identifier" value="{openid}"/>
            <input type="image" class="avatar circle" src="{avatar}" style="outline: none;"
            title="Update your avatar"/>
        </form>""".format(
            openid=openid, avatar=avatar
        )
    else:
        return '<img class="avatar circle" src="%s"/>' % (pkgdblib.utils.avatar_url(packager, size))
Пример #2
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',
    )
Пример #3
0
def package_info(namespace, package):
    ''' Display the information about the specified 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')

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

    branches = set()
    commit_acls = {}
    watch_acls = {}
    admins = {}
    pending_admins = {}
    pocs = {}
    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)

        branches.add(collection_name)

        if pkg.point_of_contact not in pocs:
            pocs[pkg.point_of_contact] = set()
        pocs[pkg.point_of_contact].add(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)
            elif acl.acl == 'approveacls' and acl.status == 'Awaiting Review':
                if acl.fas_name not in pending_admins:
                    pending_admins[acl.fas_name] = set()
                pending_admins[acl.fas_name].add(collection_name)

            if acl.acl == 'commit':
                dic = commit_acls
                if acl.status == 'Approved':
                    committers.append(acl.fas_name)
            elif acl.acl.startswith('watch') and acl.status == 'Approved':
                dic = watch_acls
            else:  # pragma: no cover  -- pass isn't `covered` by coverage
                # We managed approveacls earlier
                continue

            if acl.fas_name not in dic:
                dic[acl.fas_name] = {}
            if collection_name not in dic[acl.fas_name]:
                dic[acl.fas_name][collection_name] = {}

            dic[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

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

    statuses = set([
        listing.status
        for listing in package.sorted_listings
        if listing.collection.status != 'EOL'
    ])

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

    requester = False
    if is_authenticated():
        for req in package.requests:
            if req.user == flask.g.fas_user.username:
                requester = True
                break

    return flask.render_template(
        'package.html',
        package=package,
        commit_acls=commit_acls,
        watch_acls=watch_acls,
        pocs=pocs,
        admins=admins,
        statuses=statuses,
        pending_admins=pending_admins,
        branches=branches,
        branches_possible=branches_possible,
        committers=committers,
        form=pkgdb2.forms.ConfirmationForm(),
        requester=requester,
    )