Beispiel #1
0
    def test_get_acl_package(self):
        """ Test the get_acl_package function. """
        create_package_acl(self.session)

        packages = model.Package.all(self.session)
        self.assertEqual(3, len(packages))
        self.assertEqual('guake', packages[0].name)

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(len(pkg_acl), 2)
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].acls[0].fas_name, 'pingou')

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake', 'devel')
        self.assertEqual(pkg_acl.collection.branchname, 'devel')
        self.assertEqual(pkg_acl.package.name, 'guake')
        self.assertEqual(pkg_acl.acls[0].fas_name, 'pingou')

        # Collection does not exist
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.get_acl_package,
                          self.session,
                          'guake',
                          'unknown')
Beispiel #2
0
def package_retire(package, collection):
    ''' Gives the possibility to orphan or take 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:
        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')

    for acl in package_acl:
        if acl.collection.branchname == collection:
            if acl.point_of_contact == 'orphan':
                try:
                    pkgdblib.update_pkg_status(
                        session=SESSION,
                        pkg_name=package.name,
                        clt_name=acl.collection.branchname,
                        status='Deprecated',
                        user=flask.g.fas_user)
                    flask.flash('This package has been retired on branch: %s' %
                                collection)
                except pkgdblib.PkgdbException, err:
                    flask.flash(err.message, 'error')
                break
            else:
                flask.flash('This package has not been orphaned on '
                            'branch: %s' % collection)
Beispiel #3
0
def api_acl_get(packagename=None):
    ''' ``/api/package/acl/get/<packagename>/``
    or ``/api/package/acl/get/?packagename=<packagename>``
    Returns the ACL for a given package.

    Accept GET queries only.

    :arg packagename: String of the package name that one wants the ACL
        of.
    :return: a JSON string containing the ACL information for that
        package.

    '''
    packagename = flask.request.args.get('packagename', None) or packagename
    httpcode = 200
    output = {}
    if packagename:
        try:
            packages = pkgdblib.get_acl_package(SESSION, packagename)
            output = {'acls': [pkg.to_json() for pkg in packages]}
        except NoResultFound:
            SESSION.rollback()
            output['output'] = 'notok'
            output['error'] = 'No package found with name "%s"' % packagename
            httpcode = 500
    else:
        output = {'output': 'notok', 'error': 'No package provided'}
        httpcode = 500

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout
Beispiel #4
0
def package_orphan(package, collection):
    ''' Gives the possibility to orphan or take 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:
        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')

    for acl in package_acl:
        if acl.collection.branchname == collection:
            try:
                pkgdblib.update_pkg_poc(session=SESSION,
                                        pkg_name=package.name,
                                        clt_name=acl.collection.branchname,
                                        pkg_poc='orphan',
                                        user=flask.g.fas_user)
                flask.flash(
                    'You are no longer point of contact on branch: %s' %
                    collection)
            except pkgdblib.PkgdbException, err:
                flask.flash(err.message, 'error')
            break
Beispiel #5
0
def package_retire(package, collection):
    ''' Gives the possibility to orphan or take 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')

    for acl in package_acl:
        if acl.collection.branchname == collection:
            if acl.point_of_contact == 'orphan':
                try:
                    pkgdblib.update_pkg_status(
                        session=SESSION,
                        pkg_name=package.name,
                        pkg_branch=acl.collection.branchname,
                        status='Retired',
                        user=flask.g.fas_user
                    )
                    flask.flash(
                        'This package has been retired on branch: %s'
                        % collection)
                except pkgdblib.PkgdbException, err:
                    flask.flash(err.message, 'error')
                    SESSION.rollback()
                break
            else:
                flask.flash(
                    'This package has not been orphaned on '
                    'branch: %s' % collection)
Beispiel #6
0
def package_orphan(package, collection):
    ''' Gives the possibility to orphan or take 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:
        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')

    for acl in package_acl:
        if acl.collection.branchname == collection:
            try:
                pkgdblib.update_pkg_poc(
                    session=SESSION,
                    pkg_name=package.name,
                    clt_name=acl.collection.branchname,
                    pkg_poc='orphan',
                    user=flask.g.fas_user
                )
                flask.flash(
                    'You are no longer point of contact on branch: %s'
                    % collection)
            except pkgdblib.PkgdbException, err:
                flask.flash(err.message, 'error')
            break
