Blame SOURCES/0188-lib-move-CREATE_PRIVATE_TICKET-to-the-global-configu.patch

2c83a8
From 8d8919987929cc5eb27e45dfc58f18b78dd0e484 Mon Sep 17 00:00:00 2001
2c83a8
From: Matej Habrnal <mhabrnal@redhat.com>
2c83a8
Date: Tue, 22 Mar 2016 15:15:43 +0100
2c83a8
Subject: [PATCH] lib: move CREATE_PRIVATE_TICKET to the global configuration
2c83a8
2c83a8
The plugins should not rely directly on the environment variables. This
2c83a8
patch should ensure that every one uses the same logic to interpret the
2c83a8
environment variables.
2c83a8
2c83a8
Related to rhbz#1279453
2c83a8
2c83a8
Signed-off-by: Jakub Filak <jfilak@redhat.com>
2c83a8
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
2c83a8
---
2c83a8
 src/gui-wizard-gtk/main.c          |  1 +
2c83a8
 src/gui-wizard-gtk/wizard.c        |  9 +----
2c83a8
 src/include/global_configuration.h | 15 +++++++++
2c83a8
 src/lib/global_configuration.c     | 22 +++++++++++++
2c83a8
 src/plugins/reporter-bugzilla.c    |  4 +--
2c83a8
 tests/global_config.at             | 67 ++++++++++++++++++++++++++++++++++++++
2c83a8
 6 files changed, 107 insertions(+), 11 deletions(-)
2c83a8
2c83a8
diff --git a/src/gui-wizard-gtk/main.c b/src/gui-wizard-gtk/main.c
2c83a8
index 41a8089..1a10258 100644
2c83a8
--- a/src/gui-wizard-gtk/main.c
2c83a8
+++ b/src/gui-wizard-gtk/main.c
2c83a8
@@ -186,6 +186,7 @@ int main(int argc, char **argv)
2c83a8
 
2c83a8
     g_dump_dir_name = xstrdup(argv[0]);
2c83a8
 
2c83a8
+    load_global_configuration();
2c83a8
     /* load /etc/abrt/events/foo.{conf,xml} stuff
2c83a8
        and $XDG_CACHE_HOME/abrt/events/foo.conf */
2c83a8
     g_event_config_list = load_event_config_data();
2c83a8
diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c
2c83a8
index 17257ec..6a1bdc0 100644
2c83a8
--- a/src/gui-wizard-gtk/wizard.c
2c83a8
+++ b/src/gui-wizard-gtk/wizard.c
2c83a8
@@ -2168,14 +2168,7 @@ static void add_warning(const char *warning)
2c83a8
 
2c83a8
 static void on_sensitive_ticket_clicked_cb(GtkWidget *button, gpointer user_data)
2c83a8
 {
2c83a8
-    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
2c83a8
-    {
2c83a8
-        xsetenv(CREATE_PRIVATE_TICKET, "1");
2c83a8
-    }
2c83a8
-    else
2c83a8
-    {
2c83a8
-        safe_unsetenv(CREATE_PRIVATE_TICKET);
2c83a8
-    }
2c83a8
+    set_global_create_private_ticket(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)), /*transient*/0);
2c83a8
 }
2c83a8
 
2c83a8
 static void on_privacy_info_btn(GtkWidget *button, gpointer user_data)
2c83a8
diff --git a/src/include/global_configuration.h b/src/include/global_configuration.h
2c83a8
index 9666796..bc5513d 100644
2c83a8
--- a/src/include/global_configuration.h
2c83a8
+++ b/src/include/global_configuration.h
2c83a8
@@ -38,6 +38,21 @@ void free_global_configuration(void);
2c83a8
 #define get_global_always_excluded_elements libreport_get_global_always_excluded_elements
2c83a8
 string_vector_ptr_t get_global_always_excluded_elements(void);
2c83a8
 
2c83a8
+#define get_global_create_private_ticket libreport_get_global_create_private_ticket
2c83a8
+bool get_global_create_private_ticket(void);
2c83a8
+
2c83a8
+/**
2c83a8
+ * Configures the create private ticket global option
2c83a8
+ *
2c83a8
+ * The function changes the configuration only for the current process by
2c83a8
+ * default.
2c83a8
+ *
2c83a8
+ * @param enabled The option's value
2c83a8
+ * @param flags For future needs (enable persistent configuration)
2c83a8
+ */
2c83a8
+#define set_global_create_private_ticket libreport_set_global_create_private_ticket
2c83a8
+void set_global_create_private_ticket(bool enabled, int flags);
2c83a8
+
2c83a8
 #ifdef __cplusplus
2c83a8
 }
2c83a8
 #endif
2c83a8
diff --git a/src/lib/global_configuration.c b/src/lib/global_configuration.c
2c83a8
index 903a2fb..ef921e9 100644
2c83a8
--- a/src/lib/global_configuration.c
2c83a8
+++ b/src/lib/global_configuration.c
2c83a8
@@ -141,3 +141,25 @@ string_vector_ptr_t get_global_always_excluded_elements(void)
2c83a8
 
2c83a8
     return ret;
2c83a8
 }
