def get_item_actions(permissions_model, role_name, target_name,
    target_visibility, target_ownership, debug=False):
    """Returns the possible actions for a target given a role and target
    status.

    Parameters
    ----------

    permissions_policy : dict
        A permissions model returned by :py:func:`.load_permissions_json`.

    role_name : str
        The name of the role to find the valid actions for.

    target_name : str
        The name of the item to check the valid actions for.

    target_visibility : str
        The visibility of the tiem to check the valid actions for.

    target_ownership: {'for_owned','for_other'}
        If 'for_owned', only the valid actions for the target item available if
        the item is owned by the user will be returned. If 'for_other', only the
        valid actions subject to the visibility of the item owned by other users
        will be returned.

    debug : bool
        If True, will print the policy decisions being taken.

    Returns
    -------

    set
        Returns a set of valid actions for the target item based on the applied
        policy. If the actions don't make sense, returns an empty set, in which
        case access MUST be denied.

    """
    role_policy = permissions_model['role_policy']
    item_policy = permissions_model['item_policy']
    if debug:
        print(
            'role_name = %s\ntarget_name = %s\ntarget_visibility = %s\ntarget_ownership = %s'
             % (role_name, target_name, target_visibility, target_ownership))
    try:
        target_valid_actions = item_policy[target_name]['valid_role_actions']
        target_valid_visibilities = item_policy[target_name][
            'valid_visibilities']
        target_invalid_roles = item_policy[target_name]['invalid_roles']
        if debug:
            print('%s valid_perms: %r' % (target_name, target_valid_actions))
            print('%s valid_visibilities: %r' % (target_name,
                target_valid_visibilities))
            print('%s invalid_roles: %r' % (target_name, target_invalid_roles))
        if role_name in target_invalid_roles:
            return set({})
        if target_visibility not in target_valid_visibilities:
            return set({})
        if target_ownership == 'for_owned':
            role_actions = role_policy[role_name]['allowed_actions_for_owned']
        else:
            role_actions = role_policy[role_name]['allowed_actions_for_other'][
                target_visibility]
        available_actions = role_actions.intersection(target_valid_actions)
        if debug:
            print('target role actions: %r' % role_actions)
            print('available actions for role: %r' % available_actions)
        return available_actions
    except Exception:
        return set({})
