Blame SOURCES/0187-event-config-add-support-for-restricted-access.patch

4b6aa8
From 4d4ddb1005eda2a9ecf49f23d973d784bf6460de Mon Sep 17 00:00:00 2001
4b6aa8
From: Matej Habrnal <mhabrnal@redhat.com>
4b6aa8
Date: Tue, 22 Mar 2016 15:07:15 +0100
4b6aa8
Subject: [PATCH] event config: add support for 'restricted access'
4b6aa8
4b6aa8
The xml event definition must hold the information about availability of
4b6aa8
creating tickets with restricted access.
4b6aa8
4b6aa8
The tools like report-gtk and report-cli must use this information to:
4b6aa8
- offer the users the possibility to open the report with restricted access
4b6aa8
- tell the users whether the ticket will be private or not based on the
4b6aa8
  configuration of the event
4b6aa8
4b6aa8
Signed-off-by: Jakub Filak <jfilak@redhat.com>
4b6aa8
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
4b6aa8
---
4b6aa8
 doc/report_event.conf.txt                          | 10 ++++
4b6aa8
 src/include/event_config.h                         |  7 +++
4b6aa8
 src/lib/event_config.c                             | 34 ++++++++++++
4b6aa8
 src/lib/event_xml_parser.c                         | 20 ++++++++
4b6aa8
 tests/Makefile.am                                  |  3 +-
4b6aa8
 .../conf/event_implicit_no_support_restricted.xml  | 13 +++++
4b6aa8
 tests/conf/event_no_support_restricted.xml         | 15 ++++++
4b6aa8
 tests/conf/event_support_restricted_no_option.xml  | 15 ++++++
4b6aa8
 .../conf/event_support_restricted_with_option.xml  | 15 ++++++
4b6aa8
 tests/event_config.at                              | 60 ++++++++++++++++++++++
4b6aa8
 tests/testsuite.at                                 |  1 +
4b6aa8
 tests/xml_definition.at                            | 51 ++++++++++++++++++
4b6aa8
 12 files changed, 243 insertions(+), 1 deletion(-)
4b6aa8
 create mode 100644 tests/conf/event_implicit_no_support_restricted.xml
4b6aa8
 create mode 100644 tests/conf/event_no_support_restricted.xml
4b6aa8
 create mode 100644 tests/conf/event_support_restricted_no_option.xml
4b6aa8
 create mode 100644 tests/conf/event_support_restricted_with_option.xml
4b6aa8
 create mode 100644 tests/event_config.at
4b6aa8
4b6aa8
diff --git a/doc/report_event.conf.txt b/doc/report_event.conf.txt
4b6aa8
index 887c3e8..c7e736e 100644
4b6aa8
--- a/doc/report_event.conf.txt
4b6aa8
+++ b/doc/report_event.conf.txt
4b6aa8
@@ -71,6 +71,8 @@ Each file has XML formatting with the following DTD:
4b6aa8
 
4b6aa8
 
4b6aa8
 
4b6aa8
+
4b6aa8
+
4b6aa8
 
4b6aa8
 
4b6aa8
 
4b6aa8
@@ -117,6 +119,14 @@ gui-review-elements::
4b6aa8
     can be published. If "no", the event is executed automatically. If not
4b6aa8
     provided, "yes" is expected.
4b6aa8
 
4b6aa8
+support-restricted-access::
4b6aa8
+    If "yes", the UI tools will offer the users to enter the new report with
4b6aa8
+    restricted access. If "no", the UI tools will never offer the users to
4b6aa8
+    enter the report with restricted access. "no" is the default value. The
4b6aa8
+    element should have one argument named 'optionname' which defines name of
4b6aa8
+    an option holding configuration of the restricted access feature. The
4b6aa8
+    option must of 'bool' type.
4b6aa8
+
4b6aa8
 advanced-options::
4b6aa8
     List of options which are hidden in the default view.
4b6aa8
 
