Class: HrLite::Kudo
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- HrLite::Kudo
- Defined in:
- app/models/hr_lite/kudo.rb
Constant Summary collapse
- BADGES =
Text-labelled badges (rendered with an inline SVG icon, never emoji).
{ "team_player" => "Team player", "above_and_beyond" => "Going above and beyond", "customer_hero" => "Customer hero", "problem_solver" => "Problem solver", "culture_champion" => "Culture champion" }.freeze
- DELETE_WINDOW =
15.minutes
Instance Method Summary collapse
- #badge_label ⇒ Object
-
#deletable_by?(user) ⇒ Boolean
Praise is immutable; the giver gets a short window to undo a mistake, admins/leadership can moderate any time.
-
#register_mentions! ⇒ Object
Creates mention rows from the message markers (existing users only, giver excluded) and notifies them.
Instance Method Details
#badge_label ⇒ Object
32 33 34 |
# File 'app/models/hr_lite/kudo.rb', line 32 def badge_label BADGES[badge] end |
#deletable_by?(user) ⇒ Boolean
Praise is immutable; the giver gets a short window to undo a mistake, admins/leadership can moderate any time.
25 26 27 28 29 30 |
# File 'app/models/hr_lite/kudo.rb', line 25 def deletable_by?(user) return false if user.nil? return true if HrLite.admin?(user) || HrLite.leadership?(user) giver_id == user.id && created_at > DELETE_WINDOW.ago end |
#register_mentions! ⇒ Object
Creates mention rows from the message markers (existing users only, giver excluded) and notifies them. Called once, right after create.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/hr_lite/kudo.rb', line 38 def register_mentions! ids = HrLite::MentionParser.user_ids() - [ giver_id ] users = HrLite.user_klass.where(id: ids) users.each { |u| kudo_mentions.create!(user_id: u.id) } HrLite::Notifications.publish( "kudos.mentioned", title: "#{HrLite.display_name(giver)} gave you kudos", body: HrLite::MentionParser.strip_markers().truncate(140), path: "/kudos", bell_to: users.to_a, email_to: users.to_a ) users end |