Blame SOURCES/0026-cli-list-show-a-hint-about-creating-a-case-in-RHTS.patch

e0b939
From 16b6963ef5e37805d2587684f90d2c6d5dd4ffdc Mon Sep 17 00:00:00 2001
e0b939
From: Jakub Filak <jfilak@redhat.com>
e0b939
Date: Thu, 6 Dec 2018 17:57:59 +0100
e0b939
Subject: [PATCH] cli list: show a hint about creating a case in RHTS
e0b939
e0b939
Adds "Run 'abrt-cli report ...' for creating a case in Red Hat Customer Portal" to
e0b939
abrt-cli list output.
e0b939
e0b939
Resolves: #1649753
e0b939
e0b939
(cherry-picked from 7966e5737e8d3af43b1ecdd6a823234b8d25931d)
e0b939
e0b939
Signed-off-by: Jakub Filak <jfilak@redhat.com>
e0b939
---
e0b939
 configure.ac        |  2 ++
e0b939
 src/cli/Makefile.am |  3 ++-
e0b939
 src/cli/list.c      | 49 +++++++++++++++++++++++++++++++++++++++++++++
e0b939
 3 files changed, 53 insertions(+), 1 deletion(-)
e0b939
e0b939
diff --git a/configure.ac b/configure.ac
e0b939
index 76e0f274b..5d70bb9a8 100644
e0b939
--- a/configure.ac
e0b939
+++ b/configure.ac
e0b939
@@ -246,6 +246,7 @@ DEFAULT_PLUGINS_CONF_DIR='${datadir}/${PACKAGE_NAME}/conf.d/plugins'
e0b939
 EVENTS_DIR='${datadir}/libreport/events'
e0b939
 EVENTS_CONF_DIR='${sysconfdir}/libreport/events.d'
e0b939
 JOURNAL_CATALOG_DIR='$(prefix)/lib/systemd/catalog'
e0b939
+WORKFLOWS_DIR='${datadir}/libreport/workflows'
e0b939
 ENABLE_SOCKET_OR_DBUS='-DENABLE_DBUS=1'
e0b939
 DEFAULT_DUMP_LOCATION_MODE=0751
e0b939
 DEFAULT_DUMP_DIR_MODE=$($PKG_CONFIG --variable=dd_mode libreport)
e0b939
@@ -389,6 +390,7 @@ AC_SUBST(PLUGINS_CONF_DIR)
e0b939
 AC_SUBST(DEFAULT_PLUGINS_CONF_DIR)
e0b939
 AC_SUBST(EVENTS_CONF_DIR)
e0b939
 AC_SUBST(JOURNAL_CATALOG_DIR)
e0b939
+AC_SUBST(WORKFLOWS_DIR)
e0b939
 AC_SUBST(EVENTS_DIR)
e0b939
 AC_SUBST(DEFAULT_DUMP_LOCATION)
e0b939
 AC_SUBST(DEFAULT_DUMP_LOCATION_MODE)
e0b939
diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
e0b939
index 92dc20ab4..a7c76efa3 100644
e0b939
--- a/src/cli/Makefile.am
e0b939
+++ b/src/cli/Makefile.am
e0b939
@@ -17,7 +17,8 @@ abrt_cli_CFLAGS = \
e0b939
 	-I$(srcdir)/../include \
e0b939
 	-I$(srcdir)/../lib \
e0b939
 	$(LIBREPORT_CFLAGS) \
e0b939
-	$(POLKIT_AGENT_CFLAGS)
e0b939
+	$(POLKIT_AGENT_CFLAGS) \
e0b939
+	-DWORKFLOWS_DIR=\"${WORKFLOWS_DIR}\"
e0b939
 
e0b939
 if SUGGEST_AUTOREPORTING
e0b939
 abrt_cli_CFLAGS += -DSUGGEST_AUTOREPORTING=1
e0b939
diff --git a/src/cli/list.c b/src/cli/list.c
e0b939
index d069695c6..2c140cb38 100644
e0b939
--- a/src/cli/list.c
e0b939
+++ b/src/cli/list.c
e0b939
@@ -77,6 +77,55 @@ static void print_crash(problem_data_t *problem_data, int detailed, int text_siz
e0b939
                             /*names_to_skip:*/ NULL,
e0b939
                             /*max_text_size:*/ text_size,
e0b939
                             MAKEDESC_SHOW_ONLY_LIST | MAKEDESC_SHOW_URLS);
e0b939
+
e0b939
+        /*
e0b939
+         * If the problem is reportable and has not yet been reported into RHTS
e0b939
+         * and there is at least one applicable Workflow which contains
e0b939
+         * 'report_RHTSupport' event, then append a short message informing
e0b939
+         * user that he can create a new case in Red Hat Customer Portal.
e0b939
+         */
e0b939
+        const char *const not_reportable =  problem_data_get_content_or_NULL(problem_data, FILENAME_NOT_REPORTABLE);
e0b939
+        const char *const reported_to    =  not_reportable            ? NULL : problem_data_get_content_or_NULL(problem_data, FILENAME_REPORTED_TO);
e0b939
+        report_result_t *const report    = !reported_to               ? NULL : find_in_reported_to_data(reported_to, "RHTSupport");
e0b939
+
e0b939
+        if (!not_reportable && !report)
e0b939
+        {
e0b939
+            /* The lines below should be replaced by something simpler, I'd
e0b939
+             * like to see:
e0b939
+             * GHashTable *possible_worfklows = load_applicable_workflows_for_dump();
e0b939
+             *
e0b939
+             * However, this feature (rhbz#1055565) is intended for RHEL only
e0b939
+             * and I'm not sure whether it's worth to file another bug against
e0b939
+             * libreport and try to improve libreport public API.
e0b939
+             */
e0b939
+            const char *const dump_dir_name = problem_data_get_content_or_NULL(problem_data, CD_DUMPDIR);
e0b939
+            GList *const wf_names = list_possible_events_glist(dump_dir_name, "workflow");
e0b939
+            GHashTable *const possible_workflows = load_workflow_config_data_from_list(wf_names, WORKFLOWS_DIR);
e0b939
+            g_list_free_full(wf_names, free);
e0b939
+
e0b939
+            int event_found = 0;
e0b939
+
e0b939
+            GHashTableIter iter;
e0b939
+            gpointer key = NULL;
e0b939
+            gpointer value = NULL;
e0b939
+
e0b939
+            g_hash_table_iter_init(&iter, possible_workflows);
e0b939
+            while (!event_found && g_hash_table_iter_next(&iter, &key, &value))
e0b939
+            {
e0b939
+                GList *const event_names = wf_get_event_names((workflow_t *)value);
e0b939
+                event_found = !!g_list_find_custom(event_names, "report_RHTSupport", (GCompareFunc)g_strcmp0);
e0b939
+                g_list_free_full(event_names, free);
e0b939
+            }
e0b939
+
e0b939
+            g_hash_table_destroy(possible_workflows);
e0b939
+
e0b939
+            if (event_found)
e0b939
+            {
e0b939
+                char *tmp = xasprintf("%sRun 'abrt-cli report %s' for creating a case in Red Hat Customer Portal\n", desc, dump_dir_name);
e0b939
+                free(desc);
e0b939
+                desc = tmp;
e0b939
+            }
e0b939
+        }
e0b939
     }
e0b939
     fputs(desc, stdout);
e0b939
     free(desc);
e0b939
-- 
e0b939
2.17.2
e0b939