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

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