Beispiel #7
0
def api_acl_get(packagename=None):
    ''' ``/api/package/acl/get/<packagename>/``
    or ``/api/package/acl/get/?packagename=<packagename>``
    Returns the ACL for a given package.

    Accept GET queries only.

    :arg packagename: String of the package name that one wants the ACL
        of.
    :return: a JSON string containing the ACL information for that
        package.

    '''
    packagename = flask.request.args.get('packagename', None) or packagename
    httpcode = 200
    output = {}
    if packagename:
        try:
            packages = pkgdblib.get_acl_package(SESSION, packagename)
            output = {'acls': [pkg.to_json() for pkg in packages]}
        except NoResultFound:
            SESSION.rollback()
            output['output'] = 'notok'
            output['error'] = 'No package found with name "%s"' % packagename
            httpcode = 500
    else:
        output = {'output': 'notok', 'error': 'No package provided'}
        httpcode = 500

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout
Beispiel #8
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,
    )
Beispiel #9
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,
    )
Beispiel #10
0
    def test_get_acl_package(self):
        """ Test the get_acl_package function. """
        create_package_acl(self.session)

        packages = model.Package.all(self.session)
        self.assertEqual(3, len(packages))
        self.assertEqual('guake', packages[0].name)

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(len(pkg_acl), 2)
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].acls[0].fas_name, 'pingou')

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake', 'devel')
        self.assertEqual(pkg_acl.collection.branchname, 'devel')
        self.assertEqual(pkg_acl.package.name, 'guake')
        self.assertEqual(pkg_acl.acls[0].fas_name, 'pingou')

        # Collection does not exist
        self.assertRaises(pkgdblib.PkgdbException, pkgdblib.get_acl_package,
                          self.session, 'guake', 'unknown')
Beispiel #11
0
    def test_unorphan_package(self):
        """ Test the unorphan_package function. """
        create_package_acl(self.session)

        # Wrong package name
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='asd',
                          clt_name='devel',
                          pkg_user='******',
                          user=FakeFasUser()
                          )

        # Wrong collection
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='asd',
                          pkg_user='******',
                          user=FakeFasUser()
                          )

        # Package is not orphaned
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          pkg_user='******',
                          user=FakeFasUser()
                          )

        # Orphan package
        pkgdblib.update_pkg_poc(self.session,
                                pkg_name='guake',
                                clt_name='devel',
                                user=FakeFasUserAdmin(),
                                pkg_poc='orphan',
                                )

        # User cannot unorphan for someone else
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          pkg_user='******',
                          user=FakeFasUser()
                          )

        # User must be a packager
        user = FakeFasUser()
        user.groups = ['cla_done']
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          pkg_user='******',
                          user=user
                          )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
        self.assertEqual(pkg_acl[1].package.name, 'guake')
        self.assertEqual(pkg_acl[1].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[1].status, 'Orphaned')

        pkgdblib.unorphan_package(
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          pkg_user='******',
                          user=FakeFasUser()
                          )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
        self.assertEqual(pkg_acl[1].package.name, 'guake')
        self.assertEqual(pkg_acl[1].point_of_contact, 'pingou')
        self.assertEqual(pkg_acl[1].status, 'Approved')
