diff options
Diffstat (limited to 'app/models/concerns/taggable_queries.rb')
-rw-r--r-- | app/models/concerns/taggable_queries.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/app/models/concerns/taggable_queries.rb b/app/models/concerns/taggable_queries.rb index 2897e5e6420..cba2e93a86d 100644 --- a/app/models/concerns/taggable_queries.rb +++ b/app/models/concerns/taggable_queries.rb @@ -12,5 +12,26 @@ module TaggableQueries .where(taggings: { context: context, taggable_type: polymorphic_name }) .select('COALESCE(array_agg(tags.name ORDER BY name), ARRAY[]::text[])') end + + def matches_tag_ids(tag_ids, table: quoted_table_name, column: 'id') + matcher = ::ActsAsTaggableOn::Tagging + .where(taggable_type: CommitStatus.name) + .where(context: 'tags') + .where("taggable_id = #{connection.quote_table_name(table)}.#{connection.quote_column_name(column)}") # rubocop:disable GitlabSecurity/SqlInjection + .where.not(tag_id: tag_ids) + .select('1') + + where("NOT EXISTS (?)", matcher) + end + + def with_any_tags(table: quoted_table_name, column: 'id') + matcher = ::ActsAsTaggableOn::Tagging + .where(taggable_type: CommitStatus.name) + .where(context: 'tags') + .where("taggable_id = #{connection.quote_table_name(table)}.#{connection.quote_column_name(column)}") # rubocop:disable GitlabSecurity/SqlInjection + .select('1') + + where("EXISTS (?)", matcher) + end end end |