4b6aa8
diff --git a/src/include/event_config.h b/src/include/event_config.h
4b6aa8
index e2fcc23..7d137c1 100644
4b6aa8
--- a/src/include/event_config.h
4b6aa8
+++ b/src/include/event_config.h
4b6aa8
@@ -80,6 +80,8 @@ typedef struct
4b6aa8
     long  ec_minimal_rating;
4b6aa8
     bool  ec_skip_review;
4b6aa8
     bool  ec_sending_sensitive_data;
4b6aa8
+    bool  ec_supports_restricted_access;
4b6aa8
+    char *ec_restricted_access_option;
4b6aa8
 
4b6aa8
     GList *ec_imported_event_names;
4b6aa8
     GList *options;
4b6aa8
@@ -98,6 +100,11 @@ const char *ec_get_long_desc(event_config_t *ec);
4b6aa8
 void ec_set_long_desc(event_config_t *ec, const char *long_desc);
4b6aa8
 bool ec_is_configurable(event_config_t* ec);
4b6aa8
 
4b6aa8
+/* Returns True if the event is configured to create ticket with restricted
4b6aa8
+ * access.
4b6aa8
+ */
4b6aa8
+bool ec_restricted_access_enabled(event_config_t *ec);
4b6aa8
+
4b6aa8
 void free_event_config(event_config_t *p);
4b6aa8
 
4b6aa8
 
4b6aa8
diff --git a/src/lib/event_config.c b/src/lib/event_config.c
4b6aa8
index 30b94d3..4155938 100644
4b6aa8
--- a/src/lib/event_config.c
4b6aa8
+++ b/src/lib/event_config.c
4b6aa8
@@ -88,6 +88,39 @@ void ec_print(event_config_t *ec)
4b6aa8
         );
4b6aa8
 }
4b6aa8
 
4b6aa8
+bool ec_restricted_access_enabled(event_config_t *ec)
4b6aa8
+{
4b6aa8
+    if (!ec->ec_supports_restricted_access)
4b6aa8
+    {
4b6aa8
+        if (ec->ec_restricted_access_option != NULL)
4b6aa8
+            log_warning("Event '%s' does not support restricted access but has the option", ec_get_name(ec));
4b6aa8
+
4b6aa8
+        return false;
4b6aa8
+    }
4b6aa8
+
4b6aa8
+    if (ec->ec_restricted_access_option == NULL)
4b6aa8
+    {
4b6aa8
+        log_debug("Event '%s' supports restricted access but is missing the option", ec_get_name(ec));
4b6aa8
+        return false;
4b6aa8
+    }
4b6aa8
+
4b6aa8
+    event_option_t *eo = get_event_option_from_list(ec->ec_restricted_access_option, ec->options);
4b6aa8
+    if (eo == NULL)
4b6aa8
+    {
4b6aa8
+        log_warning("Event '%s' supports restricted access but the option is not defined", ec_get_name(ec));
4b6aa8
+        return false;
4b6aa8
+    }
4b6aa8
+
4b6aa8
+    if (eo->eo_type != OPTION_TYPE_BOOL)
4b6aa8
+    {
4b6aa8
+        log_warning("Restricted option '%s' of Event '%s' is not of 'bool' type",
4b6aa8
+                    ec->ec_restricted_access_option, ec_get_name(ec));
4b6aa8
+        return false;
4b6aa8
+    }
4b6aa8
+
4b6aa8
+    return eo->eo_value != NULL && string_to_bool(eo->eo_value);
4b6aa8
+}
4b6aa8
+
4b6aa8
 void free_event_option(event_option_t *p)
