Module: Timebox

Extended by:
ActiveSupport::Concern
Includes:
AtomicInternalId, CacheMarkdownField, FromUnion, Gitlab::SQL::Pattern, IidRoutes, Referable, StripAttribute
Included in:
Milestone
Defined in:
app/models/concerns/timebox.rb

Defined Under Namespace

Classes: TimeboxStruct

Constant Summary collapse

None =

Represents a “No Timebox” state used for filtering Issues and Merge Requests that have no timeboxes assigned.

TimeboxStruct.new('No Timebox', 'No Timebox', 0)
Any =
TimeboxStruct.new('Any Timebox', '', -1)
Upcoming =
TimeboxStruct.new('Upcoming', '#upcoming', -2)
Started =
TimeboxStruct.new('Started', '#started', -3)

Constants included from Gitlab::SQL::Pattern

Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING, Gitlab::SQL::Pattern::REGEX_QUOTED_WORD

Constants included from CacheMarkdownField

CacheMarkdownField::INVALIDATED_BY

Constants included from AtomicInternalId

AtomicInternalId::MissingValueError

Instance Attribute Summary

Attributes included from CacheMarkdownField

#skip_markdown_cache_validation

Instance Method Summary collapse

Methods included from StripAttribute

#strip_attributes!

Methods included from Referable

#referable_inspect, #to_reference_base

Methods included from IidRoutes

#to_param

Methods included from CacheMarkdownField

#attribute_invalidated?, #banzai_render_context, #cached_html_for, #cached_html_up_to_date?, #can_cache_field?, #invalidated_markdown_cache?, #latest_cached_markdown_version, #local_version, #mentionable_attributes_changed?, #mentioned_filtered_user_ids_for, #parent_user, #refresh_markdown_cache, #refresh_markdown_cache!, #rendered_field_content, #skip_project_check?, #store_mentions!, #updated_cached_html_for

Methods included from AtomicInternalId

group_init, #internal_id_read_scope, #internal_id_scope_attrs, #internal_id_scope_usage, project_init, scope_attrs, scope_usage

Instance Method Details

#group_timebox?Boolean

Returns:

  • (Boolean)

185
186
187
# File 'app/models/concerns/timebox.rb', line 185

def group_timebox?
  group_id.present?
end

#merge_requests_enabled?Boolean

Returns:

  • (Boolean)

205
206
207
208
209
210
211
212
213
# File 'app/models/concerns/timebox.rb', line 205

def merge_requests_enabled?
  if group_timebox?
    # Assume that groups have at least one project with merge requests enabled.
    # Otherwise, we would need to load all of the projects from the database.
    true
  elsif project_timebox?
    project&.merge_requests_enabled?
  end
end

#project_timebox?Boolean

Returns:

  • (Boolean)

189
190
191
# File 'app/models/concerns/timebox.rb', line 189

def project_timebox?
  project_id.present?
end

173
174
175
# File 'app/models/concerns/timebox.rb', line 173

def reference_link_text(from = nil)
  self.class.reference_prefix + self.title
end

#resource_parentObject


197
198
199
# File 'app/models/concerns/timebox.rb', line 197

def resource_parent
  group || project
end

#safe_titleObject


193
194
195
# File 'app/models/concerns/timebox.rb', line 193

def safe_title
  title.to_slug.normalize.to_s
end

#timebox_nameObject


181
182
183
# File 'app/models/concerns/timebox.rb', line 181

def timebox_name
  model_name.singular
end

#title=(value) ⇒ Object


177
178
179
# File 'app/models/concerns/timebox.rb', line 177

def title=(value)
  write_attribute(:title, sanitize_title(value)) if value.present?
end

#to_ability_nameObject


201
202
203
# File 'app/models/concerns/timebox.rb', line 201

def to_ability_name
  model_name.singular
end

#to_reference(from = nil, format: :name, full: false) ⇒ Object

Returns the String necessary to reference a Timebox in Markdown. Group timeboxes only support name references, and do not support cross-project references.

format - Symbol format to use (default: :iid, optional: :name)

Examples:

Milestone.first.to_reference                           # => "%1"
Iteration.first.to_reference(format: :name)            # => "*iteration:\"goal\""
Milestone.first.to_reference(cross_namespace_project)  # => "gitlab-org/gitlab-foss%1"
Iteration.first.to_reference(same_namespace_project)   # => "gitlab-foss*iteration:1"

162
163
164
165
166
167
168
169
170
171
# File 'app/models/concerns/timebox.rb', line 162

def to_reference(from = nil, format: :name, full: false)
  format_reference = timebox_format_reference(format)
  reference = "#{self.class.reference_prefix}#{format_reference}"

  if project
    "#{project.to_reference_base(from, full: full)}#{reference}"
  else
    reference
  end
end

#weight_available?Boolean

Returns:

  • (Boolean)

215
216
217
# File 'app/models/concerns/timebox.rb', line 215

def weight_available?
  resource_parent&.feature_available?(:issue_weights)
end