Beispiel #1
0
    def register(self, vendor):
        """Handler for applying for registration with Foundation."""
        if not api_utils.check_user_is_vendor_admin(vendor['id']):
            pecan.abort(403, 'Forbidden.')
        _check_is_not_foundation(vendor['id'])

        if vendor['type'] != const.PRIVATE_VENDOR:
            raise api_exc.ValidationError(
                'Invalid organization state for this action.')

        # change vendor type to pending
        org_info = {'id': vendor['id'], 'type': const.PENDING_VENDOR}
        db.update_organization(org_info)
Beispiel #2
0
    def cancel(self, vendor):
        """Handler for canceling registration.

        This action available to user. It allows him to cancel
        registrationand move state of his vendor from pending
        to private.
        """
        if not api_utils.check_user_is_vendor_admin(vendor['id']):
            pecan.abort(403, 'Forbidden.')
        _check_is_not_foundation(vendor['id'])

        if vendor['type'] != const.PENDING_VENDOR:
            raise api_exc.ValidationError(
                'Invalid organization state for this action.')

        # change vendor type back to private
        org_info = {'id': vendor['id'], 'type': const.PRIVATE_VENDOR}
        db.update_organization(org_info)
Beispiel #3
0
    def approve(self, vendor):
        """Handler for making vendor official."""
        if not api_utils.check_user_is_foundation_admin():
            pecan.abort(403, 'Forbidden.')
        _check_is_not_foundation(vendor['id'])

        if vendor['type'] != const.PENDING_VENDOR:
            raise api_exc.ValidationError(
                'Invalid organization state for this action.')

        # change vendor type to public
        props = vendor.get('properties')
        props = json.loads(props) if props else {}
        props.pop('registration_decline_reason', None)
        org_info = {
            'id': vendor['id'],
            'type': const.OFFICIAL_VENDOR,
            'properties': json.dumps(props)
        }
        db.update_organization(org_info)
Beispiel #4
0
    def put(self, vendor_id, **kw):
        """Handler for update item. Should return full info with updates."""
        is_admin = (api_utils.check_user_is_foundation_admin()
                    or api_utils.check_user_is_vendor_admin(vendor_id))
        if not is_admin:
            pecan.abort(403, 'Forbidden.')

        vendor_info = {'id': vendor_id}
        if 'name' in kw:
            vendor_info['name'] = kw['name']
        if 'description' in kw:
            vendor_info['description'] = kw['description']
        if 'properties' in kw:
            vendor_info['properties'] = json.dumps(kw['properties'])
        db.update_organization(vendor_info)

        pecan.response.status = 200
        vendor = db.get_organization(vendor_id)
        vendor['can_manage'] = True
        return vendor
Beispiel #5
0
    def deny(self, vendor, reason):
        """Handler for denying a vendor."""
        if not api_utils.check_user_is_foundation_admin():
            pecan.abort(403, 'Forbidden.')
        _check_is_not_foundation(vendor['id'])

        if not reason:
            raise api_exc.ValidationError('Param "reason" can not be empty')
        if vendor['type'] != const.PENDING_VENDOR:
            raise api_exc.ValidationError(
                'Invalid organization state for this action.')

        props = vendor.get('properties')
        props = json.loads(props) if props else {}
        props['reason'] = reason

        # change vendor type back to private
        org_info = {
            'id': vendor['id'],
            'type': const.PRIVATE_VENDOR,
            'properties': json.dumps(props)
        }
        db.update_organization(org_info)
Beispiel #6
0
    def put(self, vendor_id, **kw):
        """Handler for update item. Should return full info with updates."""
        is_foundation_admin = api_utils.check_user_is_foundation_admin()
        is_admin = (is_foundation_admin
                    or api_utils.check_user_is_vendor_admin(vendor_id))
        if not is_admin:
            pecan.abort(403, 'Forbidden.')
        vendor_info = {'id': vendor_id}
        vendor = db.get_organization(vendor_id)
        if 'name' in kw:
            if (vendor['type'] == const.OFFICIAL_VENDOR
                    and not is_foundation_admin):
                pecan.abort(
                    403, 'Name change for an official vendor is not allowed.')
            vendor_info['name'] = kw['name']
        if 'description' in kw:
            vendor_info['description'] = kw['description']
        if 'properties' in kw:
            vendor_info['properties'] = json.dumps(kw['properties'])
        vendor = db.update_organization(vendor_info)

        pecan.response.status = 200
        vendor['can_manage'] = True
        return vendor