Exemplo n.º 1
0
def comaintain_package(package):
    if not 'packager' in flask.g.fas_user.groups:
        flask.flash(
            'You must be a packager to apply to be a comaintainer',
            'errors')
        return flask.redirect(flask.url_for(
            '.package_info', package=package))

    pkg = pkgdblib.search_package(SESSION, pkg_name=package, limit=1)[0]
    pkg_acls = ['commit', 'watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]

    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,
                clt_name=collec,
                pkg_user=flask.g.fas_user.username,
                acl=acl,
                status=acl_status,
                user=flask.g.fas_user,
            )
        SESSION.commit()
        flask.flash('ACLs updated')
        return flask.redirect(
            flask.url_for('.package_info',
                          package=package))
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        flask.flash(err.message, 'error')
Exemplo n.º 2
0
def comaintain_package(package):
    if not 'packager' in flask.g.fas_user.groups:
        flask.flash('You must be a packager to apply to be a comaintainer',
                    'errors')
        return flask.redirect(flask.url_for('.package_info', package=package))

    pkg = pkgdblib.search_package(SESSION, pkg_name=package, limit=1)[0]
    pkg_acls = ['commit', 'watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]

    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,
                clt_name=collec,
                pkg_user=flask.g.fas_user.username,
                acl=acl,
                status=acl_status,
                user=flask.g.fas_user,
            )
        SESSION.commit()
        flask.flash('ACLs updated')
        return flask.redirect(flask.url_for('.package_info', package=package))
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        flask.flash(err.message, 'error')
Exemplo n.º 3
0
def watch_package(package):
    ''' Request watch* ACLs on a package.
    Anyone can request these ACLs, no need to be a packager.
    '''
    try:
        pkg = pkgdblib.search_package(SESSION, pkg_name=package, limit=1)[0]
    except IndexError:
        flask.flash('No package found by this name', 'error')
        return flask.redirect(
            flask.url_for('.package_info', package=package))

    pkg_acls = ['watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]
    try:
        for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
            pkgdblib.set_acl_package(
                SESSION,
                pkg_name=package,
                pkg_branch=collec,
                pkg_user=flask.g.fas_user.username,
                acl=acl,
                status='Approved',
                user=flask.g.fas_user,
            )
        SESSION.commit()
        flask.flash('ACLs updated')
    # Let's keep this in although we should never see it
    except pkgdblib.PkgdbException, err:  # pragma: no cover
        SESSION.rollback()
        flask.flash(err.message, 'error')
Exemplo n.º 4
0
def update_acl(package, user, branch=None):
    ''' Update the acls for a specific user on a package. '''

    pending_acls = pkgdblib.get_acl_user_package(SESSION,
                                                 user,
                                                 package,
                                                 status=None)
    if branch is not None:
        pending_acls2 = []
        for acls in pending_acls:
            if acls['collection'] == branch:
                pending_acls2.append(acls)
        pending_acls = pending_acls2

    collections = set([item['collection'] for item in pending_acls])
    status = pkgdb.lib.get_status(SESSION, ['pkg_acl', 'pkg_status'])

    form = pkgdb.forms.UpdateAclPackageForm(
        collections=collections,
        pkg_acl_list=status['pkg_acl'],
        pkg_status=status['pkg_status'],
    )

    if form.validate_on_submit():
        pkg_branchs = form.pkg_branch.data
        pkg_acls = form.pkg_acl.data
        acl_status = form.acl_status.data

        try:
            branch_out = []
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
                if collec in branch_out:
                    continue

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

                pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=package,
                    clt_name=collec,
                    pkg_user=user,
                    acl=acl,
                    status=acl_status,
                    user=flask.g.fas_user,
                )
                flask.flash('ACLs updated')
            SESSION.commit()
            return flask.redirect(
                flask.url_for('.package_info', package=package))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'errors')
Exemplo n.º 5
0
def update_acl(package, user, branch=None):
    ''' Update the acls for a specific user on a package. '''

    pending_acls = pkgdblib.get_acl_user_package(
        SESSION, user, package, status=None)
    if branch is not None:
        pending_acls2 = []
        for acls in pending_acls:
            if acls['collection'] == branch:
                pending_acls2.append(acls)
        pending_acls = pending_acls2

    collections = set([item['collection'] for item in pending_acls])
    status = pkgdb.lib.get_status(SESSION, ['pkg_acl', 'pkg_status'])

    form = pkgdb.forms.UpdateAclPackageForm(
        collections=collections,
        pkg_acl_list=status['pkg_acl'],
        pkg_status=status['pkg_status'],
        )

    if form.validate_on_submit():
        pkg_branchs = form.pkg_branch.data
        pkg_acls = form.pkg_acl.data
        acl_status = form.acl_status.data

        try:
            branch_out = []
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
                if collec in branch_out:
                    continue

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

                pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=package,
                    clt_name=collec,
                    pkg_user=user,
                    acl=acl,
                    status=acl_status,
                    user=flask.g.fas_user,
                )
                flask.flash('ACLs updated')
            SESSION.commit()
            return flask.redirect(
                flask.url_for('.package_info',
                              package=package))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'errors')
