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)


105
106
107
# File 'app/models/concerns/awardable.rb', line 105

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

#downvotesObject



83
84
85
# File 'app/models/concerns/awardable.rb', line 83

def downvotes
  award_emoji.downvotes.count
end

#emoji_awardable?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'app/models/concerns/awardable.rb', line 91

def emoji_awardable?
  true
end

#grouped_awards(with_thumbs: true) ⇒ Object



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

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



87
88
89
# File 'app/models/concerns/awardable.rb', line 87

def upvotes
  award_emoji.upvotes.count
end

#user_authored?(current_user) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
102
103
# File 'app/models/concerns/awardable.rb', line 99

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)


95
96
97
# File 'app/models/concerns/awardable.rb', line 95

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