def html_form_data(client, params):
    """ Transform our Ansible params into an HTML form "data" for POST'ing.
    """
    data = {}
    data['product[short_name]'] = params['short_name']
    data['product[name]'] = params['name']
    data['product[description]'] = params['description']
    data['product[bugzilla_product_name]'] = params['bugzilla_product_name']
    data['product[valid_bug_states][]'] = params['valid_bug_states']
    data['product[isactive]'] = int(params['active'])
    data['product[ftp_path]'] = params['ftp_path']
    data['product[ftp_subdir]'] = params['ftp_subdir']
    data['product[is_internal]'] = int(params['internal'])
    if params['default_docs_reviewer'] is not None:
        default_docs_reviewer_id = common_errata_tool.user_id(
            client, params['default_docs_reviewer'])
        data['product[default_docs_reviewer_id]'] = default_docs_reviewer_id
    # push targets need scraper
    push_target_scraper = common_errata_tool.PushTargetScraper(client)
    push_target_ints = push_target_scraper.convert_to_ints(
        params['push_targets'])
    data['product[push_targets][]'] = push_target_ints
    # This is an internal-only product thing that we can probably skip:
    # data['product[cdw_flag_prefix]'] = params['cdw_flag_prefix']
    solution = params['default_solution'].upper()
    solution_id = int(common_errata_tool.DefaultSolutions[solution])
    data['product[default_solution_id]'] = solution_id
    workflow_rules_scraper = common_errata_tool.WorkflowRulesScraper(client)
    state_machine_rule_set_id = int(
        workflow_rules_scraper.enum[params['state_machine_rule_set']])
    data['product[state_machine_rule_set_id]'] = state_machine_rule_set_id
    data['product[move_bugs_on_qe]'] = int(params['move_bugs_on_qe'])
    data['product[text_only_advisories_require_dists]'] = int(
        params['text_only_advisories_require_dists'])
    return data
def api_data(client, params):
    """ Transform our Ansible params into JSON data for POST'ing or PUT'ing.

    :param client: Errata Client
    :param dict params: ansible module params
    """
    # XXX The docs at /developer-guide/api-http-api.html#api-apis
    # mention a few settings I have not seen before:
    # - "allow_beta"
    # - "is_deferred"
    # - "url_name" - this one is actually listed twice!
    # Are those really a valid settings? grep errata-rails.git for more
    # references to find out. That whole POST /api/v1/releases section of the
    # docs could probably use a review.
    # CLOUDWF-298 is an RFE for specifying all values by name instead of ID.
    release = params.copy()
    # Update the values for ones that the REST API will accept:
    if 'product' in release:
        product_name = release.pop('product')
        if product_name is not None:
            release['product_id'] = get_product_id(client, product_name)
    if 'program_manager' in release:
        pm_login_name = release.pop('program_manager')
        try:
            pm_id = common_errata_tool.user_id(client, pm_login_name)
        except UserNotFoundError as e:
            raise_from(ProgramManagerNotFoundError(str(e)), e)
        release['program_manager_id'] = pm_id
    # "active" -> "isactive"
    if 'active' in release:
        active = release.pop('active')
        release['isactive'] = active
    # "supports_component_acl" -> "disable_acl"
    if 'supports_component_acl' in release:
        supports_component_acl = release.pop('supports_component_acl')
        release['disable_acl'] = not supports_component_acl
    # "product_versions" -> "product_version_ids"
    if 'product_versions' in release:
        product_versions = release.pop('product_versions')
        product_version_ids = get_product_version_ids(client, product_versions)
        release['product_version_ids'] = product_version_ids
    # "state_machine_rule_set" -> "state_machine_rule_set_id"
    if 'state_machine_rule_set' in release:
        state_machine_rule_set = release.pop('state_machine_rule_set')
        if state_machine_rule_set:
            rules_scraper = common_errata_tool.WorkflowRulesScraper(client)
            rule_set_id = int(rules_scraper.enum[state_machine_rule_set])

            release['state_machine_rule_set_id'] = rule_set_id
        else:
            release['state_machine_rule_set_id'] = None
    # "blocker_flags" list -> str
    if 'blocker_flags' in release:
        release['blocker_flags'] = ",".join(release['blocker_flags'])
    data = {'release': release}
    if 'type' in params:
        data['type'] = params['type']
    return data
def html_form_data(client, params):
    """ Transform our Ansible params into an HTML form "data" for POST'ing.
    """
    data = {}
    data['product[short_name]'] = params['short_name']
    data['product[name]'] = params['name']
    data['product[description]'] = params['description']
    data['product[bugzilla_product_name]'] = params['bugzilla_product_name']
    data['product[valid_bug_states][]'] = params['valid_bug_states']
    data['product[isactive]'] = int(params['active'])
    data['product[ftp_path]'] = params['ftp_path']
    data['product[ftp_subdir]'] = params.get('ftp_subdir', '')
    data['product[is_internal]'] = int(params['internal'])
    docs_reviewer = params.get('default_docs_reviewer')
    if docs_reviewer is not None:
        try:
            docs_user_id = common_errata_tool.user_id(client, docs_reviewer)
        except UserNotFoundError as e:
            raise_from(DocsReviewerNotFoundError(str(e)), e)
        data['product[default_docs_reviewer_id]'] = docs_user_id
    # push targets need scraper
    push_targets = params['push_targets']
    push_target_scraper = common_errata_tool.PushTargetScraper(client)
    push_target_ints = push_target_scraper.convert_to_ints(push_targets)
    data['product[push_targets][]'] = push_target_ints
    # This is an internal-only product thing that we can probably skip:
    # data['product[cdw_flag_prefix]'] = params['cdw_flag_prefix']
    solution = params['default_solution'].upper()
    solution_id = int(common_errata_tool.DefaultSolutions[solution])
    data['product[default_solution_id]'] = solution_id
    state_machine_rule_set = params['state_machine_rule_set']
    rules_scraper = common_errata_tool.WorkflowRulesScraper(client)
    state_machine_rule_set_id = int(rules_scraper.enum[state_machine_rule_set])
    data['product[state_machine_rule_set_id]'] = state_machine_rule_set_id
    data['product[move_bugs_on_qe]'] = int(params['move_bugs_on_qe'])
    exd_org_group = params.get('exd_org_group')
    if exd_org_group is not None:
        exd_org_group_id = int(EXD_ORG_GROUPS[exd_org_group])
        data['product[exd_org_group_id]'] = exd_org_group_id
    return data