4b6aa8
 {
4b6aa8
     if (!p)
4b6aa8
@@ -112,6 +145,7 @@ void free_event_config(event_config_t *p)
4b6aa8
     free(p->ec_exclude_items_by_default);
4b6aa8
     free(p->ec_include_items_by_default);
4b6aa8
     free(p->ec_exclude_items_always);
4b6aa8
+    free(p->ec_restricted_access_option);
4b6aa8
     g_list_free_full(p->ec_imported_event_names, free);
4b6aa8
     g_list_free_full(p->options, (GDestroyNotify)free_event_option);
4b6aa8
 
4b6aa8
diff --git a/src/lib/event_xml_parser.c b/src/lib/event_xml_parser.c
4b6aa8
index a15f1e1..a5e3d3e 100644
4b6aa8
--- a/src/lib/event_xml_parser.c
4b6aa8
+++ b/src/lib/event_xml_parser.c
4b6aa8
@@ -33,6 +33,8 @@
4b6aa8
 #define MINIMAL_RATING_ELEMENT  "minimal-rating"
4b6aa8
 #define GUI_REVIEW_ELEMENTS     "gui-review-elements"
4b6aa8
 #define SENDING_SENSITIVE_DATA_ELEMENT  "sending-sensitive-data"
4b6aa8
+#define SUPPORTS_RESTRICTED_ACCESS_ELEMENT "support-restricted-access"
4b6aa8
+#define RESTRICTED_ACCESS_OPTION_ATTR "optionname"
4b6aa8
 
4b6aa8
 #define REQUIRES_ELEMENT        "requires-items"
4b6aa8
 #define EXCL_BY_DEFAULT_ELEMENT "exclude-items-by-default"
4b6aa8
@@ -234,6 +236,20 @@ static void start_element(GMarkupParseContext *context,
4b6aa8
         free(parse_data->attribute_lang);
4b6aa8
         parse_data->attribute_lang = get_element_lang(parse_data, attribute_names, attribute_values);
4b6aa8
     }
4b6aa8
+    else
4b6aa8
+    if (strcmp(element_name, SUPPORTS_RESTRICTED_ACCESS_ELEMENT) == 0)
4b6aa8
+    {
4b6aa8
+        if ((     attribute_names[0] != NULL
4b6aa8
+               && strcmp(attribute_names[0], RESTRICTED_ACCESS_OPTION_ATTR) != 0)
4b6aa8
+            || attribute_names[1] != NULL)
4b6aa8
+        {
4b6aa8
+            error_msg("XML event configuration error: '%s' element misses attribute '%s'",
4b6aa8
+                    SUPPORTS_RESTRICTED_ACCESS_ELEMENT, RESTRICTED_ACCESS_OPTION_ATTR);
4b6aa8
+            return;
4b6aa8
+        }
4b6aa8
+
4b6aa8
+        parse_data->event_config.values->ec_restricted_access_option = xstrdup(attribute_values[0]);
4b6aa8
+    }
4b6aa8
 }
4b6aa8
 
4b6aa8
 // Called for close tags </foo>
4b6aa8
@@ -489,6 +505,10 @@ static void text(GMarkupParseContext *context,
4b6aa8
         {
4b6aa8
             ui->ec_sending_sensitive_data = string_to_bool(text_copy);
4b6aa8
         }
4b6aa8
+        else if (strcmp(inner_element, SUPPORTS_RESTRICTED_ACCESS_ELEMENT) == 0)
4b6aa8
+        {
4b6aa8
+            ui->ec_supports_restricted_access = string_to_bool(text_copy);
4b6aa8
+        }
4b6aa8
     }
4b6aa8
     free(text_copy);
4b6aa8
 }
4b6aa8
diff --git a/tests/Makefile.am b/tests/Makefile.am
4b6aa8
index 825a870..9aa3a07 100644
4b6aa8
--- a/tests/Makefile.am
4b6aa8
+++ b/tests/Makefile.am
4b6aa8
@@ -46,7 +46,8 @@ TESTSUITE_AT = \
4b6aa8
   dump_dir.at \
4b6aa8
   global_config.at \
4b6aa8
   iso_date.at \
4b6aa8
-  uriparser.at
4b6aa8
+  uriparser.at \
4b6aa8
+  event_config.at
4b6aa8
 
4b6aa8
 TESTSUITE_AT_IN = \
4b6aa8
   bugzilla_plugin.at
