Blob Blame History Raw
From 056aea2ac07d86d7cbade4814570f03c2e6cbec7 Mon Sep 17 00:00:00 2001
From: Matej Habrnal <mhabrnal@redhat.com>
Date: Tue, 22 Mar 2016 14:39:59 +0100
Subject: [PATCH] report-gtk: offer users to create private ticket

Make the feature public and offer it only in the cases where it make
sense (i.e. do not offer users to crate private ticket for
'report_Uploader').

Related to rhbz#1279453

Signed-off-by: Jakub Filak <jfilak@redhat.com>
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
---
 src/gui-wizard-gtk/wizard.c     | 109 ++++++++++++++++++++++++++++++++---
 src/gui-wizard-gtk/wizard.glade | 123 ----------------------------------------
 2 files changed, 102 insertions(+), 130 deletions(-)

diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c
index 3a7db9c..17257ec 100644
--- a/src/gui-wizard-gtk/wizard.c
+++ b/src/gui-wizard-gtk/wizard.c
@@ -124,6 +124,21 @@ static void add_workflow_buttons(GtkBox *box, GHashTable *workflows, GCallback f
 static void set_auto_event_chain(GtkButton *button, gpointer user_data);
 static void start_event_run(const char *event_name);
 
+static GtkWidget *g_sens_ticket;
+static GtkToggleButton *g_sens_ticket_cb;
+
+enum {
+    PRIV_WARN_SHOW_BTN      = 0x01,
+    PRIV_WARN_HIDE_BTN      = 0x02,
+    PRIV_WARN_SHOW_MSG      = 0x04,
+    PRIV_WARN_HIDE_MSG      = 0x08,
+    PRIV_WARN_BTN_CHECKED   = 0x10,
+    PRIV_WARN_BTN_UNCHECKED = 0x20,
+};
+
+static void private_ticket_creation_warning(int flags);
+static void update_private_ticket_creation_warning_for_selected_event(void);
+
 enum
 {
     /* Note: need to update types in
@@ -202,11 +217,13 @@ static const gchar *const page_names[] =
 #define PRIVATE_TICKET_CB "private_ticket_cb"
 
 #define SENSITIVE_DATA_WARN "sensitive_data_warning"
+#define SENSITIVE_DATA_WARN_MSG "sensitive_data_warning_message"
 #define SENSITIVE_LIST "ls_sensitive_words"
 static const gchar *misc_widgets[] =
 {
     SENSITIVE_DATA_WARN,
     SENSITIVE_LIST,
+    PRIVATE_TICKET_CB,
     NULL
 };
 
@@ -956,6 +973,7 @@ static int check_event_config(const char *event_name)
     {
         g_hash_table_unref(errors);
         show_event_opt_error_dialog(event_name);
+        update_private_ticket_creation_warning_for_selected_event();
         return 1;
     }
     return 0;
@@ -2160,17 +2178,52 @@ static void on_sensitive_ticket_clicked_cb(GtkWidget *button, gpointer user_data
     }
 }
 
-static void add_sensitive_data_warning(void)
+static void on_privacy_info_btn(GtkWidget *button, gpointer user_data)
+{
+    if (g_event_selected == NULL)
+        return;
+
+    show_event_config_dialog(g_event_selected, GTK_WINDOW(g_top_most_window));
+}
+
+static void private_ticket_creation_warning(int flags)
 {
-    GtkBuilder *builder = make_builder();
+    if (flags & PRIV_WARN_HIDE_BTN)
+    {
+        gtk_widget_hide(GTK_WIDGET(g_sens_ticket));
+    }
+
+    if (flags & PRIV_WARN_SHOW_BTN)
+    {
+        gtk_widget_show_all(GTK_WIDGET(g_sens_ticket));
+        gtk_widget_show(GTK_WIDGET(g_sens_ticket));
+    }
+
+    if (flags & PRIV_WARN_BTN_UNCHECKED)
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_sens_ticket_cb), FALSE);
+
+    if (flags & PRIV_WARN_BTN_CHECKED)
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_sens_ticket_cb), TRUE);
+
+    if (flags & PRIV_WARN_HIDE_MSG)
+        clear_warnings();
+
+    if (flags & PRIV_WARN_SHOW_MSG)
+    {
+       add_warning(_("Possible sensitive data detected, feel free to edit the report and remove them."));
+       show_warnings();
+    }
+}
 
-    GtkWidget *sens_data_warn = GTK_WIDGET(gtk_builder_get_object(builder, SENSITIVE_DATA_WARN));
-    GtkButton *sens_ticket_cb = GTK_BUTTON(gtk_builder_get_object(builder, PRIVATE_TICKET_CB));
+static void add_sensitive_data_warning(void)
+{
+    int flags = PRIV_WARN_SHOW_MSG;
 
-    g_signal_connect(sens_ticket_cb, "toggled", G_CALLBACK(on_sensitive_ticket_clicked_cb), NULL);
-    add_widget_to_warning_area(GTK_WIDGET(sens_data_warn));
+    event_config_t *cfg = get_event_config(g_event_selected);
+    if (cfg != NULL && cfg->ec_supports_restricted_access)
+        flags |= PRIV_WARN_SHOW_BTN | PRIV_WARN_BTN_CHECKED;
 
-    g_object_unref(builder);
+    private_ticket_creation_warning(flags);
 }
 
 static void show_warnings(void)
@@ -2627,6 +2680,19 @@ static char *get_next_processed_event(GList **events_list)
     return event_name;
 }
 
+static void update_private_ticket_creation_warning_for_selected_event(void)
+{
+    event_config_t *cfg = get_event_config(g_event_selected);
+    if (cfg == NULL || !cfg->ec_supports_restricted_access)
+        return;
+
+    int flags = PRIV_WARN_SHOW_BTN | PRIV_WARN_HIDE_MSG;
+    if (ec_restricted_access_enabled(cfg))
+        flags |= PRIV_WARN_BTN_CHECKED;
+
+    private_ticket_creation_warning(flags);
+}
+
 static void on_page_prepare(GtkNotebook *assistant, GtkWidget *page, gpointer user_data)
 {
     //int page_no = gtk_assistant_get_current_page(g_assistant);
@@ -2669,6 +2735,11 @@ static void on_page_prepare(GtkNotebook *assistant, GtkWidget *page, gpointer us
 
     if (pages[PAGENO_SUMMARY].page_widget == page)
     {
+        if (get_global_create_private_ticket())
+            private_ticket_creation_warning(  PRIV_WARN_SHOW_BTN
+                                            | PRIV_WARN_BTN_CHECKED
+                                            | PRIV_WARN_HIDE_MSG);
+
         if (!g_expert_mode)
         {
             /* Skip intro screen */
@@ -2718,6 +2789,8 @@ static void on_page_prepare(GtkNotebook *assistant, GtkWidget *page, gpointer us
 
     if (pages[PAGENO_EDIT_COMMENT].page_widget == page)
     {
+        update_private_ticket_creation_warning_for_selected_event();
+
         gtk_widget_set_sensitive(g_btn_next, false);
         on_comment_changed(gtk_text_view_get_buffer(g_tv_comment), NULL);
     }
@@ -3527,6 +3600,28 @@ void create_assistant(GtkApplication *app, bool expert_mode)
     gtk_box_pack_start(g_box_assistant, GTK_WIDGET(g_assistant), true, true, 0);
 
     gtk_box_pack_start(g_box_assistant, GTK_WIDGET(g_widget_warnings_area), false, false, 0);
+
+    /* Private ticket warning */
+    {
+        g_sens_ticket = GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0));
+        gtk_widget_set_no_show_all(GTK_WIDGET(g_sens_ticket), TRUE);
+        gtk_widget_hide(GTK_WIDGET(g_sens_ticket));
+
+        g_sens_ticket_cb = GTK_TOGGLE_BUTTON(gtk_check_button_new_with_label(_("Restrict access to the report")));
+        gtk_widget_set_margin_start(GTK_WIDGET(g_sens_ticket_cb), 5);
+        gtk_widget_show(GTK_WIDGET(g_sens_ticket_cb));
+        g_signal_connect(g_sens_ticket_cb, "toggled", G_CALLBACK(on_sensitive_ticket_clicked_cb), NULL);
+
+        GtkLinkButton *privacy_info_btn = GTK_LINK_BUTTON(gtk_link_button_new_with_label("", _("Learn more about restricted access in the configuration")));
+        gtk_widget_show(GTK_WIDGET(privacy_info_btn));
+        g_signal_connect(privacy_info_btn, "clicked", G_CALLBACK(on_privacy_info_btn), NULL);
+
+        gtk_box_pack_start(GTK_BOX(g_sens_ticket), GTK_WIDGET(g_sens_ticket_cb), false, false, 5);
+        gtk_box_pack_start(GTK_BOX(g_sens_ticket), GTK_WIDGET(privacy_info_btn), false, false, 5);
+
+        gtk_box_pack_start(g_box_assistant, GTK_WIDGET(g_sens_ticket), false, true, 5);
+    }
+
     gtk_box_pack_start(g_box_assistant, GTK_WIDGET(g_box_buttons), false, false, 5);
 
     gtk_widget_show_all(GTK_WIDGET(g_box_buttons));
diff --git a/src/gui-wizard-gtk/wizard.glade b/src/gui-wizard-gtk/wizard.glade
index 9296bca..441b2fc 100644
--- a/src/gui-wizard-gtk/wizard.glade
+++ b/src/gui-wizard-gtk/wizard.glade
@@ -16,129 +16,6 @@
       <column type="gpointer"/>
     </columns>
   </object>
-  <object class="GtkWindow" id="sensitiveDataWarning_w">
-    <property name="can_focus">False</property>
-    <child>
-      <object class="GtkBox" id="sensitive_data_warning">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="orientation">vertical</property>
-        <child>
-          <object class="GtkBox" id="box5">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <child>
-              <object class="GtkImage" id="image2">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="margin_left">4</property>
-                <property name="stock">gtk-media-record</property>
-                <property name="icon-size">1</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel" id="label10">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="margin_left">6</property>
-                <property name="margin_top">3</property>
-                <property name="margin_bottom">3</property>
-                <property name="label" translatable="yes">Possible sensitive data detected, feel free to edit the report and remove them.</property>
-                <attributes>
-                  <attribute name="weight" value="bold"/>
-                </attributes>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkBox" id="box6">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <child>
-              <object class="GtkBox" id="box4">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="orientation">vertical</property>
-                <child>
-                  <object class="GtkCheckButton" id="private_ticket_cb">
-                    <property name="label" translatable="yes">Restrict access to the report</property>
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">False</property>
-                    <property name="xalign">0</property>
-                    <property name="draw_indicator">True</property>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkLabel" id="label11">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="margin_top">13</property>
-                    <property name="label" translatable="yes">No one except Red Hat employees will be allowed to see the report with restricted access (not even you)</property>
-                    <attributes>
-                      <attribute name="style" value="italic"/>
-                    </attributes>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkLinkButton" id="linkbutton1">
-                    <property name="label" translatable="yes">Read more about reports with restricted access</property>
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <property name="has_tooltip">True</property>
-                    <property name="relief">none</property>
-                    <property name="uri">https://github.com/abrt/abrt/wiki/FAQ#reports-with-restricted-access</property>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">2</property>
-                  </packing>
-                </child>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">1</property>
-          </packing>
-        </child>
-      </object>
-    </child>
-  </object>
   <object class="GtkWindow" id="window0">
     <property name="can_focus">False</property>
     <child>
-- 
1.8.3.1