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

sleede / fab-manager / #98

pending completion
#98

push

coveralls-ruby

sylvainbx
Merge branch 'dev' for release 5.7.0

1368 of 1368 new or added lines in 161 files covered. (100.0%)

7383 of 12030 relevant lines covered (61.37%)

14.06 hits per line

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

86.49
/app/controllers/api/notifications_controller.rb
1
# frozen_string_literal: true
2

3
# API Controller for resources of type Notification
4
# Notifications are scoped by user
5
class API::NotificationsController < API::ApiController
1✔
6
  before_action :authenticate_user!
1✔
7
  before_action :set_notification, only: :update
1✔
8

9
  # notifications can have anything attached, so we won't eager load the whole database
10
  around_action :skip_bullet, if: -> { defined?(Bullet) }
6✔
11

12
  # Number of notifications added to the page when the user clicks on 'load next notifications'
13
  NOTIFICATIONS_PER_PAGE = 15
1✔
14

15
  def index
1✔
16
    loop do
2✔
17
      @notifications = current_user.notifications
2✔
18
                                   .delivered_in_system(current_user)
19
                                   .includes(:attached_object)
20
                                   .page(params[:page])
21
                                   .per(NOTIFICATIONS_PER_PAGE)
22
                                   .order('created_at DESC')
23
      # we delete obsolete notifications on first access
24
      break unless delete_obsoletes(@notifications)
2✔
25
    end
26
    @totals = {
27
      total: current_user.notifications.delivered_in_system(current_user).count,
2✔
28
      unread: current_user.notifications.delivered_in_system(current_user).where(is_read: false).count
29
    }
30
    render :index
2✔
31
  end
32

33
  def last_unread
1✔
34
    loop do
1✔
35
      @notifications = current_user.notifications
1✔
36
                                   .delivered_in_system(current_user)
37
                                   .includes(:attached_object)
38
                                   .where(is_read: false)
39
                                   .limit(3)
40
                                   .order('created_at DESC')
41
      # we delete obsolete notifications on first access
42
      break unless delete_obsoletes(@notifications)
1✔
43
    end
44
    @totals = {
45
      total: current_user.notifications.delivered_in_system(current_user).count,
1✔
46
      unread: current_user.notifications.delivered_in_system(current_user).where(is_read: false).count
47
    }
48
    render :index
1✔
49
  end
50

51
  def polling
1✔
52
    @notifications = current_user.notifications
×
53
                                 .where('is_read = false AND created_at >= :date', date: params[:last_poll])
54
                                 .order('created_at DESC')
55
    @totals = {
56
      total: current_user.notifications.delivered_in_system(current_user).count,
×
57
      unread: current_user.notifications.delivered_in_system(current_user).where(is_read: false).count
58
    }
59
    render :index
×
60
  end
61

62
  def update
1✔
63
    @notification.mark_as_read
1✔
64
    render :show
1✔
65
  end
66

67
  def update_all
1✔
68
    current_user.notifications.where(is_read: false).find_each(&:mark_as_read)
1✔
69
    head :no_content
1✔
70
  end
71

72
  private
1✔
73

74
  def set_notification
1✔
75
    @notification = current_user.notifications.find(params[:id])
1✔
76
  end
77

78
  def delete_obsoletes(notifications)
1✔
79
    cleaned = false
3✔
80
    notifications.each do |n|
3✔
81
      if !Module.const_get(n.attached_object_type) || !n.attached_object
14✔
82
        n.destroy!
×
83
        cleaned = true
×
84
      end
85
    end
86
    cleaned
3✔
87
  end
88
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

© 2026 Coveralls, Inc