4b6aa8
diff --git a/tests/conf/event_implicit_no_support_restricted.xml b/tests/conf/event_implicit_no_support_restricted.xml
4b6aa8
new file mode 100644
4b6aa8
index 0000000..eb37be8
4b6aa8
--- /dev/null
4b6aa8
+++ b/tests/conf/event_implicit_no_support_restricted.xml
4b6aa8
@@ -0,0 +1,13 @@
4b6aa8
+
4b6aa8
+<event>
4b6aa8
+    <name>Bugzilla</name>
4b6aa8
+    <description>Report to Bugzilla bug tracker</description>
4b6aa8
+    <long-description>Report to Bugzilla bug tracker in long description</long-description>
4b6aa8
+
4b6aa8
+    <options>
4b6aa8
+        <option type="text" name="Bugzilla_BugzillaURL">
4b6aa8
+            <label>Bugzilla URL</label>
4b6aa8
+            <note-html>Bugzilla HTML note</note-html>
4b6aa8
+        </option>
4b6aa8
+    </options>
4b6aa8
+</event>
4b6aa8
diff --git a/tests/conf/event_no_support_restricted.xml b/tests/conf/event_no_support_restricted.xml
4b6aa8
new file mode 100644
4b6aa8
index 0000000..b2c83b1
4b6aa8
--- /dev/null
4b6aa8
+++ b/tests/conf/event_no_support_restricted.xml
4b6aa8
@@ -0,0 +1,15 @@
4b6aa8
+
4b6aa8
+<event>
4b6aa8
+    <name>Bugzilla</name>
4b6aa8
+    <description>Report to Bugzilla bug tracker</description>
4b6aa8
+    <long-description>Report to Bugzilla bug tracker in long description</long-description>
4b6aa8
+
4b6aa8
+    <support-restricted-access>no</support-restricted-access>
4b6aa8
+
4b6aa8
+    <options>
4b6aa8
+        <option type="text" name="Bugzilla_BugzillaURL">
4b6aa8
+            <label>Bugzilla URL</label>
4b6aa8
+            <note-html>Bugzilla HTML note</note-html>
4b6aa8
+        </option>
4b6aa8
+    </options>
4b6aa8
+</event>
4b6aa8
diff --git a/tests/conf/event_support_restricted_no_option.xml b/tests/conf/event_support_restricted_no_option.xml
4b6aa8
new file mode 100644
4b6aa8
index 0000000..b70e64b
4b6aa8
--- /dev/null
4b6aa8
+++ b/tests/conf/event_support_restricted_no_option.xml
4b6aa8
@@ -0,0 +1,15 @@
4b6aa8
+
4b6aa8
+<event>
4b6aa8
+    <name>Bugzilla</name>
4b6aa8
+    <description>Report to Bugzilla bug tracker</description>
4b6aa8
+    <long-description>Report to Bugzilla bug tracker in long description</long-description>
4b6aa8
+
4b6aa8
+    <support-restricted-access>yes</support-restricted-access>
4b6aa8
+
4b6aa8
+    <options>
4b6aa8
+        <option type="text" name="Bugzilla_BugzillaURL">
4b6aa8
+            <label>Bugzilla URL</label>
4b6aa8
+            <note-html>Bugzilla HTML note</note-html>
4b6aa8
+        </option>
4b6aa8
+    </options>
4b6aa8
+</event>
4b6aa8
diff --git a/tests/conf/event_support_restricted_with_option.xml b/tests/conf/event_support_restricted_with_option.xml
4b6aa8
new file mode 100644
4b6aa8
index 0000000..ce5a1f9
4b6aa8
--- /dev/null
4b6aa8
+++ b/tests/conf/event_support_restricted_with_option.xml
4b6aa8
@@ -0,0 +1,15 @@
4b6aa8
+
4b6aa8
+<event>
4b6aa8
+    <name>Bugzilla</name>
4b6aa8
+    <description>Report to Bugzilla bug tracker</description>
4b6aa8
+    <long-description>Report to Bugzilla bug tracker in long description</long-description>
4b6aa8
+
4b6aa8
+    <support-restricted-access optionname="Bugzilla_RestrictedAccess">yes</support-restricted-access>
4b6aa8
+
4b6aa8
+    <options>
4b6aa8
+        <option type="bool" name="Bugzilla_RestrictedAccess">
4b6aa8
+            <label>Bugzilla URL</label>
4b6aa8
+            <default-value>no</default-value>
4b6aa8
+        </option>
4b6aa8
+    </options>
4b6aa8
+</event>
4b6aa8
diff --git a/tests/event_config.at b/tests/event_config.at
4b6aa8
new file mode 100644
4b6aa8
index 0000000..5baf000
4b6aa8
--- /dev/null
4b6aa8
+++ b/tests/event_config.at
4b6aa8
@@ -0,0 +1,60 @@
4b6aa8
+# -*- Autotest -*-
4b6aa8
+
4b6aa8
+AT_BANNER([Event config])
4b6aa8
+
4b6aa8
+## ----------------- ##
4b6aa8
+## restricted_access ##
4b6aa8
+## ----------------- ##
4b6aa8
+
4b6aa8
+AT_TESTFUN([restricted_access],
4b6aa8
+[[
4b6aa8
+
4b6aa8
+#include "testsuite.h"
4b6aa8
+
4b6aa8
+TS_MAIN
4b6aa8
+{
4b6aa8
+    event_config_t *ect = new_event_config("restricted_access");
4b6aa8
+
4b6aa8
+    TS_ASSERT_FALSE(ect->ec_supports_restricted_access);
4b6aa8
+    TS_ASSERT_PTR_IS_NULL(ect->ec_restricted_access_option);
4b6aa8
+    TS_ASSERT_FALSE(ec_restricted_access_enabled(ect));
4b6aa8
+
4b6aa8
+    ect->ec_supports_restricted_access = true;
4b6aa8
+
4b6aa8
+    TS_ASSERT_PTR_IS_NULL(ect->ec_restricted_access_option);
4b6aa8
+    TS_ASSERT_FALSE(ec_restricted_access_enabled(ect));
4b6aa8
+
4b6aa8
+    ect->ec_restricted_access_option = xstrdup("PrivateTicket");
4b6aa8
+
4b6aa8
+    TS_ASSERT_FALSE(ec_restricted_access_enabled(ect));
4b6aa8
+
4b6aa8
+    event_option_t *eot = new_event_option();
4b6aa8
+    eot->eo_name = xstrdup("PrivateTicket");
4b6aa8
+    eot->eo_value = NULL;
4b6aa8
+
4b6aa8
+    ect->options = g_list_prepend(ect->options, eot);
4b6aa8
+
4b6aa8
+    TS_ASSERT_FALSE(ec_restricted_access_enabled(ect));
4b6aa8
+
4b6aa8
+    eot->eo_type = OPTION_TYPE_BOOL;
4b6aa8
+    eot->eo_value = xstrdup("no");
4b6aa8
+
4b6aa8
+    TS_ASSERT_FALSE(ec_restricted_access_enabled(ect));
4b6aa8
+
4b6aa8
+    free(eot->eo_value);
4b6aa8
+    eot->eo_value = xstrdup("yes");
4b6aa8
+
4b6aa8
+    TS_ASSERT_TRUE(ec_restricted_access_enabled(ect));
4b6aa8
+
4b6aa8
+    eot->eo_type = OPTION_TYPE_NUMBER;
4b6aa8
+
4b6aa8
+    TS_ASSERT_FALSE(ec_restricted_access_enabled(ect));
4b6aa8
+
4b6aa8
+    ect->ec_supports_restricted_access = false;
4b6aa8
+
4b6aa8
+    TS_ASSERT_FALSE(ec_restricted_access_enabled(ect));
4b6aa8
+
4b6aa8
+    free_event_config(ect);
4b6aa8
+}
4b6aa8
+TS_RETURN_MAIN
4b6aa8
+]])
4b6aa8
diff --git a/tests/testsuite.at b/tests/testsuite.at
4b6aa8
index c8269b1..392c3db 100644
4b6aa8
--- a/tests/testsuite.at
4b6aa8
+++ b/tests/testsuite.at
4b6aa8
@@ -22,3 +22,4 @@ m4_include([global_config.at])
4b6aa8
 m4_include([iso_date.at])
