diff options
Diffstat (limited to 'app/models/issue.rb')
-rw-r--r-- | app/models/issue.rb | 44 |
1 files changed, 13 insertions, 31 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index e0b0c352c22..9c568414ec2 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -81,6 +81,7 @@ class Issue < ApplicationRecord has_and_belongs_to_many :self_managed_prometheus_alert_events, join_table: :issues_self_managed_prometheus_alert_events # rubocop: disable Rails/HasAndBelongsToMany has_and_belongs_to_many :prometheus_alert_events, join_table: :issues_prometheus_alert_events # rubocop: disable Rails/HasAndBelongsToMany has_many :prometheus_alerts, through: :prometheus_alert_events + has_and_belongs_to_many :customer_relations_contacts, join_table: :issue_customer_relations_contacts, class_name: 'CustomerRelations::Contact' # rubocop: disable Rails/HasAndBelongsToMany accepts_nested_attributes_for :issuable_severity, update_only: true accepts_nested_attributes_for :sentry_issue @@ -107,8 +108,6 @@ class Issue < ApplicationRecord scope :order_due_date_asc, -> { reorder(::Gitlab::Database.nulls_last_order('due_date', 'ASC')) } scope :order_due_date_desc, -> { reorder(::Gitlab::Database.nulls_last_order('due_date', 'DESC')) } scope :order_closest_future_date, -> { reorder(Arel.sql('CASE WHEN issues.due_date >= CURRENT_DATE THEN 0 ELSE 1 END ASC, ABS(CURRENT_DATE - issues.due_date) ASC')) } - scope :order_relative_position_asc, -> { reorder(::Gitlab::Database.nulls_last_order('relative_position', 'ASC')) } - scope :order_relative_position_desc, -> { reorder(::Gitlab::Database.nulls_first_order('relative_position', 'DESC')) } scope :order_closed_date_desc, -> { reorder(closed_at: :desc) } scope :order_created_at_desc, -> { reorder(created_at: :desc) } scope :order_severity_asc, -> { includes(:issuable_severity).order('issuable_severities.severity ASC NULLS FIRST') } @@ -127,6 +126,7 @@ class Issue < ApplicationRecord project: [:route, { namespace: :route }]) } scope :with_issue_type, ->(types) { where(issue_type: types) } + scope :without_issue_type, ->(types) { where.not(issue_type: types) } scope :public_only, -> { without_hidden.where(confidential: false) @@ -166,6 +166,8 @@ class Issue < ApplicationRecord scope :by_project_id_and_iid, ->(composites) do where_composite(%i[project_id iid], composites) end + scope :with_null_relative_position, -> { where(relative_position: nil) } + scope :with_non_null_relative_position, -> { where.not(relative_position: nil) } after_commit :expire_etag_cache, unless: :importing? after_save :ensure_metrics, unless: :importing? @@ -266,8 +268,8 @@ class Issue < ApplicationRecord 'due_date' => -> { order_due_date_asc.with_order_id_desc }, 'due_date_asc' => -> { order_due_date_asc.with_order_id_desc }, 'due_date_desc' => -> { order_due_date_desc.with_order_id_desc }, - 'relative_position' => -> { order_relative_position_asc.with_order_id_desc }, - 'relative_position_asc' => -> { order_relative_position_asc.with_order_id_desc } + 'relative_position' => -> { order_by_relative_position }, + 'relative_position_asc' => -> { order_by_relative_position } } ) end @@ -277,7 +279,7 @@ class Issue < ApplicationRecord when 'closest_future_date', 'closest_future_date_asc' then order_closest_future_date when 'due_date', 'due_date_asc' then order_due_date_asc.with_order_id_desc when 'due_date_desc' then order_due_date_desc.with_order_id_desc - when 'relative_position', 'relative_position_asc' then order_relative_position_asc.with_order_id_desc + when 'relative_position', 'relative_position_asc' then order_by_relative_position when 'severity_asc' then order_severity_asc.with_order_id_desc when 'severity_desc' then order_severity_desc.with_order_id_desc else @@ -285,13 +287,8 @@ class Issue < ApplicationRecord end end - # `with_cte` argument allows sorting when using CTE queries and prevents - # errors in postgres when using CTE search optimisation - def self.order_by_position_and_priority(with_cte: false) - order = Gitlab::Pagination::Keyset::Order.build([column_order_relative_position, column_order_highest_priority, column_order_id_desc]) - - order_labels_priority(with_cte: with_cte) - .reorder(order) + def self.order_by_relative_position + reorder(Gitlab::Pagination::Keyset::Order.build([column_order_relative_position, column_order_id_asc])) end def self.column_order_relative_position @@ -306,25 +303,6 @@ class Issue < ApplicationRecord ) end - def self.column_order_highest_priority - Gitlab::Pagination::Keyset::ColumnOrderDefinition.new( - attribute_name: 'highest_priority', - column_expression: Arel.sql('highest_priorities.label_priority'), - order_expression: Gitlab::Database.nulls_last_order('highest_priorities.label_priority', 'ASC'), - reversed_order_expression: Gitlab::Database.nulls_last_order('highest_priorities.label_priority', 'DESC'), - order_direction: :asc, - nullable: :nulls_last, - distinct: false - ) - end - - def self.column_order_id_desc - Gitlab::Pagination::Keyset::ColumnOrderDefinition.new( - attribute_name: 'id', - order_expression: arel_table[:id].desc - ) - end - def self.column_order_id_asc Gitlab::Pagination::Keyset::ColumnOrderDefinition.new( attribute_name: 'id', @@ -541,6 +519,10 @@ class Issue < ApplicationRecord issue_type_supports?(:time_tracking) end + def supports_move_and_clone? + issue_type_supports?(:move_and_clone) + end + def email_participants_emails issue_email_participants.pluck(:email) end |