• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pdc_describe / 9dbcf7a4-1c56-4510-9614-74ad5a22cff6

31 Jul 2024 02:46PM UTC coverage: 1.08% (-95.1%) from 96.17%
9dbcf7a4-1c56-4510-9614-74ad5a22cff6

push

circleci

jrgriffiniii
wip

52 of 4814 relevant lines covered (1.08%)

0.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/models/work_activity_notification.rb
1
# frozen_string_literal: true
2

3
class WorkActivityNotification < ApplicationRecord
×
4
  belongs_to :work_activity
×
5
  belongs_to :user
×
6

7
  after_create do
×
8
    if send_message?
×
9
      mailer = NotificationMailer.with(user:, work_activity:)
×
10
      message = mailer.build_message
×
11
      message.deliver_later(wait: 10.seconds) unless Rails.env.development?
×
12
    end
×
13
  end
×
14

15
  private
×
16

17
    def direct_message?
×
18
      @direct_message ||= work_activity.activity_type == WorkActivity::MESSAGE && work_activity.message.include?("@#{user.uid}")
×
19
    end
×
20

21
    def send_message?
×
22
      return true if direct_message? # always send a direct message
×
23
      return false unless user.email_messages_enabled? # do not send message if all emails are disabled
×
24
      work = work_activity.work
×
25

26
      if work.resource.subcommunities.count > 1
×
27
        subcommunities_can_send = work.resource.subcommunities.map { |subcommunity| send_message_for_community?(subcommunity) }
×
28
        subcommunities_can_send.any?
×
29
      else
×
30
        send_message_for_community?(work.resource.subcommunities.first)
×
31
      end
×
32
    end
×
33

34
    def send_message_for_community?(subcommunity)
×
35
      group.messages_enabled_for?(user:, subcommunity:)
×
36
    end
×
37

38
    def group
×
39
      @group ||= work_activity.work.group
×
40
    end
×
41
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc