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

simukappu / activity_notification / 20669942116

03 Jan 2026 12:59AM UTC coverage: 99.759%. Remained the same
20669942116

push

travis-ci

web-flow
Update CHANGELOG.md

3727 of 3736 relevant lines covered (99.76%)

1839.75 hits per line

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

100.0
/app/controllers/activity_notification/notifications_controller.rb
1
module ActivityNotification
18✔
2
  # Controller to manage notifications.
3
  class NotificationsController < ActivityNotification.config.parent_controller.constantize
18✔
4
    # Include CommonController to select target and define common methods
5
    include CommonController
18✔
6
    before_action :set_notification, except: [:index, :open_all, :destroy_all]
18✔
7

8
    # Shows notification index of the target.
9
    #
10
    # GET /:target_type/:target_id/notifications
11
    # @overload index(params)
12
    #   @param [Hash] params Request parameter options for notification index
13
    #   @option params [String] :filter                 (nil)     Filter option to load notification index by their status (Nothing as auto, 'opened' or 'unopened')
14
    #   @option params [String] :limit                  (nil)     Maximum number of notifications to return
15
    #   @option params [String] :reverse                ('false') Whether notification index will be ordered as earliest first
16
    #   @option params [String] :without_grouping       ('false') Whether notification index will include group members
17
    #   @option params [String] :with_group_members     ('false') Whether notification index will include group members
18
    #   @option params [String] :filtered_by_type       (nil)     Notifiable type to filter notification index
19
    #   @option params [String] :filtered_by_group_type (nil)     Group type to filter notification index, valid with :filtered_by_group_id
20
    #   @option params [String] :filtered_by_group_id   (nil)     Group instance ID to filter notification index, valid with :filtered_by_group_type
21
    #   @option params [String] :filtered_by_key        (nil)     Key of notifications to filter notification index
22
    #   @option params [String] :later_than             (nil)     ISO 8601 format time to filter notification index later than specified time
23
    #   @option params [String] :earlier_than           (nil)     ISO 8601 format time to filter notification index earlier than specified time
24
    #   @option params [String] :reload                 ('true')  Whether notification index will be reloaded
25
    #   @return [Response] HTML view of notification index
26
    def index
18✔
27
      set_index_options
1,026✔
28
      load_index if params[:reload].to_s.to_boolean(true)
1,026✔
29
    end
30

31
    # Opens all notifications of the target.
32
    #
33
    # POST /:target_type/:target_id/notifications/open_all
34
    # @overload open_all(params)
35
    #   @param [Hash] params Request parameters
36
    #   @option params [String] :filter                 (nil)     Filter option to load notification index by their status (Nothing as auto, 'opened' or 'unopened')
37
    #   @option params [String] :limit                  (nil)     Maximum number of notifications to return
38
    #   @option params [String] :without_grouping       ('false') Whether notification index will include group members
39
    #   @option params [String] :with_group_members     ('false') Whether notification index will include group members
40
    #   @option params [String] :filtered_by_type       (nil)     Notifiable type to filter notification index
41
    #   @option params [String] :filtered_by_group_type (nil)     Group type to filter notification index, valid with :filtered_by_group_id
42
    #   @option params [String] :filtered_by_group_id   (nil)     Group instance ID to filter notification index, valid with :filtered_by_group_type
43
    #   @option params [String] :filtered_by_key        (nil)     Key of notifications to filter notification index
44
    #   @option params [String] :later_than             (nil)     ISO 8601 format time to filter notification index later than specified time
45
    #   @option params [String] :earlier_than           (nil)     ISO 8601 format time to filter notification index earlier than specified time
46
    #   @option params [Array]  :ids                    (nil)     Array of specific notification IDs to open
47
    #   @option params [String] :reload                 ('true')  Whether notification index will be reloaded
48
    #   @return [Response] JavaScript view for ajax request or redirects to back as default
49
    def open_all
18✔
50
      @opened_notifications = @target.open_all_notifications(params)
882✔
51
      return_back_or_ajax
882✔
52
    end