Beispiel #12
0
    def test_update_pkg_poc(self):
        """ Test the update_pkg_poc function. """
        self.test_add_package()

        # Package must exists
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.update_pkg_poc,
                          self.session,
                          pkg_name='test',
                          clt_name='F-17',
                          user=FakeFasUser(),
                          pkg_poc='toshio',
                          )
        self.session.rollback()

        # Collection must exists
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.update_pkg_poc,
                          self.session,
                          pkg_name='guake',
                          clt_name='F-16',
                          user=FakeFasUser(),
                          pkg_poc='toshio',
                          )
        self.session.rollback()

        # User must be the actual Point of Contact (or an admin of course,
        # or part of the group)
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.update_pkg_poc,
                          self.session,
                          pkg_name='guake',
                          clt_name='F-18',
                          user=FakeFasUser(),
                          pkg_poc='toshio',
                          )
        self.session.rollback()

        # Groups must end with -sig
        user = FakeFasUser()
        user.username = '******'
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.update_pkg_poc,
                          self.session,
                          pkg_name='guake',
                          clt_name='F-18',
                          user=user,
                          pkg_poc='group::perl',
                          )
        self.session.rollback()

        # Change PoC to a group
        pkgdblib.update_pkg_poc(
                          self.session,
                          pkg_name='guake',
                          clt_name='F-18',
                          user=user,
                          pkg_poc='group::perl-sig',
                          )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'group::perl-sig')

        # User must be in the group it gives the PoC to
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.update_pkg_poc,
                          self.session,
                          pkg_name='guake',
                          clt_name='F-18',
                          user=user,
                          pkg_poc='ralph',
                          )
        self.session.rollback()

        user.groups.append('perl-sig')
        pkgdblib.update_pkg_poc(
                          self.session,
                          pkg_name='guake',
                          clt_name='F-18',
                          user=user,
                          pkg_poc='ralph',
                          )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'ralph')

        # PoC can change PoC
        user = FakeFasUser()
        user.username = '******'
        pkgdblib.update_pkg_poc(self.session,
                                 pkg_name='guake',
                                 clt_name='F-18',
                                 user=user,
                                 pkg_poc='toshio',
                                 )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'toshio')

        # Admin can change PoC
        pkgdblib.update_pkg_poc(self.session,
                                 pkg_name='guake',
                                 clt_name='F-18',
                                 user=FakeFasUserAdmin(),
                                 pkg_poc='kevin',
                                 )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'kevin')

        # Orphan -> status changed to Orphaned
        user = FakeFasUser()
        user.username = '******'
        pkgdblib.update_pkg_poc(self.session,
                                 pkg_name='guake',
                                 clt_name='F-18',
                                 user=user,
                                 pkg_poc='orphan',
                                 )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[0].status, 'Orphaned')

        # Take orphaned package -> status changed to Approved
        pkgdblib.update_pkg_poc(self.session,
                                 pkg_name='guake',
                                 clt_name='F-18',
                                 user=FakeFasUser(),
                                 pkg_poc=FakeFasUser().username,
                                 )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'pingou')
        self.assertEqual(pkg_acl[0].status, 'Approved')
Beispiel #13
0
def package_give(package):
    ''' Gives the PoC of a package to someone else. '''


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

    # 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
            else:
                collect_name.append(acl.collection.branchname)

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

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

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

                SESSION.commit()
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'error')

        return flask.redirect(
            flask.url_for('.package_info', package=packagename)
        )
