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

Make bulk tagging work if resources already tagged #711

Merged
merged 3 commits into from
Aug 22, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix ORPHAN calculations in GET_TICKETS [#684](https://github.com/greenbone/gvmd/pull/684) [#692](https://github.com/greenbone/gvmd/pull/692)
- Fix assignment of orphaned tickets to the current user [#685](https://github.com/greenbone/gvmd/pull/685)
- Fix response from GET_VULNS when given vuln_id does not exists [#696](https://github.com/greenbone/gvmd/pull/696)
- Make bulk tagging with a filter work if the resources are already tagged [#711](https://github.com/greenbone/gvmd/pull/711)

### Removed
- The handling of NVT updates via OTP has been removed. [#575](https://github.com/greenbone/gvmd/pull/575)
Expand Down
40 changes: 8 additions & 32 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -62067,13 +62067,12 @@ manage_slave_check_period ()
* @param[in] uuid The resource UUID.
* @param[in] resource The resource row id.
* @param[in] location Whether the resource is in the trashcan.
* @param[in] duplicates_check Whether to check if resource already has tag.
*
*
* @return 0 success, -1 error
*/
static int
tag_add_resource (tag_t tag, const char *type, const char *uuid,
resource_t resource, int location, int duplicates_check)
resource_t resource, int location)
{
int already_added, ret;
gchar *quoted_resource_uuid;
Expand All @@ -62082,9 +62081,7 @@ tag_add_resource (tag_t tag, const char *type, const char *uuid,

quoted_resource_uuid = uuid ? sql_insert (uuid) : g_strdup ("''");

if (duplicates_check == 0)
already_added = 0;
else if (type_is_info_subtype (type))
if (type_is_info_subtype (type))
already_added = sql_int ("SELECT count(*) FROM tag_resources"
" WHERE resource_type = '%s'"
" AND resource_uuid = %s"
Expand Down Expand Up @@ -62158,7 +62155,7 @@ tag_add_resource_uuid (tag_t tag, const char *type, const char *uuid,
if (resource == 0)
return 1;

return tag_add_resource (tag, type, uuid, resource, resource_location, 1);
return tag_add_resource (tag, type, uuid, resource, resource_location);
}

/**
Expand Down Expand Up @@ -62256,30 +62253,9 @@ tag_add_resources_filter (tag_t tag, const char *type, const char *filter)
return 2;
}

if (type_is_info_subtype (type))
init_iterator (&resources,
"SELECT id, uuid FROM (%s) AS filter_selection"
" WHERE NOT EXISTS"
" (SELECT * FROM tag_resources"
" WHERE resource_type = '%s'"
" AND resource_uuid = filter_selection.uuid"
" AND tag = %llu)",
filtered_select,
type,
tag);
else
init_iterator (&resources,
"SELECT id, uuid FROM (%s) AS filter_selection"
" WHERE NOT EXISTS"
" (SELECT * FROM tag_resources"
" WHERE resource_type = '%s'"
" AND resource = filter_selection.id"
" AND resource_location = %d"
" AND tag = %llu)",
filtered_select,
type,
LOCATION_TABLE,
tag);
init_iterator (&resources,
"%s",
filtered_select);

break;
default:
Expand All @@ -62306,7 +62282,7 @@ tag_add_resources_filter (tag_t tag, const char *type, const char *filter)
current_uuid = iterator_string (&resources, 1);

add_ret = tag_add_resource (tag, type, current_uuid, resource,
LOCATION_TABLE, 0);
LOCATION_TABLE);
if (add_ret)
{
ret = add_ret;
Expand Down