2c83a8
+
2c83a8
+bool get_global_create_private_ticket(void)
2c83a8
+{
2c83a8
+    assert_global_configuration_initialized();
2c83a8
+
2c83a8
+    char *env_create_private = getenv(CREATE_PRIVATE_TICKET);
2c83a8
+
2c83a8
+    if (env_create_private == NULL)
2c83a8
+        return false;
2c83a8
+
2c83a8
+    return string_to_bool(env_create_private);
2c83a8
+}
2c83a8
+
2c83a8
+void set_global_create_private_ticket(bool enabled, int flags/*unused - persistent*/)
2c83a8
+{
2c83a8
+    assert_global_configuration_initialized();
2c83a8
+
2c83a8
+    if (enabled)
2c83a8
+        xsetenv(CREATE_PRIVATE_TICKET, "1");
2c83a8
+    else
2c83a8
+        safe_unsetenv(CREATE_PRIVATE_TICKET);
2c83a8
+}
2c83a8
diff --git a/src/plugins/reporter-bugzilla.c b/src/plugins/reporter-bugzilla.c
2c83a8
index d11fadf..941c91f 100644
2c83a8
--- a/src/plugins/reporter-bugzilla.c
2c83a8
+++ b/src/plugins/reporter-bugzilla.c
2c83a8
@@ -740,9 +740,7 @@ static void set_settings(struct bugzilla_struct *b, map_string_t *settings)
2c83a8
     environ = getenv("Bugzilla_DontMatchComponents");
2c83a8
     b->b_DontMatchComponents = environ ? environ : get_map_string_item_or_empty(settings, "DontMatchComponents");
2c83a8
 
2c83a8
-    environ = getenv(CREATE_PRIVATE_TICKET);
2c83a8
-    if (environ)
2c83a8
-        b->b_create_private = string_to_bool(environ);
2c83a8
+    b->b_create_private = get_global_create_private_ticket();
2c83a8
 
2c83a8
     if (!b->b_create_private)
2c83a8
     {
2c83a8
diff --git a/tests/global_config.at b/tests/global_config.at
2c83a8
index a6f5423..05a0ffa 100644
2c83a8
--- a/tests/global_config.at
2c83a8
+++ b/tests/global_config.at
2c83a8
@@ -102,3 +102,70 @@ int main(int argc, char **argv)
2c83a8
     return EXIT_SUCCESS;
2c83a8
 }
2c83a8
 ]])
2c83a8
+
2c83a8
+## --------------------- ##
2c83a8
+## create_private_ticket ##
2c83a8
+## --------------------- ##
2c83a8
+
2c83a8
+AT_TESTFUN([create_private_ticket],
2c83a8
+[[
2c83a8
+#include "testsuite.h"
2c83a8
+
2c83a8
+TS_MAIN
2c83a8
+{
2c83a8
+    char cwd_buf[PATH_MAX + 1];
2c83a8
+    static const char *dirs[] = {
2c83a8
+        NULL,
2c83a8
+        NULL,
2c83a8
+    };
2c83a8
+    dirs[0] = getcwd(cwd_buf, sizeof(cwd_buf));
2c83a8
+
2c83a8
+    static int dir_flags[] = {
2c83a8
+        CONF_DIR_FLAG_NONE,
2c83a8
+        -1,
2c83a8
+    };
2c83a8
+
2c83a8
+    unlink("libreport.conf");
2c83a8
+    FILE *lrf = fopen("libreport.conf", "wx");
2c83a8
+    assert(lrf != NULL);
2c83a8
+    fclose(lrf);
2c83a8
+
2c83a8
+    assert(load_global_configuration_from_dirs(dirs, dir_flags));
2c83a8
+
2c83a8
+    TS_ASSERT_FALSE_MESSAGE(get_global_create_private_ticket(), "False by default");
2c83a8
+
2c83a8
+    set_global_create_private_ticket(false, 0);
2c83a8
+
2c83a8
+    TS_ASSERT_FALSE_MESSAGE(get_global_create_private_ticket(), "Still false");
2c83a8
+
2c83a8
+    set_global_create_private_ticket(true, 0);
2c83a8
+
2c83a8
+    TS_ASSERT_TRUE_MESSAGE(get_global_create_private_ticket(), "Configuration accepted");
2c83a8
+    TS_ASSERT_STRING_EQ(getenv(CREATE_PRIVATE_TICKET), "1", "Correct ENVIRONMENT value");
2c83a8
+
2c83a8
+    set_global_create_private_ticket(true, 0);
2c83a8
+
2c83a8
+    TS_ASSERT_TRUE_MESSAGE(get_global_create_private_ticket(), "Configuration sanity");
2c83a8
+    TS_ASSERT_STRING_EQ(getenv(CREATE_PRIVATE_TICKET), "1", "Correct ENVIRONMENT value");
2c83a8
+
2c83a8
+    set_global_create_private_ticket(false, 0);
2c83a8
+
2c83a8
+    TS_ASSERT_FALSE_MESSAGE(get_global_create_private_ticket(), "Reverted back to False");
2c83a8
+    TS_ASSERT_STRING_NULL_OR_EMPTY(getenv(CREATE_PRIVATE_TICKET), "Correct ENVIRONMENT value");
2c83a8
+
2c83a8
+    xsetenv(CREATE_PRIVATE_TICKET, "1");
2c83a8
+
2c83a8
+    TS_ASSERT_TRUE_MESSAGE(get_global_create_private_ticket(), "Loaded from environment");
2c83a8
+
2c83a8
+    unsetenv(CREATE_PRIVATE_TICKET);
2c83a8
+
2c83a8
+    TS_ASSERT_FALSE_MESSAGE(get_global_create_private_ticket(), "Reflects environment");
2c83a8
+
2c83a8
+    xsetenv(CREATE_PRIVATE_TICKET, "0");
2c83a8
+
2c83a8
+    TS_ASSERT_FALSE_MESSAGE(get_global_create_private_ticket(), "Zero is false");
2c83a8
+
2c83a8
+    free_global_configuration();
2c83a8
+}
2c83a8
+TS_RETURN_MAIN
2c83a8
+]])
2c83a8
-- 
2c83a8
1.8.3.1
2c83a8