Beispiel #14
0
    def test_update_pkg_status(self):
        """ Test the update_pkg_status function. """
        create_package_acl(self.session)

        # Wrong package
        self.assertRaises(
            pkgdblib.PkgdbException,
            pkgdblib.update_pkg_status,
            self.session,
            pkg_name='test',
            clt_name='F-17',
            status='Deprecated',
            user=FakeFasUser(),
        )
        self.session.rollback()

        # Wrong collection
        self.assertRaises(
            pkgdblib.PkgdbException,
            pkgdblib.update_pkg_status,
            self.session,
            pkg_name='guake',
            clt_name='F-16',
            status='Orphaned',
            user=FakeFasUser(),
        )
        self.session.rollback()

        # User not allowed to deprecate the package on F-18
        self.assertRaises(
            pkgdblib.PkgdbException,
            pkgdblib.update_pkg_status,
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            status='Deprecated',
            user=FakeFasUser(),
        )
        self.session.rollback()

        # Wrong status
        self.assertRaises(
            pkgdblib.PkgdbException,
            pkgdblib.update_pkg_status,
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            status='Depreasdcated',
            user=FakeFasUser(),
        )
        self.session.rollback()

        # User not allowed to change status to Allowed
        self.assertRaises(
            pkgdblib.PkgdbException,
            pkgdblib.update_pkg_status,
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            status='Allowed',
            user=FakeFasUser(),
        )
        self.session.rollback()

        # Admin can retire package
        pkgdblib.update_pkg_status(self.session,
                                   pkg_name='guake',
                                   clt_name='F-18',
                                   status='Deprecated',
                                   user=FakeFasUserAdmin())

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[0].status, 'Deprecated')

        # User can orphan package
        pkgdblib.update_pkg_status(self.session,
                                   pkg_name='guake',
                                   clt_name='devel',
                                   status='Orphaned',
                                   user=FakeFasUser())

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[0].status, 'Deprecated')
        self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
        self.assertEqual(pkg_acl[1].package.name, 'guake')
        self.assertEqual(pkg_acl[1].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[1].status, 'Orphaned')

        # Admin must give a poc when un-orphan/un-retire a package
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.update_pkg_status,
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          status='Approved',
                          user=FakeFasUserAdmin())

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[0].status, 'Deprecated')
        self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
        self.assertEqual(pkg_acl[1].package.name, 'guake')
        self.assertEqual(pkg_acl[1].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[1].status, 'Orphaned')

        # Admin can un-orphan package
        pkgdblib.update_pkg_status(self.session,
                                   pkg_name='guake',
                                   clt_name='devel',
                                   status='Approved',
                                   poc="pingou",
                                   user=FakeFasUserAdmin())

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[0].status, 'Deprecated')
        self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
        self.assertEqual(pkg_acl[1].package.name, 'guake')
        self.assertEqual(pkg_acl[1].point_of_contact, 'pingou')
        self.assertEqual(pkg_acl[1].status, 'Approved')

        # Admin can un-retire package
        pkgdblib.update_pkg_status(self.session,
                                   pkg_name='guake',
                                   clt_name='F-18',
                                   status='Approved',
                                   poc="pingou",
                                   user=FakeFasUserAdmin())

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'pingou')
        self.assertEqual(pkg_acl[0].status, 'Approved')
        self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
        self.assertEqual(pkg_acl[1].package.name, 'guake')
        self.assertEqual(pkg_acl[1].point_of_contact, 'pingou')
        self.assertEqual(pkg_acl[1].status, 'Approved')

        # Not Admin and status is not Orphaned nor Deprecated
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.update_pkg_status,
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          status='Removed',
                          user=FakeFasUser())
Beispiel #15
0
    def test_update_pkg_poc(self):
        """ Test the update_pkg_poc function. """
        self.test_add_package()

        # Package must exists
        self.assertRaises(
            pkgdblib.PkgdbException,
            pkgdblib.update_pkg_poc,
            self.session,
            pkg_name='test',
            clt_name='F-17',
            user=FakeFasUser(),
            pkg_poc='toshio',
        )
        self.session.rollback()

        # Collection must exists
        self.assertRaises(
            pkgdblib.PkgdbException,
            pkgdblib.update_pkg_poc,
            self.session,
            pkg_name='guake',
            clt_name='F-16',
            user=FakeFasUser(),
            pkg_poc='toshio',
        )
        self.session.rollback()

        # User must be the actual Point of Contact (or an admin of course,
        # or part of the group)
        self.assertRaises(
            pkgdblib.PkgdbException,
            pkgdblib.update_pkg_poc,
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            user=FakeFasUser(),
            pkg_poc='toshio',
        )
        self.session.rollback()

        # Groups must end with -sig
        user = FakeFasUser()
        user.username = '******'
        self.assertRaises(
            pkgdblib.PkgdbException,
            pkgdblib.update_pkg_poc,
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            user=user,
            pkg_poc='group::perl',
        )
        self.session.rollback()

        # Change PoC to a group
        pkgdblib.update_pkg_poc(
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            user=user,
            pkg_poc='group::perl-sig',
        )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'group::perl-sig')

        # User must be in the group it gives the PoC to
        self.assertRaises(
            pkgdblib.PkgdbException,
            pkgdblib.update_pkg_poc,
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            user=user,
            pkg_poc='ralph',
        )
        self.session.rollback()

        user.groups.append('perl-sig')
        pkgdblib.update_pkg_poc(
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            user=user,
            pkg_poc='ralph',
        )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'ralph')

        # PoC can change PoC
        user = FakeFasUser()
        user.username = '******'
        pkgdblib.update_pkg_poc(
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            user=user,
            pkg_poc='toshio',
        )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'toshio')

        # Admin can change PoC
        pkgdblib.update_pkg_poc(
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            user=FakeFasUserAdmin(),
            pkg_poc='kevin',
        )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'kevin')

        # Orphan -> status changed to Orphaned
        user = FakeFasUser()
        user.username = '******'
        pkgdblib.update_pkg_poc(
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            user=user,
            pkg_poc='orphan',
        )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[0].status, 'Orphaned')

        # Take orphaned package -> status changed to Approved
        pkgdblib.update_pkg_poc(
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            user=FakeFasUser(),
            pkg_poc=FakeFasUser().username,
        )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'pingou')
        self.assertEqual(pkg_acl[0].status, 'Approved')