53

54
    # Destroys all notifications of the target matching filter criteria.
55
    #
56
    # POST /:target_type/:target_id/notifications/destroy_all
57
    # @overload destroy_all(params)
58
    #   @param [Hash] params Request parameters
59
    #   @option params [String] :filter                 (nil)     Filter option to load notification index by their status (Nothing as auto, 'opened' or 'unopened')
60
    #   @option params [String] :limit                  (nil)     Maximum number of notifications to return
61
    #   @option params [String] :without_grouping       ('false') Whether notification index will include group members
62
    #   @option params [String] :with_group_members     ('false') Whether notification index will include group members
63
    #   @option params [String] :filtered_by_type       (nil)     Notifiable type to filter notifications
64
    #   @option params [String] :filtered_by_group_type (nil)     Group type to filter notifications, valid with :filtered_by_group_id
65
    #   @option params [String] :filtered_by_group_id   (nil)     Group instance ID to filter notifications, valid with :filtered_by_group_type
66
    #   @option params [String] :filtered_by_key        (nil)     Key of notifications to filter
67
    #   @option params [String] :later_than             (nil)     ISO 8601 format time to filter notifications later than specified time
68
    #   @option params [String] :earlier_than           (nil)     ISO 8601 format time to filter notifications earlier than specified time
69
    #   @option params [Array]  :ids                    (nil)     Array of specific notification IDs to destroy
70
    #   @option params [String] :reload                 ('true')  Whether notification index will be reloaded
71
    #   @return [Response] JavaScript view for ajax request or redirects to back as default
72
    def destroy_all
18✔
73
      @destroyed_notifications = @target.destroy_all_notifications(params)
828✔
74
      set_index_options
828✔
75
      load_index if params[:reload].to_s.to_boolean(true)
828✔
76
      return_back_or_ajax
828✔
77
    end
78
  
79
    # Shows a notification.
80
    #
81
    # GET /:target_type/:target_id/notifications/:id
82
    # @overload show(params)
83
    #   @param [Hash] params Request parameters
84
    #   @return [Response] HTML view as default
85
    def show
18✔
86
    end
87
  
88
    # Deletes a notification.
89
    #
90
    # DELETE /:target_type/:target_id/notifications/:id
91
    # @overload destroy(params)
92
    #   @param [Hash] params Request parameters
93
    #   @option params [String] :filter                 (nil)     Filter option to load notification index by their status (Nothing as auto, 'opened' or 'unopened')
94
    #   @option params [String] :limit                  (nil)     Maximum number of notifications to return
95
    #   @option params [String] :without_grouping       ('false') Whether notification index will include group members
96
    #   @option params [String] :with_group_members     ('false') Whether notification index will include group members
97
    #   @option params [String] :reload                 ('true')  Whether notification index will be reloaded
98
    #   @return [Response] JavaScript view for ajax request or redirects to back as default
99
    def destroy
18✔
100
      @notification.destroy
432✔
101
      return_back_or_ajax
432✔
102
    end
103
  
104
    # Opens a notification.
105
    #
106
    # PUT /:target_type/:target_id/notifications/:id/open
107
    # @overload open(params)
108
    #   @param [Hash] params Request parameters
109
    #   @option params [String] :move                   ('false') Whether it redirects to notifiable_path after the notification is opened
110
    #   @option params [String] :filter                 (nil)     Filter option to load notification index by their status (Nothing as auto, 'opened' or 'unopened')
111
    #   @option params [String] :limit                  (nil)     Maximum number of notifications to return
112
    #   @option params [String] :without_grouping       ('false') Whether notification index will include group members
113
    #   @option params [String] :with_group_members     ('false') Whether notification index will include group members
114
    #   @option params [String] :reload                 ('true')  Whether notification index will be reloaded
115
    #   @return [Response] JavaScript view for ajax request or redirects to back as default
116
    def open
18✔
117
      with_members = !(params[:with_group_members].to_s.to_boolean(false) || params[:without_grouping].to_s.to_boolean(false))
