Blame SOURCES/0190-bugzilla-don-t-report-private-problem-as-comment.patch

4b6aa8
From 6e11121e7ec10cd63e6bbaa8e996b883e9fe1ac2 Mon Sep 17 00:00:00 2001
4b6aa8
From: Matej Habrnal <mhabrnal@redhat.com>
4b6aa8
Date: Wed, 23 Mar 2016 17:11:56 +0100
4b6aa8
Subject: [PATCH] bugzilla: don't report private problem as comment
4b6aa8
4b6aa8
Before this patch reporter-bugzilla ignored the Private report request
4b6aa8
and added a public comment to a duplicate bug because it was assumed
4b6aa8
that the duplicate comment cannot contain anything security sensitive.
4b6aa8
4b6aa8
There are two problems with it. The assumption is invalid because the
4b6aa8
comment contains all one-line files including 'cmdline' and the reporter
4b6aa8
might added something private to the bug description.
4b6aa8
4b6aa8
Bugzilla comments can be made private but not all users have rights to
4b6aa8
do so. On the contrary, all users can set a group to a bug report.
4b6aa8
Hence, this commit teaches reporter-bugzilla to ask the user if he/she
4b6aa8
wants to open a new, private bug report and immediately close it as a
4b6aa8
duplicate of the original or terminate the reporting. The tool will ask
4b6aa8
the question only if the users wants to open a private report and a
4b6aa8
duplicate bug report is found.
4b6aa8
4b6aa8
Resolves: #1279453
4b6aa8
4b6aa8
Signed-off-by: Jakub Filak <jfilak@redhat.com>
4b6aa8
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
4b6aa8
---
4b6aa8
 src/plugins/reporter-bugzilla.c | 44 +++++++++++++++++++++++++++++++++++++++--
4b6aa8
 src/plugins/rhbz.c              | 23 +++++++++++++++++++++
4b6aa8
 src/plugins/rhbz.h              |  4 ++++
4b6aa8
 3 files changed, 69 insertions(+), 2 deletions(-)
4b6aa8
4b6aa8
diff --git a/src/plugins/reporter-bugzilla.c b/src/plugins/reporter-bugzilla.c
4b6aa8
index 941c91f..fbe7873 100644
4b6aa8
--- a/src/plugins/reporter-bugzilla.c
4b6aa8
+++ b/src/plugins/reporter-bugzilla.c
4b6aa8
@@ -907,6 +907,7 @@ int main(int argc, char **argv)
4b6aa8
     unsigned opts = parse_opts(argc, argv, program_options, program_usage_string);
4b6aa8
     argv += optind;
4b6aa8
 
4b6aa8
+    load_global_configuration();
4b6aa8
     export_abrt_envvars(0);
4b6aa8
 
4b6aa8
     map_string_t *settings = new_map_string();
4b6aa8
@@ -928,6 +929,8 @@ int main(int argc, char **argv)
4b6aa8
          */
4b6aa8
         /*free_map_string(settings);*/
4b6aa8
     }
4b6aa8
+    /* either we got Bugzilla_CreatePrivate from settings or -g was specified on cmdline */
4b6aa8
+    rhbz.b_create_private |= (opts & OPT_g);
4b6aa8
 
4b6aa8
     log_notice("Initializing XML-RPC library");
4b6aa8
     xmlrpc_env env;
4b6aa8
@@ -1189,8 +1192,38 @@ int main(int argc, char **argv)
4b6aa8
             }
4b6aa8
         }
4b6aa8
 