4b6aa8
 m4_include([uriparser.at])
4b6aa8
 m4_include([bugzilla_plugin.at])
4b6aa8
+m4_include([event_config.at])
4b6aa8
diff --git a/tests/xml_definition.at b/tests/xml_definition.at
4b6aa8
index 29043f8..7d2140f 100644
4b6aa8
--- a/tests/xml_definition.at
4b6aa8
+++ b/tests/xml_definition.at
4b6aa8
@@ -137,3 +137,54 @@ int main(void)
4b6aa8
     return EXIT_SUCCESS;
4b6aa8
 }
4b6aa8
 ]])
4b6aa8
+
4b6aa8
+## ----------------- ##
4b6aa8
+## restricted_access ##
4b6aa8
+## ----------------- ##
4b6aa8
+
4b6aa8
+AT_TESTFUN([restricted_access],
4b6aa8
+[[
4b6aa8
+
4b6aa8
+#include "testsuite.h"
4b6aa8
+
4b6aa8
+TS_MAIN
4b6aa8
+{
4b6aa8
+    {
4b6aa8
+        event_config_t *event_config = new_event_config("event_test_definition");
4b6aa8
+        load_event_description_from_file(event_config, "../../conf/event_no_support_restricted.xml");
4b6aa8
+
4b6aa8
+        TS_ASSERT_FALSE(event_config->ec_supports_restricted_access);
4b6aa8
+        TS_ASSERT_PTR_IS_NULL(event_config->ec_restricted_access_option);
4b6aa8
+
4b6aa8
+        free_event_config(event_config);
4b6aa8
+    }
4b6aa8
+    {
4b6aa8
+        event_config_t *event_config = new_event_config("event_test_definition");
4b6aa8
+        load_event_description_from_file(event_config, "../../conf/event_implicit_no_support_restricted.xml");
4b6aa8
+
4b6aa8
+        TS_ASSERT_FALSE(event_config->ec_supports_restricted_access);
4b6aa8
+        TS_ASSERT_PTR_IS_NULL(event_config->ec_restricted_access_option);
4b6aa8
+
4b6aa8
+        free_event_config(event_config);
4b6aa8
+    }
4b6aa8
+    {
4b6aa8
+        event_config_t *event_config = new_event_config("event_test_definition");
4b6aa8
+        load_event_description_from_file(event_config, "../../conf/event_support_restricted_no_option.xml");
4b6aa8
+
4b6aa8
+        TS_ASSERT_TRUE(event_config->ec_supports_restricted_access);
4b6aa8
+        TS_ASSERT_PTR_IS_NULL(event_config->ec_restricted_access_option);
4b6aa8
+
4b6aa8
+        free_event_config(event_config);
4b6aa8
+    }
4b6aa8
+    {
4b6aa8
+        event_config_t *event_config = new_event_config("event_test_definition");
4b6aa8
+        load_event_description_from_file(event_config, "../../conf/event_support_restricted_with_option.xml");
4b6aa8
+
4b6aa8
+        TS_ASSERT_TRUE(event_config->ec_supports_restricted_access);
4b6aa8
+        TS_ASSERT_STRING_EQ(event_config->ec_restricted_access_option, "Bugzilla_RestrictedAccess", "Loaded from configuration");
4b6aa8
+
4b6aa8
+        free_event_config(event_config);
4b6aa8
+    }
4b6aa8
+}
4b6aa8
+TS_RETURN_MAIN
4b6aa8
+]])
4b6aa8
-- 
4b6aa8
1.8.3.1
4b6aa8