Beispiel #16
0
    def test_set_acl_package(self):
        """ Test the set_acl_package function. """
        self.test_add_package()

        # Not allowed to set acl on non-existant package
        self.assertRaises(
            pkgdblib.PkgdbException,
            pkgdblib.set_acl_package,
            self.session,
            pkg_name='test',
            clt_name='F-17',
            pkg_user='******',
            acl='nothing',
            status='Appr',
            user=FakeFasUser(),
        )
        self.session.rollback()

        # Not allowed to set non-existant collection
        self.assertRaises(
            pkgdblib.PkgdbException,
            pkgdblib.set_acl_package,
            self.session,
            pkg_name='guake',
            clt_name='F-16',
            pkg_user='******',
            acl='nothing',
            status='Appr',
            user=FakeFasUser(),
        )
        self.session.rollback()

        # Not allowed to set non-existant status
        self.assertRaises(
            IntegrityError,
            pkgdblib.set_acl_package,
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            acl='commit',
            pkg_user='******',
            status='Appro',
            user=FakeFasUserAdmin(),
        )
        self.session.rollback()

        # Not allowed to set non-existant acl
        self.assertRaises(
            IntegrityError,
            pkgdblib.set_acl_package,
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            pkg_user='******',
            acl='nothing',
            status='Approved',
            user=FakeFasUserAdmin(),
        )
        self.session.rollback()

        # Not allowed to set acl for yourself
        self.assertRaises(
            pkgdblib.PkgdbException,
            pkgdblib.set_acl_package,
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            pkg_user='******',
            acl='approveacls',
            status='Approved',
            user=FakeFasUser(),
        )
        self.session.rollback()

        # Not allowed to set acl for someone else
        self.assertRaises(
            pkgdblib.PkgdbException,
            pkgdblib.set_acl_package,
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            pkg_user='******',
            acl='commit',
            status='Approved',
            user=FakeFasUser(),
        )
        self.session.rollback()

        # Not allowed to set acl approveacl to a group
        self.assertRaises(
            pkgdblib.PkgdbException,
            pkgdblib.set_acl_package,
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            pkg_user='******',
            acl='approveacls',
            status='Approved',
            user=FakeFasUser(),
        )
        self.session.rollback()

        # Group must ends with -sig
        self.assertRaises(
            pkgdblib.PkgdbException,
            pkgdblib.set_acl_package,
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            pkg_user='******',
            acl='commit',
            status='Approved',
            user=FakeFasUser(),
        )
        self.session.rollback()

        # You can ask for new ACLs
        pkgdblib.set_acl_package(
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            pkg_user='******',
            acl='approveacls',
            status='Awaiting Review',
            user=FakeFasUser(),
        )

        # You can obsolete your own ACLs
        pkgdblib.set_acl_package(
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            pkg_user='******',
            acl='approveacls',
            status='Obsolete',
            user=FakeFasUser(),
        )

        # You can remove your own ACLs
        pkgdblib.set_acl_package(
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            pkg_user='******',
            acl='approveacls',
            status='Removed',
            user=FakeFasUser(),
        )

        # An admin can approve you ACLs
        pkgdblib.set_acl_package(
            self.session,
            pkg_name='guake',
            clt_name='F-18',
            pkg_user='******',
            acl='commit',
            status='Approved',
            user=FakeFasUserAdmin(),
        )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(len(pkg_acl[0].acls), 6)