Exemplo n.º 6
0
def request_acl(package):
    ''' Request acls for a specific package. '''

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

    form = pkgdb.forms.RequestAclPackageForm(
        collections=collections,
        pkg_acl_list=pkg_acl
        )
    if form.validate_on_submit():
        pkg_branchs = form.pkg_branch.data
        pkg_acls = form.pkg_acl.data

        try:
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
                acl_status = 'Awaiting Review'
                if acl in APP.config['AUTO_APPROVE']:
                    acl_status = 'Approved'
                elif 'packager' not in flask.g.fas_user.groups:
                    flask.flash(
                        'You must be a packager to apply to the'
                        ' ACL: %s on %s' % (acl, collec), 'errors')
                    continue

                pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=package,
                    clt_name=collec,
                    pkg_user=flask.g.fas_user.username,
                    acl=acl,
                    status=acl_status,
                    user=flask.g.fas_user,
                )
            SESSION.commit()
            flask.flash('ACLs updated')
            return flask.redirect(
                flask.url_for('.package_info',
                              package=package))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'error')
Exemplo n.º 7
0
def comaintain_package(package):
    ''' Asks for ACLs to co-maintain a package.
    You need to be a packager to request co-maintainership.
    '''
    # This is really wearing belt and suspenders, the decorator above
    # should take care of this
    if not 'packager' in flask.g.fas_user.groups:  # pragma: no cover
        flask.flash(
            'You must be a packager to apply to be a comaintainer',
            'errors')
        return flask.redirect(flask.url_for(
            '.package_info', package=package))

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

    pkg_acls = ['commit', 'watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]

    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(err.message, 'error')
Exemplo n.º 8
0
def api_acl_update():
    ''' ``/api/package/acl/``
    Update the ACL for a given package.

    Accept POST queries only.

    :arg pkg_name: String of the package name.
    :arg pkg_branch: List of strings with the name of the branches to change,
        update.
    :arg pkg_acl: List of strings of the ACL to change/update. Possible acl
        are: 'commit', 'build', 'watchbugzilla', 'watchcommits',
        'approveacls', 'checkout'.
    :arg pkg_status: String of the type of action required. Possible status
        are: 'Approved', 'Awaiting Review', 'Denied', 'Obsolete', 'Removed'.
    :kwarg pkg_user: the name of the user that is the target of this ACL
        change/update. This will only work if: 1) you are an admin,
        2) you are changing one of your package.

     '''
    httpcode = 200
    output = {}

    status = pkgdb.lib.get_status(SESSION, ['pkg_acl', 'acl_status'])

    form = forms.SetAclPackageForm(
        csrf_enabled=False,
        pkg_acl=status['pkg_acl'],
        acl_status=status['acl_status'],
    )
    if form.validate_on_submit():
        pkg_name = form.pkg_name.data
        pkg_branch = form.pkg_branch.data.split(',')
        pkg_acl = form.pkg_acl.data
        pkg_status = form.pkg_status.data
        pkg_user = form.pkg_user.data

        try:
            for branch in pkg_branch:
                message = pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=pkg_name,
                    pkg_branch=branch,
                    pkg_acl=pkg_acl,
                    pkg_status=pkg_status,
                    pkg_user=pkg_user,
                    user=flask.g.fas_user.username,
                )
            SESSION.commit()
            output['output'] = 'ok'
            output['messages'] = [message]
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            output['output'] = 'notok'
            output['error'] = err
            httpcode = 500
Exemplo n.º 9
0
def api_acl_update():
    ''' ``/api/package/acl/``
    Update the ACL for a given package.

    Accept POST queries only.

    :arg pkg_name: String of the package name.
    :arg pkg_branch: List of strings with the name of the branches to change,
        update.
    :arg pkg_acl: List of strings of the ACL to change/update. Possible acl
        are: 'commit', 'build', 'watchbugzilla', 'watchcommits',
        'approveacls', 'checkout'.
    :arg pkg_status: String of the type of action required. Possible status
        are: 'Approved', 'Awaiting Review', 'Denied', 'Obsolete', 'Removed'.
    :kwarg pkg_user: the name of the user that is the target of this ACL
        change/update. This will only work if: 1) you are an admin,
        2) you are changing one of your package.

     '''
    httpcode = 200
    output = {}

    status = pkgdb.lib.get_status(SESSION, ['pkg_acl', 'acl_status'])

    form = forms.SetAclPackageForm(
        csrf_enabled=False,
        pkg_acl=status['pkg_acl'],
        acl_status=status['acl_status'],
    )
    if form.validate_on_submit():
        pkg_name = form.pkg_name.data
        pkg_branch = form.pkg_branch.data.split(',')
        pkg_acl = form.pkg_acl.data
        pkg_status = form.pkg_status.data
        pkg_user = form.pkg_user.data

        try:
            for branch in pkg_branch:
                message = pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=pkg_name,
                    pkg_branch=branch,
                    pkg_acl=pkg_acl,
                    pkg_status=pkg_status,
                    pkg_user=pkg_user,
                    user=flask.g.fas_user.username,
                )
            SESSION.commit()
            output['output'] = 'ok'
            output['messages'] = [message]
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            output['output'] = 'notok'
            output['error'] = err
            httpcode = 500