4b6aa8
-        if (existing_id < 0)
4b6aa8
+        if (existing_id < 0 || rhbz.b_create_private)
4b6aa8
         {
4b6aa8
+
4b6aa8
+            if (existing_id >= 0)
4b6aa8
+            {
4b6aa8
+                char *msg = xasprintf(_(
4b6aa8
+                "You have requested to make your data accessible only to a "
4b6aa8
+                "specific group and this bug is a duplicate of bug: "
4b6aa8
+                "%s/%u"
4b6aa8
+                " "
4b6aa8
+                "In case of bug duplicates a new comment is added to the "
4b6aa8
+                "original bug report but access to the comments cannot be "
4b6aa8
+                "restricted to a specific group."
4b6aa8
+                " "
4b6aa8
+                "Would you like to open a new bug report and close it as "
4b6aa8
+                "DUPLICATE of the original one?"
4b6aa8
+                " "
4b6aa8
+                "Otherwise, the bug reporting procedure will be terminated."),
4b6aa8
+                rhbz.b_bugzilla_url, existing_id);
4b6aa8
+
4b6aa8
+                int r = ask_yes_no(msg);
4b6aa8
+                free(msg);
4b6aa8
+
4b6aa8
+                if (r == 0)
4b6aa8
+                {
4b6aa8
+                    log(_("Logging out"));
4b6aa8
+                    rhbz_logout(client);
4b6aa8
+
4b6aa8
+                    exit(EXIT_CANCEL_BY_USER);
4b6aa8
+                }
4b6aa8
+            }
4b6aa8
+
4b6aa8
             /* Create new bug */
4b6aa8
             log(_("Creating a new bug"));
4b6aa8
 
4b6aa8
@@ -1205,7 +1238,7 @@ int main(int argc, char **argv)
4b6aa8
             int new_id = rhbz_new_bug(client,
4b6aa8
                     problem_data, rhbz.b_product, rhbz.b_product_version,
4b6aa8
                     summary, bzcomment,
4b6aa8
-                    (rhbz.b_create_private | (opts & OPT_g)), // either we got Bugzilla_CreatePrivate from settings or -g was specified on cmdline
4b6aa8
+                    rhbz.b_create_private,
4b6aa8
                     rhbz.b_private_groups
4b6aa8
                     );
4b6aa8
             free(bzcomment);
4b6aa8
@@ -1241,6 +1274,13 @@ int main(int argc, char **argv)
4b6aa8
             bz = new_bug_info();
4b6aa8
             bz->bi_status = xstrdup("NEW");
4b6aa8
             bz->bi_id = new_id;
4b6aa8
+
4b6aa8
+            if (existing_id >= 0)
4b6aa8
+            {
4b6aa8
+                log(_("Closing bug %i as duplicate of bug %i"), new_id, existing_id);
4b6aa8
+                rhbz_close_as_duplicate(client, new_id, existing_id, RHBZ_NOMAIL_NOTIFY);
4b6aa8
+            }
4b6aa8
+
4b6aa8
             goto log_out;
4b6aa8
         }
4b6aa8
 
4b6aa8
diff --git a/src/plugins/rhbz.c b/src/plugins/rhbz.c
4b6aa8
index bad9ed4..a227c62 100644
4b6aa8
--- a/src/plugins/rhbz.c
4b6aa8
+++ b/src/plugins/rhbz.c
4b6aa8
@@ -862,6 +862,29 @@ void rhbz_set_url(struct abrt_xmlrpc *ax, int bug_id, const char *url, int flags
4b6aa8
         xmlrpc_DECREF(result);
4b6aa8
 }
4b6aa8
 
4b6aa8
+void rhbz_close_as_duplicate(struct abrt_xmlrpc *ax, int bug_id,
4b6aa8
+                        int duplicate_bug,
4b6aa8
+                        int flags)
4b6aa8
+{
4b6aa8
+    func_entry();
4b6aa8
+
4b6aa8
+    const int nomail_notify = !!IS_NOMAIL_NOTIFY(flags);
4b6aa8
+    xmlrpc_value *result = abrt_xmlrpc_call(ax, "Bug.update", "{s:i,s:s,s:s,s:i,s:i}",
4b6aa8
+                              "ids", bug_id,
4b6aa8
+                              "status", "CLOSED",
4b6aa8
+                              "resolution", "DUPLICATE",
4b6aa8
+                              "dupe_of", duplicate_bug,
4b6aa8
+
4b6aa8
+                /* Undocumented argument but it works with Red Hat Bugzilla version 4.2.4-7
4b6aa8
+                 * and version 4.4.rc1.b02
4b6aa8
+                 */
4b6aa8
+                              "nomail", nomail_notify
4b6aa8
+    );
4b6aa8
+
4b6aa8
+    if (result)
4b6aa8
+        xmlrpc_DECREF(result);
4b6aa8
+}
4b6aa8
+
4b6aa8
 xmlrpc_value *rhbz_search_duphash(struct abrt_xmlrpc *ax,
4b6aa8
                         const char *product,
4b6aa8
                         const char *version,
4b6aa8
diff --git a/src/plugins/rhbz.h b/src/plugins/rhbz.h
4b6aa8
index 976d333..15e7699 100644
4b6aa8
--- a/src/plugins/rhbz.h
4b6aa8
+++ b/src/plugins/rhbz.h
4b6aa8
@@ -74,6 +74,10 @@ void rhbz_add_comment(struct abrt_xmlrpc *ax, int bug_id, const char *comment,
4b6aa8
 
4b6aa8
 void rhbz_set_url(struct abrt_xmlrpc *ax, int bug_id, const char *url, int flags);
4b6aa8
 
4b6aa8
+void rhbz_close_as_duplicate(struct abrt_xmlrpc *ax, int bug_id,
4b6aa8
+                             int duplicate_bug,
4b6aa8
+                             int flags);
4b6aa8
+
4b6aa8
 void *rhbz_bug_read_item(const char *memb, xmlrpc_value *xml, int flags);
4b6aa8
 
4b6aa8
 void rhbz_logout(struct abrt_xmlrpc *ax);
4b6aa8
-- 
4b6aa8
1.8.3.1
4b6aa8