Beispiel #17
0
    def test_unorphan_package(self):
        """ Test the unorphan_package function. """
        create_package_acl(self.session)

        # Wrong package name
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='asd',
                          clt_name='devel',
                          pkg_user='******',
                          user=FakeFasUser())

        # Wrong collection
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='asd',
                          pkg_user='******',
                          user=FakeFasUser())

        # Package is not orphaned
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          pkg_user='******',
                          user=FakeFasUser())

        # Orphan package
        pkgdblib.update_pkg_poc(
            self.session,
            pkg_name='guake',
            clt_name='devel',
            user=FakeFasUserAdmin(),
            pkg_poc='orphan',
        )

        # User cannot unorphan for someone else
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          pkg_user='******',
                          user=FakeFasUser())

        # User must be a packager
        user = FakeFasUser()
        user.groups = ['cla_done']
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          pkg_user='******',
                          user=user)

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
        self.assertEqual(pkg_acl[1].package.name, 'guake')
        self.assertEqual(pkg_acl[1].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[1].status, 'Orphaned')

        pkgdblib.unorphan_package(self.session,
                                  pkg_name='guake',
                                  clt_name='devel',
                                  pkg_user='******',
                                  user=FakeFasUser())

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
        self.assertEqual(pkg_acl[1].package.name, 'guake')
        self.assertEqual(pkg_acl[1].point_of_contact, 'pingou')
        self.assertEqual(pkg_acl[1].status, 'Approved')
