예제 #1
0
def package_info(package):
    ''' Display the information about the specified package. '''

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

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

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

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

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

    return flask.render_template(
        'package.html',
        package=package,
        package_acl=package_acls,
        branch_admin=branch_admin,
        is_poc=is_poc,
    )
예제 #3
0
def unorphan_package(session, pkg_name, clt_name, pkg_user, user):
    """ Unorphan a specific package in favor of someone and give him the
    appropriate ACLs.

    :arg session: session with which to connect to the database
    :arg pkg_name: the name of the package
    :arg clt_name: the name of the collection
    :arg pkg_user: the FAS user requesting the package
    :arg user: the user making the action
    """
    try:
        package = model.Package.by_name(session, pkg_name)
        pkg_listing = get_acl_package(session, pkg_name, clt_name)
    except NoResultFound:
        raise PkgdbException('No package found by this name')

    if not pkg_listing.status in ('Orphaned', 'Deprecated'):
        raise PkgdbException('Package is not orphaned on %s' % clt_name)

    if not pkgdb.is_pkg_admin(user, package.name, clt_name):
        if user.username != pkg_user and not pkg_user.startswith('group::'):
            raise PkgdbException('You are not allowed to update ACLs of '
                                 'someone else.')
        elif user.username == pkg_user and 'packager' not in user.groups:
            raise PkgdbException('You must be a packager to take a package.')

    status = 'Approved'
    pkg_listing.point_of_contact = pkg_user
    pkg_listing.status = status
    session.add(pkg_listing)
    session.flush()

    model.Log.insert(
        session, user.username, package,
        'user: %s un-orphaned package: %s on branch: %s' %
        (user.username, package.name, clt_name))

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

    for acl in acls:
        personpkg = model.PackageListingAcl.get_or_create(session,
                                                          pkg_user,
                                                          pkg_listing.id,
                                                          acl=acl,
                                                          status=status)
        prev_status = personpkg.status
        personpkg.status = status
        session.add(personpkg)
        model.Log.insert(
            session, user.username, package,
            'user: %s set acl: %s of package: %s from: %s to: %s on '
            'branch: %s' %
            (user.username, acl, package.name, prev_status, status, clt_name))
    session.flush()
예제 #4
0
def unorphan_package(session, pkg_name, clt_name, pkg_user, user):
    """ Unorphan a specific package in favor of someone and give him the
    appropriate ACLs.

    :arg session: session with which to connect to the database
    :arg pkg_name: the name of the package
    :arg clt_name: the name of the collection
    :arg pkg_user: the FAS user requesting the package
    :arg user: the user making the action
    """
    try:
        package = model.Package.by_name(session, pkg_name)
        pkg_listing = get_acl_package(session, pkg_name, clt_name)
    except NoResultFound:
        raise PkgdbException('No package found by this name')

    if not pkg_listing.status in ('Orphaned', 'Deprecated'):
            raise PkgdbException('Package is not orphaned on %s' % clt_name)

    if not pkgdb.is_pkg_admin(user, package.name, clt_name):
        if user.username != pkg_user and not pkg_user.startswith('group::'):
            raise PkgdbException('You are not allowed to update ACLs of '
                                 'someone else.')
        elif user.username == pkg_user and 'packager' not in user.groups:
            raise PkgdbException('You must be a packager to take a package.')

    status = 'Approved'
    pkg_listing.point_of_contact = pkg_user
    pkg_listing.status = status
    session.add(pkg_listing)
    session.flush()

    model.Log.insert(
        session,
        user.username,
        package,
        'user: %s un-orphaned package: %s on branch: %s' % (
            user.username, package.name, clt_name)
    )

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

    for acl in acls:
        personpkg = model.PackageListingAcl.get_or_create(session,
                                                          pkg_user,
                                                          pkg_listing.id,
                                                          acl=acl,
                                                          status=status)
        prev_status = personpkg.status
        personpkg.status = status
        session.add(personpkg)
        model.Log.insert(
            session,
            user.username,
            package,
            'user: %s set acl: %s of package: %s from: %s to: %s on '
            'branch: %s' % (
                user.username, acl, package.name, prev_status, status,
                clt_name)
        )
    session.flush()
