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

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