Beispiel #18
0
    def test_set_acl_package(self):
        """ Test the set_acl_package function. """
        self.test_add_package()

        # Not allowed to set acl on non-existant package
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.set_acl_package,
                          self.session,
                          pkg_name='test',
                          clt_name='F-17',
                          pkg_user='******',
                          acl='nothing',
                          status='Appr',
                          user=FakeFasUser(),
                          )
        self.session.rollback()

        # Not allowed to set non-existant collection
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.set_acl_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='F-16',
                          pkg_user='******',
                          acl='nothing',
                          status='Appr',
                          user=FakeFasUser(),
                          )
        self.session.rollback()

        # Not allowed to set non-existant status
        self.assertRaises(IntegrityError,
                          pkgdblib.set_acl_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='F-18',
                          acl='commit',
                          pkg_user='******',
                          status='Appro',
                          user=FakeFasUserAdmin(),
                          )
        self.session.rollback()

        # Not allowed to set non-existant acl
        self.assertRaises(IntegrityError,
                          pkgdblib.set_acl_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='F-18',
                          pkg_user='******',
                          acl='nothing',
                          status='Approved',
                          user=FakeFasUserAdmin(),
                          )
        self.session.rollback()

        # Not allowed to set acl for yourself
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.set_acl_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='F-18',
                          pkg_user='******',
                          acl='approveacls',
                          status='Approved',
                          user=FakeFasUser(),
                          )
        self.session.rollback()

        # Not allowed to set acl for someone else
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.set_acl_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='F-18',
                          pkg_user='******',
                          acl='commit',
                          status='Approved',
                          user=FakeFasUser(),
                          )
        self.session.rollback()

        # Not allowed to set acl approveacl to a group
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.set_acl_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='F-18',
                          pkg_user='******',
                          acl='approveacls',
                          status='Approved',
                          user=FakeFasUser(),
                          )
        self.session.rollback()

        # Group must ends with -sig
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.set_acl_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='F-18',
                          pkg_user='******',
                          acl='commit',
                          status='Approved',
                          user=FakeFasUser(),
                          )
        self.session.rollback()

        # You can ask for new ACLs
        pkgdblib.set_acl_package(self.session,
                                 pkg_name='guake',
                                 clt_name='F-18',
                                 pkg_user='******',
                                 acl='approveacls',
                                 status='Awaiting Review',
                                 user=FakeFasUser(),
                                 )

        # You can obsolete your own ACLs
        pkgdblib.set_acl_package(self.session,
                                 pkg_name='guake',
                                 clt_name='F-18',
                                 pkg_user='******',
                                 acl='approveacls',
                                 status='Obsolete',
                                 user=FakeFasUser(),
                                 )

        # You can remove your own ACLs
        pkgdblib.set_acl_package(self.session,
                                 pkg_name='guake',
                                 clt_name='F-18',
                                 pkg_user='******',
                                 acl='approveacls',
                                 status='Removed',
                                 user=FakeFasUser(),
                                 )

        # An admin can approve you ACLs
        pkgdblib.set_acl_package(self.session,
                                 pkg_name='guake',
                                 clt_name='F-18',
                                 pkg_user='******',
                                 acl='commit',
                                 status='Approved',
                                 user=FakeFasUserAdmin(),
                                 )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(len(pkg_acl[0].acls), 6)
    def test_api_package_unorphan(self, login_func, mock_func):
        """ Test the api_package_unorphan function.  """
        login_func.return_value=None

        # Redirect as you are not a packager
        user = FakeFasUser()
        user.groups = []

        with user_set(pkgdb.APP, user):
            output = self.app.post('/api/package/unorphan/')
            self.assertEqual(output.status_code, 302)

        user = FakeFasUser()
        with user_set(pkgdb.APP, user):
            output = self.app.post('/api/package/unorphan/')
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "Invalid input submitted",
                    "error_detail": [
                        "pkg_poc: This field is required.",
                        "clt_name: This field is required.",
                        "pkg_name: This field is required."
                    ],
                    "output": "notok"
                }
            )

        data = {
            'pkg_name': 'guake',
            'clt_name': 'F-18,devel',
            'pkg_poc': 'test',
        }
        with user_set(pkgdb.APP, user):
            output = self.app.post('/api/package/unorphan/', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "No package found by this name",
                    "output": "notok"
                }
            )

        create_package_acl(self.session)
        mock_func.log.return_value = ''

        # Unorphan a not-orphaned package
        data = {
            'pkg_name': 'guake',
            'clt_name': 'F-18,devel',
            'pkg_poc': 'test',
        }
        with user_set(pkgdb.APP, user):
            output = self.app.post('/api/package/unorphan/', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "Package is not orphaned on F-18",
                    "output": "notok"
                }
            )

        # Orphan the package
        data = {
            'pkg_name': 'guake',
            'clt_name': 'F-18,devel',
            'pkg_poc': 'test',
        }
        with user_set(pkgdb.APP, user):
            output = self.app.post('/api/package/orphan/', data=data)
            self.assertEqual(output.status_code, 200)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "messages": ["", ""],
                    "output": "ok"
                }
            )
            pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
            self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
            self.assertEqual(pkg_acl[0].package.name, 'guake')
            self.assertEqual(pkg_acl[0].point_of_contact, 'orphan')
            self.assertEqual(pkg_acl[0].status, 'Orphaned')

            self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
            self.assertEqual(pkg_acl[1].package.name, 'guake')
            self.assertEqual(pkg_acl[1].point_of_contact, 'orphan')
            self.assertEqual(pkg_acl[1].status, 'Orphaned')

        # Unorphan the package for someone else
        data = {
            'pkg_name': 'guake',
            'clt_name': 'F-18,devel',
            'pkg_poc': 'test',
        }
        with user_set(pkgdb.APP, user):
            output = self.app.post('/api/package/unorphan/', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "You are not allowed to update ACLs of someone else.",
                    "output": "notok"
                }
            )

        # Unorphan the package
        data = {
            'pkg_name': 'guake',
            'clt_name': 'F-18,devel',
            'pkg_poc': 'pingou',
        }
        with user_set(pkgdb.APP, user):
            output = self.app.post('/api/package/unorphan/', data=data)
            self.assertEqual(output.status_code, 200)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "messages": [
                        "Package guake has been unorphaned on F-18 by pingou",
                        "Package guake has been unorphaned on devel by pingou"
                    ],
                    "output": "ok"
                }
            )

            pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
            self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
            self.assertEqual(pkg_acl[0].package.name, 'guake')
            self.assertEqual(pkg_acl[0].point_of_contact, 'pingou')
            self.assertEqual(pkg_acl[0].status, 'Approved')

            self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
            self.assertEqual(pkg_acl[1].package.name, 'guake')
            self.assertEqual(pkg_acl[1].point_of_contact, 'pingou')
            self.assertEqual(pkg_acl[1].status, 'Approved')