예제 #5
0
def set_acl_package(session, pkg_name, clt_name, pkg_user, acl, status,
                    user):
    """ Set the specified ACLs for the specified package.

    :arg session: session with which to connect to the database
    :arg pkg_name: the name of the package
    :arg colt_name: the name of the collection
    :arg pkg_user: the FAS user for which the ACL should be set/change
    :arg status: the status of the ACLs
    :arg user: the user making the action
    """
    try:
        package = model.Package.by_name(session, pkg_name)
        package_acl = get_acl_package(session, pkg_name)
    except NoResultFound:
        raise PkgdbException('No package found by this name')

    try:
        collection = model.Collection.by_name(session, clt_name)
    except NoResultFound:
        raise PkgdbException('No collection found by this name')

    if not pkgdb.is_pkg_admin(user, package.name, clt_name):
        if user.username != pkg_user and not pkg_user.startswith('group::'):
            raise PkgdbException('You are not allowed to update ACLs of '
                                 'someone else.')
        elif user.username == pkg_user and status not in \
                ('Awaiting Review', 'Removed', 'Obsolete') \
                and acl not in pkgdb.APP.config['AUTO_APPROVE']:
                raise PkgdbException(
                    'You are not allowed to approve or deny '
                    'ACLs for yourself.')

    if pkg_user.startswith('group::') and acl == 'approveacls':
        raise PkgdbException(
            'Groups cannot have "approveacls".')

    if pkg_user.startswith('group::') and not pkg_user.endswith('-sig'):
        raise PkgdbException(
            'Invalid group "%s" all groups in pkgdb should end with '
            '"-sig".' % pkg_user)

    try:
        pkglisting = model.PackageListing.by_pkgid_collectionid(
            session,
            package.id,
            collection.id)
    except NoResultFound:  # pragma: no cover  TODO: can we test this?
        pkglisting = package.create_listing(owner=pkg_user,
                                            collection=collection,
                                            statusname='Approved')
        session.add(pkglisting)
        session.flush()

    personpkg = model.PackageListingAcl.get_or_create(session,
                                                      pkg_user,
                                                      pkglisting.id,
                                                      acl=acl,
                                                      status=status)
    prev_status = personpkg.status
    personpkg.status = status
    session.flush()
    model.Log.insert(
        session,
        user.username,
        package,
        'user: %s set acl: %s of package: %s from: %s to: %s on '
        'branch: %s' % (
            user.username, acl, package.name, prev_status, status,
            collection.branchname)
    )
예제 #6
0
def set_acl_package(session, pkg_name, clt_name, pkg_user, acl, status, user):
    """ Set the specified ACLs for the specified package.

    :arg session: session with which to connect to the database
    :arg pkg_name: the name of the package
    :arg colt_name: the name of the collection
    :arg pkg_user: the FAS user for which the ACL should be set/change
    :arg status: the status of the ACLs
    :arg user: the user making the action
    """
    try:
        package = model.Package.by_name(session, pkg_name)
        package_acl = get_acl_package(session, pkg_name)
    except NoResultFound:
        raise PkgdbException('No package found by this name')

    try:
        collection = model.Collection.by_name(session, clt_name)
    except NoResultFound:
        raise PkgdbException('No collection found by this name')

    if not pkgdb.is_pkg_admin(user, package.name, clt_name):
        if user.username != pkg_user and not pkg_user.startswith('group::'):
            raise PkgdbException('You are not allowed to update ACLs of '
                                 'someone else.')
        elif user.username == pkg_user and status not in \
                ('Awaiting Review', 'Removed', 'Obsolete') \
                and acl not in pkgdb.APP.config['AUTO_APPROVE']:
            raise PkgdbException('You are not allowed to approve or deny '
                                 'ACLs for yourself.')

    if pkg_user.startswith('group::') and acl == 'approveacls':
        raise PkgdbException('Groups cannot have "approveacls".')

    if pkg_user.startswith('group::') and not pkg_user.endswith('-sig'):
        raise PkgdbException(
            'Invalid group "%s" all groups in pkgdb should end with '
            '"-sig".' % pkg_user)

    try:
        pkglisting = model.PackageListing.by_pkgid_collectionid(
            session, package.id, collection.id)
    except NoResultFound:  # pragma: no cover  TODO: can we test this?
        pkglisting = package.create_listing(owner=pkg_user,
                                            collection=collection,
                                            statusname='Approved')
        session.add(pkglisting)
        session.flush()

    personpkg = model.PackageListingAcl.get_or_create(session,
                                                      pkg_user,
                                                      pkglisting.id,
                                                      acl=acl,
                                                      status=status)
    prev_status = personpkg.status
    personpkg.status = status
    session.flush()
    model.Log.insert(
        session, user.username, package,
        'user: %s set acl: %s of package: %s from: %s to: %s on '
        'branch: %s' % (user.username, acl, package.name, prev_status, status,
                        collection.branchname))