Module: Awardable

Extended by:
ActiveSupport::Concern
Included in:
Issuable, Note, Snippet
Defined in:
app/models/concerns/awardable.rb

Instance Method Summary collapse

Instance Method Details

#awarded_emoji?(emoji_name, current_user) ⇒ Boolean

Returns:

  • (Boolean)

107
108
109
# File 'app/models/concerns/awardable.rb', line 107

def awarded_emoji?(emoji_name, current_user)
  award_emoji.named(emoji_name).awarded_by(current_user).exists?
end

#downvotesObject


85
86
87
# File 'app/models/concerns/awardable.rb', line 85

def downvotes
  award_emoji.downvotes.count
end

#emoji_awardable?Boolean

Returns:

  • (Boolean)

93
94
95
# File 'app/models/concerns/awardable.rb', line 93

def emoji_awardable?
  true
end

#grouped_awards(with_thumbs: true) ⇒ Object


73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/concerns/awardable.rb', line 73

def grouped_awards(with_thumbs: true)
  # By default we always load award_emoji user association
  awards = award_emoji.group_by(&:name)

  if with_thumbs && (!project || project.show_default_award_emojis?)
    awards[AwardEmoji::UPVOTE_NAME]   ||= []
    awards[AwardEmoji::DOWNVOTE_NAME] ||= []
  end

  awards
end

#upvotesObject


89
90
91
# File 'app/models/concerns/awardable.rb', line 89

def upvotes
  award_emoji.upvotes.count
end

#user_authored?(current_user) ⇒ Boolean

Returns:

  • (Boolean)

101
102
103
104
105
# File 'app/models/concerns/awardable.rb', line 101

def user_authored?(current_user)
  author = self.respond_to?(:author) ? self.author : self.user

  author == current_user
end

#user_can_award?(current_user) ⇒ Boolean

Returns:

  • (Boolean)

97
98
99
# File 'app/models/concerns/awardable.rb', line 97

def user_can_award?(current_user)
  Ability.allowed?(current_user, :award_emoji, self)
end