Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Add Note/Override excerpt size setting #2052

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -8026,7 +8026,8 @@ buffer_notes_xml (GString *buffer, iterator_t *notes, int include_notes_details,
if (include_notes_details == 0)
{
const char *text = note_iterator_text (notes);
gchar *excerpt = utf8_substring (text, 0, 60);
gchar *excerpt = utf8_substring (text, 0,
setting_excerpt_size_int ());
/* This must match send_get_common. */
buffer_xml_append_printf (buffer,
"<owner><name>%s</name></owner>"
Expand Down Expand Up @@ -8288,7 +8289,8 @@ buffer_overrides_xml (GString *buffer, iterator_t *overrides,
if (include_overrides_details == 0)
{
const char *text = override_iterator_text (overrides);
gchar *excerpt = utf8_substring (text, 0, 60);
gchar *excerpt = utf8_substring (text, 0,
setting_excerpt_size_int ());
/* This must match send_get_common. */
buffer_xml_append_printf (buffer,
"<owner><name>%s</name></owner>"
Expand Down
10 changes: 10 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,13 @@ result_detection_reference (result_t, report_t, const char *, const char *,
*/
#define MIN_QOD_DEFAULT 70

/**
* @brief Default size to limit note and override text to in reports.
*/
#define EXCERPT_SIZE_DEFAULT 300



void
reports_clear_count_cache_for_override (override_t, int);

Expand Down Expand Up @@ -3299,6 +3306,9 @@ setting_is_default_ca_cert (const gchar *);
char *
setting_filter (const char *);

int
setting_excerpt_size_int ();

void
init_setting_iterator (iterator_t *, const char *, const char *, int, int, int,
const char *);
Expand Down
40 changes: 40 additions & 0 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -15785,6 +15785,19 @@ check_db_settings ()
" 'Whether to rebuild report caches on changes affecting severity.',"
" '1');");

if (sql_int ("SELECT count(*) FROM settings"
" WHERE uuid = '9246a0f6-c6ad-44bc-86c2-557a527c8fb3'"
" AND " ACL_IS_GLOBAL () ";")
== 0)
sql ("INSERT into settings (uuid, owner, name, comment, value)"
" VALUES"
" ('9246a0f6-c6ad-44bc-86c2-557a527c8fb3', NULL,"
" 'Note/Override Excerpt Size',"
" 'The maximum length of notes and override text shown in' ||"
" ' reports without enabling note/override details.',"
" '%d');",
EXCERPT_SIZE_DEFAULT);

if (sql_int ("SELECT count(*) FROM settings"
" WHERE uuid = '" SETTING_UUID_LSC_DEB_MAINTAINER "'"
" AND " ACL_IS_GLOBAL () ";")
Expand Down Expand Up @@ -17148,6 +17161,13 @@ credentials_setup (credentials_t *credentials)
" ORDER BY coalesce (owner, 0) DESC LIMIT 1;",
credentials->uuid);

credentials->excerpt_size
= sql_int ("SELECT value FROM settings"
" WHERE name = 'Note/Override Excerpt Size'"
" AND " ACL_GLOBAL_OR_USER_OWNS ()
" ORDER BY coalesce (owner, 0) DESC LIMIT 1;",
credentials->uuid);

return 0;
}

Expand Down Expand Up @@ -50132,6 +50152,19 @@ setting_filter (const char *resource)
current_credentials.uuid);
}

/**
* @brief Return the Note/Override Excerpt Size user setting as an int.
*
* @return The excerpt size.
*/
int
setting_excerpt_size_int ()
{
if (current_credentials.excerpt_size <= 0)
return EXCERPT_SIZE_DEFAULT;
return current_credentials.excerpt_size;
}

/**
* @brief Return the Dynamic Severity user setting as an int.
*
Expand Down Expand Up @@ -50474,6 +50507,7 @@ modify_setting (const gchar *uuid, const gchar *name,
}

if (uuid && (strcmp (uuid, SETTING_UUID_ROWS_PER_PAGE) == 0
|| strcmp (uuid, SETTING_UUID_EXCERPT_SIZE) == 0
|| strcmp (uuid, "6765549a-934e-11e3-b358-406186ea4fc5") == 0
|| strcmp (uuid, "77ec2444-e7f2-4a80-a59b-f4237782d93f") == 0
|| strcmp (uuid, "7eda49c5-096c-4bef-b1ab-d080d87300df") == 0
Expand Down Expand Up @@ -50586,6 +50620,12 @@ modify_setting (const gchar *uuid, const gchar *name,
reports_clear_count_cache (current_credentials.uuid);
}

if (strcmp (uuid, SETTING_UUID_EXCERPT_SIZE) == 0)
{
/* Note/Override Excerpt Size */
current_credentials.excerpt_size = atoi (value);
}

if (strcmp (uuid, "7eda49c5-096c-4bef-b1ab-d080d87300df") == 0)
{
double severity_dbl;
Expand Down
5 changes: 5 additions & 0 deletions src/manage_sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@
*/
#define SETTING_UUID_MAX_ROWS_PER_PAGE "76374a7a-0569-11e6-b6da-28d24461215b"

/**
* @brief UUID of 'Note/Override Excerpt Size' setting.
*/
#define SETTING_UUID_EXCERPT_SIZE "9246a0f6-c6ad-44bc-86c2-557a527c8fb3"

/**
* @brief UUID of 'Default CA Cert' setting.
*/
Expand Down