Пример #1
0
    def delete(self, id, version_id):
        """Delete a product version.

        Endpoint: /v1/products/<product_id>/versions/<version_id>
        """
        if (not api_utils.check_user_is_product_admin(id)
                and not api_utils.check_user_is_foundation_admin()):

            pecan.abort(403, 'Forbidden.')
        try:
            version = db.get_product_version(version_id,
                                             allowed_keys=['version'])
            if not version['version']:
                pecan.abort(
                    400, 'Can not delete the empty version as it is '
                    'used for basic product/test association. '
                    'This version was implicitly created with '
                    'the product, and so it cannot be deleted '
                    'explicitly.')

            db.delete_product_version(version_id)
        except DBReferenceError:
            pecan.abort(
                400, 'Unable to delete. There are still tests '
                'associated to this product version.')
        pecan.response.status = 204
Пример #2
0
    def put(self, test_id, **kw):
        """Update a test result."""
        test_info = {'id': test_id}
        is_foundation_admin = api_utils.check_user_is_foundation_admin()

        if 'product_version_id' in kw:
            test = db.get_test(test_id)
            if test['verification_status'] == const.TEST_VERIFIED:
                pecan.abort(
                    403, 'Can not update product_version_id for a '
                    'verified test run.')

            if kw['product_version_id']:
                # Verify that the user is a member of the product's vendor.
                version = db.get_product_version(kw['product_version_id'],
                                                 allowed_keys=['product_id'])
                is_vendor_admin = (api_utils.check_user_is_product_admin(
                    version['product_id']))
            else:
                # No product vendor to check membership for, so just set
                # is_vendor_admin to True.
                is_vendor_admin = True
                kw['product_version_id'] = None

            if not is_vendor_admin and not is_foundation_admin:
                pecan.abort(403, 'Forbidden.')

            test_info['product_version_id'] = kw['product_version_id']

        if 'verification_status' in kw:
            if not is_foundation_admin:
                pecan.abort(
                    403, 'You do not have permission to change a '
                    'verification status.')

            if kw['verification_status'] not in (0, 1):
                pecan.abort(
                    400, 'Invalid verification_status value: %d' %
                    kw['verification_status'])

            # Check pre-conditions are met to mark a test verified.
            if (kw['verification_status'] == 1
                    and not (db.get_test_meta_key(test_id, 'target')
                             and db.get_test_meta_key(test_id, 'guideline')
                             and db.get_test_meta_key(test_id,
                                                      const.SHARED_TEST_RUN))):

                pecan.abort(
                    403, 'In order to mark a test verified, the '
                    'test must be shared and have been '
                    'associated to a guideline and target '
                    'program.')

            test_info['verification_status'] = kw['verification_status']

        test = db.update_test(test_info)
        pecan.response.status = 201
        return test
Пример #3
0
 def get_one(self, id, version_id):
     """Get specific version information."""
     product = db.get_product(id)
     vendor_id = product['organization_id']
     is_admin = (api_utils.check_user_is_foundation_admin()
                 or api_utils.check_user_is_vendor_admin(vendor_id))
     if not product['public'] and not is_admin:
         pecan.abort(403, 'Forbidden.')
     allowed_keys = ['id', 'product_id', 'version', 'cpid']
     return db.get_product_version(version_id, allowed_keys=allowed_keys)
Пример #4
0
def check_owner(test_id):
    """Check that user has access to specified test run as owner."""
    if not is_authenticated():
        return False

    test = db.get_test(test_id)
    # If the test is owned by a product.
    if test.get('product_version_id'):
        version = db.get_product_version(test['product_version_id'])
        return check_user_is_product_admin(version['product_id'])
    # Otherwise, check the user ownership.
    else:
        user = db.get_test_meta_key(test_id, const.USER)
        return user and user == get_user_id()
Пример #5
0
def check_owner(test_id):
    """Check that user has access to specified test run as owner."""
    if not is_authenticated():
        return False

    test = db.get_test_result(test_id)
    # If the test is owned by a product.
    if test.get('product_version_id'):
        version = db.get_product_version(test['product_version_id'])
        return check_user_is_product_admin(version['product_id'])
    # Otherwise, check the user ownership.
    else:
        user = db.get_test_result_meta_key(test_id, const.USER)
        return user and user == get_user_id()