Skip to content

Commit

Permalink
Merge pull request #711 from timopollmeier/bulk-tag-fix
Browse files Browse the repository at this point in the history
Make bulk tagging work if resources already tagged
  • Loading branch information
mattmundell authored Aug 22, 2019
2 parents 1f0d7c9 + 3dacfdb commit 79f0542
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 32 deletions.
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

0 comments on commit 79f0542

Please sign in to comment.