summaryrefslogtreecommitdiff
path: root/app/models/concerns/issuable.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/concerns/issuable.rb')
-rw-r--r--app/models/concerns/issuable.rb30
1 files changed, 20 insertions, 10 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index 2d06247a486..d5e2e63402f 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -31,6 +31,7 @@ module Issuable
TITLE_HTML_LENGTH_MAX = 800
DESCRIPTION_LENGTH_MAX = 1.megabyte
DESCRIPTION_HTML_LENGTH_MAX = 5.megabytes
+ SEARCHABLE_FIELDS = %w(title description).freeze
STATE_ID_MAP = {
opened: 1,
@@ -264,15 +265,16 @@ module Issuable
# matched_columns - Modify the scope of the query. 'title', 'description' or joining them with a comma.
#
# Returns an ActiveRecord::Relation.
- def full_search(query, matched_columns: 'title,description', use_minimum_char_limit: true)
- allowed_columns = [:title, :description]
- matched_columns = matched_columns.to_s.split(',').map(&:to_sym)
- matched_columns &= allowed_columns
+ def full_search(query, matched_columns: nil, use_minimum_char_limit: true)
+ if matched_columns
+ matched_columns = matched_columns.to_s.split(',')
+ matched_columns &= SEARCHABLE_FIELDS
+ matched_columns.map!(&:to_sym)
+ end
- # Matching title or description if the matched_columns did not contain any allowed columns.
- matched_columns = [:title, :description] if matched_columns.empty?
+ search_columns = matched_columns.presence || [:title, :description]
- fuzzy_search(query, matched_columns, use_minimum_char_limit: use_minimum_char_limit)
+ fuzzy_search(query, search_columns, use_minimum_char_limit: use_minimum_char_limit)
end
def simple_sorts
@@ -330,12 +332,15 @@ module Issuable
# When using CTE make sure to select the same columns that are on the group_by clause.
# This prevents errors when ignored columns are present in the database.
issuable_columns = with_cte ? issue_grouping_columns(use_cte: with_cte) : "#{table_name}.*"
+ group_columns = issue_grouping_columns(use_cte: with_cte) + ["highest_priorities.label_priority"]
- extra_select_columns.unshift("(#{highest_priority}) AS highest_priority")
+ extra_select_columns.unshift("highest_priorities.label_priority as highest_priority")
select(issuable_columns)
.select(extra_select_columns)
- .group(issue_grouping_columns(use_cte: with_cte))
+ .from("#{table_name}")
+ .joins("JOIN LATERAL(#{highest_priority}) as highest_priorities ON TRUE")
+ .group(group_columns)
.reorder(Gitlab::Database.nulls_last_order('highest_priority', direction))
end
@@ -382,7 +387,7 @@ module Issuable
if use_cte
attribute_names.map { |attr| arel_table[attr.to_sym] }
else
- arel_table[:id]
+ [arel_table[:id]]
end
end
@@ -457,6 +462,7 @@ module Issuable
if old_associations
old_labels = old_associations.fetch(:labels, labels)
old_assignees = old_associations.fetch(:assignees, assignees)
+ old_severity = old_associations.fetch(:severity, severity)
if old_labels != labels
changes[:labels] = [old_labels.map(&:hook_attrs), labels.map(&:hook_attrs)]
@@ -466,6 +472,10 @@ module Issuable
changes[:assignees] = [old_assignees.map(&:hook_attrs), assignees.map(&:hook_attrs)]
end
+ if supports_severity? && old_severity != severity
+ changes[:severity] = [old_severity, severity]
+ end
+
if self.respond_to?(:total_time_spent)
old_total_time_spent = old_associations.fetch(:total_time_spent, total_time_spent)
old_time_change = old_associations.fetch(:time_change, time_change)