Module: ResolvableDiscussion

Extended by:
ActiveSupport::Concern
Includes:
Gitlab::Utils::StrongMemoize
Included in:
Discussion
Defined in:
app/models/concerns/resolvable_discussion.rb

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Instance Method Details

#can_resolve?(current_user) ⇒ Boolean

Returns:

  • (Boolean)

80
81
82
83
84
85
86
# File 'app/models/concerns/resolvable_discussion.rb', line 80

def can_resolve?(current_user)
  return false unless current_user
  return false unless resolvable?

  current_user == self.noteable.try(:author) ||
    current_user.can?(:resolve_note, self.project)
end

#first_noteObject


50
51
52
53
54
# File 'app/models/concerns/resolvable_discussion.rb', line 50

def first_note
  strong_memoize(:first_note) do
    notes.first
  end
end

#first_note_to_resolveObject


56
57
58
59
60
61
62
# File 'app/models/concerns/resolvable_discussion.rb', line 56

def first_note_to_resolve
  return unless resolvable?

  strong_memoize(:first_note_to_resolve) do
    notes.find(&:to_be_resolved?)
  end
end

#last_resolved_noteObject


64
65
66
67
68
69
70
# File 'app/models/concerns/resolvable_discussion.rb', line 64

def last_resolved_note
  return unless resolved?

  strong_memoize(:last_resolved_note) do
    resolved_notes.max_by(&:resolved_at)
  end
end

#resolvable?Boolean

Returns:

  • (Boolean)

38
39
40
41
42
# File 'app/models/concerns/resolvable_discussion.rb', line 38

def resolvable?
  strong_memoize(:resolvable) do
    potentially_resolvable? && notes.any?(&:resolvable?)
  end
end

#resolve!(current_user) ⇒ Object


88
89
90
91
92
# File 'app/models/concerns/resolvable_discussion.rb', line 88

def resolve!(current_user)
  return unless resolvable?

  update { |notes| notes.resolve!(current_user) }
end

#resolved?Boolean

Returns:

  • (Boolean)

44
45
46
47
48
# File 'app/models/concerns/resolvable_discussion.rb', line 44

def resolved?
  strong_memoize(:resolved) do
    resolvable? && notes.none?(&:to_be_resolved?)
  end
end

#resolved_notesObject


72
73
74
# File 'app/models/concerns/resolvable_discussion.rb', line 72

def resolved_notes
  notes.select(&:resolved?)
end

#to_be_resolved?Boolean

Returns:

  • (Boolean)

76
77
78
# File 'app/models/concerns/resolvable_discussion.rb', line 76

def to_be_resolved?
  resolvable? && !resolved?
end

#unresolve!Object


94
95
96
97
98
# File 'app/models/concerns/resolvable_discussion.rb', line 94

def unresolve!
  return unless resolvable?

  update { |notes| notes.unresolve! }
end