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 May 13, 2024
1 parent e6f6ec7 commit bd4a6e8
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 @@ -2037,7 +2037,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 @@ -21969,22 +21969,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 @@ -22032,7 +22032,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 @@ -22057,9 +22058,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 @@ -22399,9 +22400,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 bd4a6e8

Please sign in to comment.