648✔
118
      @opened_notifications_count = @notification.open!(with_members: with_members)
648✔
119
      params[:move].to_s.to_boolean(false) ? move : return_back_or_ajax
648✔
120
    end
121

122
    # Moves to notifiable_path of the notification.
123
    #
124
    # GET /:target_type/:target_id/notifications/:id/move
125
    # @overload open(params)
126
    #   @param [Hash] params Request parameters
127
    #   @option params [String] :open                   ('false') Whether the notification will be opened
128
    #   @option params [String] :filter                 (nil)     Filter option to load notification index by their status (Nothing as auto, 'opened' or 'unopened')
129
    #   @option params [String] :limit                  (nil)     Maximum number of notifications to return
130
    #   @option params [String] :without_grouping       ('false') Whether notification index will include group members
131
    #   @option params [String] :with_group_members     ('false') Whether notification index will include group members
132
    #   @option params [String] :reload                 ('true')  Whether notification index will be reloaded
133
    #   @return [Response] JavaScript view for ajax request or redirects to back as default
134
    def move
18✔
135
      with_members = !(params[:with_group_members].to_s.to_boolean(false) || params[:without_grouping].to_s.to_boolean(false))
504✔
136
      @opened_notifications_count = @notification.open!(with_members: with_members) if params[:open].to_s.to_boolean(false)
504✔
137
      redirect_to_notifiable_path
504✔
138
    end
139
  
140
    # Returns path of the target view templates.
141
    # This method has no action routing and needs to be public since it is called from view helper.
142
    def target_view_path
18✔
143
      super
4,482✔
144
    end
145

146
    protected
18✔
147

148
      # Sets @notification instance variable from request parameters.
149
      # @api protected
150
      # @return [Object] Notification instance (Returns HTTP 403 when the target of notification is different from specified target by request parameter)
151
      def set_notification
18✔
152
        validate_target(@notification = Notification.with_target.find(params[:id]))
1,710✔
153
      end
154

155
      # Sets options to load notification index from request parameters.
156
      # @api protected
157
      # @return [Hash] options to load notification index
158
      def set_index_options
18✔
159
        limit              = params[:limit].to_i > 0 ? params[:limit].to_i : nil
3,834✔
160
        reverse            = params[:reverse].present? ?
3,834✔
161
                               params[:reverse].to_s.to_boolean(false) : nil
27✔
162
        with_group_members = params[:with_group_members].present? || params[:without_grouping].present? ?
3,834✔
163
                               params[:with_group_members].to_s.to_boolean(false) || params[:without_grouping].to_s.to_boolean(false) : nil
164
        @index_options     = params.permit(:filter, :filtered_by_type, :filtered_by_group_type, :filtered_by_group_id, :filtered_by_key, :later_than, :earlier_than, :routing_scope, :devise_default_routes)
3,834✔
165
                                   .to_h.symbolize_keys
166
                                   .merge(limit: limit, reverse: reverse, with_group_members: with_group_members)
167
      end
168

169
      # Loads notification index with request parameters.
170
      # @api protected
171
      # @return [Array] Array of notification index
172
      def load_index
18✔
173
        @notifications = 
174
          case @index_options[:filter]
2,322✔
175
          when :opened, 'opened'
176
            @target.opened_notification_index_with_attributes(@index_options)
54✔
177
          when :unopened, 'unopened'
178
            @target.unopened_notification_index_with_attributes(@index_options)
54✔
179
          else
180
            @target.notification_index_with_attributes(@index_options)
2,214✔
181
          end
182
      end
183

184
      # Redirect to notifiable_path
185
      # @api protected
186
      def redirect_to_notifiable_path
18✔
187
        redirect_to @notification.notifiable_path
288✔
188
      end
189

190
      # Returns controller path.
191
      # This method is called from target_view_path method and can be overridden.
192
      # @api protected
193
      # @return [String] "activity_notification/notifications" as controller path
194
      def controller_path
18✔
195
        "activity_notification/notifications"
8,964✔
196
      end
197

198
  end
199
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