Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h-abdelsalam committed Feb 20, 2024
1 parent e3ad01e commit a1cb092
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ manage_create_sql_functions ()
"$$ LANGUAGE plpgsql"
" IMMUTABLE;");

sql ("CREATE OR REPLACE FUNCTION compliance_status ("
sql ("CREATE OR REPLACE FUNCTION report_compliance_status ("
" report_id integer)"
"RETURNS text AS $$ "
"BEGIN"
Expand All @@ -918,7 +918,9 @@ manage_create_sql_functions ()
"$$ LANGUAGE plpgsql"
" IMMUTABLE;");

sql ("CREATE OR REPLACE FUNCTION compliance_count (report_id integer, compliance text)"
sql ("CREATE OR REPLACE FUNCTION report_compliance_count ("
" report_id integer,"
" compliance text)"
" RETURNS integer AS $$"
" DECLARE count integer := 0;"
" BEGIN"
Expand Down
21 changes: 11 additions & 10 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,7 @@ filter_control_str (keyword_t **point, const char *column, gchar **string)
* @param[out] levels String describing threat levels (message types)
* to include in count (for example, "hmlg" for
* High, Medium, Low and loG). All levels if NULL.
* @param[out] comliance_levels String describing compliance levels
* @param[out] compliance_levels String describing compliance levels
* to include in count (for example, "yniu" for
* "yes" (compliant), "n" for "no" (not compliant),
* "i" for "incomplete" and "u" for "undefined"
Expand Down Expand Up @@ -21910,22 +21910,22 @@ report_add_results_array (report_t report, GArray *results)
KEYWORD_TYPE_INTEGER \
}, \
{ \
"compliance_count (id, 'YES')", \
"report_compliance_count (id, 'YES')", \
"compliance_yes", \
KEYWORD_TYPE_INTEGER \
}, \
{ \
"compliance_count (id, 'NO')", \
"report_compliance_count (id, 'NO')", \
"compliance_no", \
KEYWORD_TYPE_INTEGER \
}, \
{ \
"compliance_count (id, 'INCOMPLETE')", \
"report_compliance_count (id, 'INCOMPLETE')", \
"compliance_incomplete", \
KEYWORD_TYPE_INTEGER \
}, \
{ \
"compliance_status (id)", \
"report_compliance_status (id)", \
"compliant", \
KEYWORD_TYPE_STRING \
}, \
Expand Down Expand Up @@ -21973,7 +21973,8 @@ where_compliance_status (const char *compliance)
compliance_sql = g_string_new ("");
count = 0;

g_string_append_printf (compliance_sql, " AND compliance_status(reports.id) IN (");
g_string_append_printf (compliance_sql,
" AND report_compliance_status(reports.id) IN (");

if (strchr (compliance, 'y'))
{
Expand All @@ -21998,9 +21999,9 @@ where_compliance_status (const char *compliance)

g_string_append (compliance_sql, ")");

if (count == 4)
if ((count == 4) || (count == 0))
{
/* All compliance levels selected. */
/* All compliance levels or no valid ones selected. */
g_string_free (compliance_sql, TRUE);
return NULL;
}
Expand Down Expand Up @@ -22340,9 +22341,9 @@ where_compliance_levels (const char *levels)
}
g_string_append (levels_sql, ")");

if (count == 4)
if ((count == 4) || (count == 0))
{
/* All compliance levels selected, so no restriction is necessary. */
/* All compliance levels or none selected, so no restriction is necessary. */
g_string_free (levels_sql, TRUE);
return NULL;
}
Expand Down

0 comments on commit a1cb092

Please sign in to comment.