def handle_patch(cls, **kwargs):
        """Bulk/single system change of opt_out status"""

        args_desc = [{
            'arg_name': 'opt_out',
            'convert_func': None
        }, {
            'arg_name': 'inventory_id',
            'convert_func': parse_str_or_list
        }]
        args = cls._parse_arguments(kwargs['data'], args_desc)

        opt_out = args['opt_out']
        system_list = args['inventory_id']

        update = (SystemPlatform.update(opt_out=opt_out).where(
            ((RHAccount.select(RHAccount.id).where(
                RHAccount.name == connexion.context['user']).get()
              ).id == SystemPlatform.rh_account_id)
            & (SystemPlatform.inventory_id << system_list)).returning(
                SystemPlatform))
        updated = []
        for system in update.execute():
            updated.append(system.inventory_id)
        if not updated:
            raise ApplicationException(
                'inventory_id must exist and inventory_id must be visible to user',
                404)
        return {'updated': updated}
 def handle_patch(cls, **kwargs):
     """Logic of the opt out feature"""
     inventory_id = kwargs['inventory_id']
     value = kwargs['value']
     update = (SystemPlatform.update(opt_out=value)
               .where(((RHAccount.select(RHAccount.id)
                        .where(RHAccount.name == connexion.context['user'])
                        .get()).id == SystemPlatform.rh_account_id) &
                      (SystemPlatform.inventory_id == inventory_id)))
     rows_affected = update.execute()
     if rows_affected == 0:
         raise ApplicationException('inventory_id must exist and inventory_id must be visible to user', 404)
 def handle_patch(cls, **kwargs):
     """Logic of the opt out feature"""
     inventory_id = kwargs['inventory_id']
     value = kwargs['value']
     try:
         account = (RHAccount.select(RHAccount.id).where(
             RHAccount.name == connexion.context['user']).get())
     except DoesNotExist as exc:
         raise ApplicationException('user does not exist', 403) from exc
     update = (SystemPlatform.update(opt_out=value).where(
         (account.id == SystemPlatform.rh_account_id)
         & (SystemPlatform.inventory_id == inventory_id)
         & (SystemPlatform.when_deleted.is_null(True))))
     rows_affected = update.execute()
     if rows_affected == 0:
         raise ApplicationException(
             'inventory_id must exist and inventory_id must be visible to user',
             404)
示例#4
0
    def handle_patch(cls, **kwargs):
        """Bulk/single system change of opt_out status"""
        opt_out = kwargs['data']['opt_out']
        system_list = kwargs['data']['inventory_id']
        if isinstance(system_list, str):
            system_list = [system_list]

        update = (SystemPlatform.update(opt_out=opt_out).where(
            ((RHAccount.select(RHAccount.id).where(
                RHAccount.name == connexion.context['user']).get()
              ).id == SystemPlatform.rh_account_id)
            & (SystemPlatform.inventory_id << system_list)).returning(
                SystemPlatform))
        updated = []
        for system in update.execute():
            updated.append(system.inventory_id)
        if not updated:
            raise ApplicationException(
                'inventory_id must exist and inventory_id must be visible to user',
                404)
        return {'updated': updated}