Beispiel #20
0
    def test_update_pkg_status(self):
        """ Test the update_pkg_status function. """
        create_package_acl(self.session)

        # Wrong package
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.update_pkg_status,
                          self.session,
                          pkg_name='test',
                          clt_name='F-17',
                          status='Deprecated',
                          user=FakeFasUser(),
                          )
        self.session.rollback()

        # Wrong collection
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.update_pkg_status,
                          self.session,
                          pkg_name='guake',
                          clt_name='F-16',
                          status='Orphaned',
                          user=FakeFasUser(),
                          )
        self.session.rollback()

        # User not allowed to deprecate the package on F-18
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.update_pkg_status,
                          self.session,
                          pkg_name='guake',
                          clt_name='F-18',
                          status='Deprecated',
                          user=FakeFasUser(),
                          )
        self.session.rollback()

        # Wrong status
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.update_pkg_status,
                          self.session,
                          pkg_name='guake',
                          clt_name='F-18',
                          status='Depreasdcated',
                          user=FakeFasUser(),
                          )
        self.session.rollback()

        # User not allowed to change status to Allowed
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.update_pkg_status,
                          self.session,
                          pkg_name='guake',
                          clt_name='F-18',
                          status='Allowed',
                          user=FakeFasUser(),
                          )
        self.session.rollback()

        # Admin can retire package
        pkgdblib.update_pkg_status(self.session,
                                   pkg_name='guake',
                                   clt_name='F-18',
                                   status='Deprecated',
                                   user=FakeFasUserAdmin()
                                   )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[0].status, 'Deprecated')

        # User can orphan package
        pkgdblib.update_pkg_status(self.session,
                                   pkg_name='guake',
                                   clt_name='devel',
                                   status='Orphaned',
                                   user=FakeFasUser()
                                   )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[0].status, 'Deprecated')
        self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
        self.assertEqual(pkg_acl[1].package.name, 'guake')
        self.assertEqual(pkg_acl[1].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[1].status, 'Orphaned')

        # Admin must give a poc when un-orphan/un-retire a package
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.update_pkg_status,
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          status='Approved',
                          user=FakeFasUserAdmin()
                          )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[0].status, 'Deprecated')
        self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
        self.assertEqual(pkg_acl[1].package.name, 'guake')
        self.assertEqual(pkg_acl[1].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[1].status, 'Orphaned')


        # Admin can un-orphan package
        pkgdblib.update_pkg_status(self.session,
                                   pkg_name='guake',
                                   clt_name='devel',
                                   status='Approved',
                                   poc="pingou",
                                   user=FakeFasUserAdmin()
                                   )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[0].status, 'Deprecated')
        self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
        self.assertEqual(pkg_acl[1].package.name, 'guake')
        self.assertEqual(pkg_acl[1].point_of_contact, 'pingou')
        self.assertEqual(pkg_acl[1].status, 'Approved')

        # Admin can un-retire package
        pkgdblib.update_pkg_status(self.session,
                                   pkg_name='guake',
                                   clt_name='F-18',
                                   status='Approved',
                                   poc="pingou",
                                   user=FakeFasUserAdmin()
                                   )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
        self.assertEqual(pkg_acl[0].package.name, 'guake')
        self.assertEqual(pkg_acl[0].point_of_contact, 'pingou')
        self.assertEqual(pkg_acl[0].status, 'Approved')
        self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
        self.assertEqual(pkg_acl[1].package.name, 'guake')
        self.assertEqual(pkg_acl[1].point_of_contact, 'pingou')
        self.assertEqual(pkg_acl[1].status, 'Approved')

        # Not Admin and status is not Orphaned nor Deprecated
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.update_pkg_status,
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          status='Removed',
                          user=FakeFasUser()
                          )
Beispiel #21
0
def package_give(package):
    ''' Gives the PoC of a package to someone else. '''

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

    # 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
            else:
                collect_name.append(acl.collection.branchname)

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

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

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

                SESSION.commit()
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'error')

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