Exemplo n.º 10
0
def request_acl(package):
    ''' Request acls for a specific package. '''

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

    form = pkgdb.forms.RequestAclPackageForm(collections=collections,
                                             pkg_acl_list=pkg_acl)
    if form.validate_on_submit():
        pkg_branchs = form.pkg_branch.data
        pkg_acls = form.pkg_acl.data

        try:
            for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
                acl_status = 'Awaiting Review'
                if acl in APP.config['AUTO_APPROVE']:
                    acl_status = 'Approved'
                elif 'packager' not in flask.g.fas_user.groups:
                    flask.flash(
                        'You must be a packager to apply to the'
                        ' ACL: %s on %s' % (acl, collec), 'errors')
                    continue

                pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=package,
                    clt_name=collec,
                    pkg_user=flask.g.fas_user.username,
                    acl=acl,
                    status=acl_status,
                    user=flask.g.fas_user,
                )
            SESSION.commit()
            flask.flash('ACLs updated')
            return flask.redirect(
                flask.url_for('.package_info', package=package))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'error')
Exemplo n.º 11
0
def watch_package(package):
    pkg = pkgdblib.search_package(SESSION, pkg_name=package)[0]
    pkg_acls = ['watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]
    try:
        for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
            pkgdblib.set_acl_package(
                SESSION,
                pkg_name=package,
                clt_name=collec,
                pkg_user=flask.g.fas_user.username,
                acl=acl,
                status='Approved',
                user=flask.g.fas_user,
            )
        SESSION.commit()
        flask.flash('ACLs updated')
        return flask.redirect(flask.url_for('.package_info', package=package))
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        flask.flash(err.message, 'error')
Exemplo n.º 12
0
def watch_package(package):
    pkg = pkgdblib.search_package(SESSION, pkg_name=package)[0]
    pkg_acls = ['watchcommits', 'watchbugzilla']
    pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings]
    try:
        for (collec, acl) in itertools.product(pkg_branchs, pkg_acls):
            pkgdblib.set_acl_package(
                SESSION,
                pkg_name=package,
                clt_name=collec,
                pkg_user=flask.g.fas_user.username,
                acl=acl,
                status='Approved',
                user=flask.g.fas_user,
            )
        SESSION.commit()
        flask.flash('ACLs updated')
        return flask.redirect(
            flask.url_for('.package_info',
                          package=package))
    except pkgdblib.PkgdbException, err:
        SESSION.rollback()
        flask.flash(err.message, 'error')
Exemplo n.º 13
0
def api_acl_update():
    '''
Update package ACL
------------------
    Update the ACL for a given package.

    ::

        /api/package/acl/

    Accept POST queries only.

    :arg pkg_name: String of the package name.
    :arg pkg_branch: List of strings with the name of the branches to change,
        update.
    :arg pkg_acl: List of strings of the ACL to change/update. Possible acl
        are: 'commit', 'build', 'watchbugzilla', 'watchcommits',
        'approveacls', 'checkout'.
    :arg acl_status: String of the type of action required. Possible status
        are: 'Approved', 'Awaiting Review', 'Denied', 'Obsolete', 'Removed'.
    :kwarg pkg_user: the name of the user that is the target of this ACL
        change/update. This will only work if: 1) you are an admin,
        2) you are changing one of your package.

    Sample response:

    ::

        {
          "output": "ok",
          "messages": ["user: $USER set acl: $ACL of package: $PACKAGE "
                       "from: $PREVIOUS_STATUS to $NEW_STATUS on branch: "
                       "$BRANCH"]
        }

        {
          "output": "notok",
          "error": ["You are not allowed to update ACLs of someone else."]
        }

     '''
    httpcode = 200
    output = {}

    status = pkgdb.lib.get_status(SESSION, ['pkg_acl', 'acl_status'])

    form = forms.SetAclPackageForm(
        csrf_enabled=False,
        pkg_acl=status['pkg_acl'],
        acl_status=status['acl_status'],
    )
    if form.validate_on_submit():
        pkg_name = form.pkg_name.data
        pkg_branch = form.pkg_branch.data.split(',')
        pkg_acl = form.pkg_acl.data
        acl_status = form.acl_status.data
        pkg_user = form.pkg_user.data

        try:
            messages = []
            for branch in pkg_branch:
                message = pkgdblib.set_acl_package(
                    SESSION,
                    pkg_name=pkg_name,
                    pkg_branch=branch,
                    acl=pkg_acl,
                    status=acl_status,
                    pkg_user=pkg_user,
                    user=flask.g.fas_user,
                )
                messages.append(message)
            SESSION.commit()
            output['output'] = 'ok'
            output['messages'] = messages
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            output['output'] = 'notok'
            output['error'] = err.message
            httpcode = 500
Exemplo n.º 14
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)
Exemplo n.º 15
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)
Exemplo n.º 16
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)
        )
Exemplo n.º 17
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))